clearCallingIdentity method

  1. @native
  2. @RequiresApiOrNoop(29)
Future<CallingIdentity?> clearCallingIdentity()

Reset the identity of the incoming IPC on the current thread.

This can be useful if, while handling an incoming call, you will be calling on interfaces of other objects that may be local to your process and need to do permission checks on the calls coming into them (so they will check the permission of your own local process, and not whatever process originally called you).

Returns an opaque token that can be used to restore the original calling identity by passing it to restoreCallingIdentity.

Supported starting from Android Q, returns null on lower versions.

--- References ---

clearCallingIdentity(): ContentProvider.CallingIdentity https://developer.android.com/reference/kotlin/android/content/ContentProvider#clearcallingidentity

Implementation

@native
@RequiresApiOrNoop(29)
Future<CallingIdentity?> clearCallingIdentity() async {
  final result =
      await _methodChannel.invokeMethod<String>('clearCallingIdentity');
  return result == null ? null : CallingIdentity.fromId(result);
}