# AppAuthenticator

Artifact: [androidx.security:security-app-authenticator](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/app/authenticator/AppAuthenticator.java+class:androidx.security.app.authenticator.AppAuthenticator) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

*** ** * ** ***


```
public class AppAuthenticator
```

<br />

*** ** * ** ***

Provides methods to verify the signing identity of other apps on the device.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH() = -3` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not have any of the expected signing identities for the provided permission. |
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_PACKAGE_UID_MISMATCH() = -5` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not belong to the provided calling UID, or if the UID is not provided and the specified package name does not belong to the UID of the calling process as returned by `https://developer.android.com/reference/android/os/Binder.html#getCallingUid()`. |
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE() = -4` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not belong to an app installed on the device. |
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED() = 0` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name has the expected signing identity for the provided permission. |
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#SIGNATURE_MATCH() = 0` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String)` when the specified package name has the expected signing identity. |
| `static final int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#SIGNATURE_NO_MATCH() = -1` This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String)` when the specified package name does not have the expected signing identity. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName)` Checks the specified `packageName` has the expected signing identity as specified in the `<expected-identity>` tag. |
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission )` Checks the specified `packageName` has the expected signing identity for the provided `permission`. |
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission, int uid )` Checks the specified `packageName` running under `uid` has the expected signing identity for the provided `permission`. |
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission, int pid, int uid )` Checks the specified `packageName` running with `pid` and `uid` has the expected signing identity for the provided `permission`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#createFromInputStream(android.content.Context,java.io.InputStream)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/InputStream.html xmlInputStream )` Creates a new `AppAuthenticator` that can be used to guard resources based on package name / signing identity as well as allow verification of expected signing identities before interacting with other apps on a device using the configuration defined in the provided `xmlInputStream`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#createFromResource(android.content.Context,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/XmlRes int xmlResource)` Creates a new `AppAuthenticator` that can be used to guard resources based on package name / signing identity as well as allow verification of expected signing identities before interacting with other apps on a device using the configuration defined in the provided XML resource. |
| `void` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#enforceAppIdentity(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName)` Enforces the specified `packageName` has the expected signing identity as declared in the `<expected-identity>` tag. |
| `void` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission )` Enforces the specified `packageName` has the expected signing identity for the provided `permission`. |
| `void` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission, int uid )` Enforces the specified `packageName` belongs to the provided `uid` and has the expected signing identity for the `permission`. |
| `void` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission, int pid, int uid )` Enforces the specified `packageName` belongs to the provided `pid` / `uid` and has the expected signing identity for the `permission`. |

## Constants

### PERMISSION_DENIED_NO_MATCH

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int PERMISSION_DENIED_NO_MATCH = -3
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not have any of the expected signing identities for the provided permission.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.html#SIGNATURE_NO_MATCH` |   |

### PERMISSION_DENIED_PACKAGE_UID_MISMATCH

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int PERMISSION_DENIED_PACKAGE_UID_MISMATCH = -5
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not belong to the provided calling UID, or if the UID is not provided and the specified package name does not belong to the UID of the calling process as returned by `https://developer.android.com/reference/android/os/Binder.html#getCallingUid()`.

### PERMISSION_DENIED_UNKNOWN_PACKAGE

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int PERMISSION_DENIED_UNKNOWN_PACKAGE = -4
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name does not belong to an app installed on the device.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.html#SIGNATURE_UNKNOWN_PACKAGE` |   |

### PERMISSION_GRANTED

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int PERMISSION_GRANTED = 0
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String)` and `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int)` when the specified package name has the expected signing identity for the provided permission.

### SIGNATURE_MATCH

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int SIGNATURE_MATCH = 0
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String)` when the specified package name has the expected signing identity.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.html#SIGNATURE_MATCH` |   |

### SIGNATURE_NO_MATCH

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static final int SIGNATURE_NO_MATCH = -1
```

This is returned by `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String)` when the specified package name does not have the expected signing identity.

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/pm/PackageManager.html#SIGNATURE_NO_MATCH` |   |

## Public methods

### checkAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public int checkAppIdentity(@NonNull String packageName)
```

Checks the specified `packageName` has the expected signing identity as specified in the `<expected-identity>` tag.

This method should be used when an app's signing identity must be verified; for instance before a client connects to an exported service this method can be used to verify that the app comes from the expected developer.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |

| Returns |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#SIGNATURE_MATCH()` if the specified package has the expected signing identity |

### checkCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public int checkCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission
)
```

Checks the specified `packageName` has the expected signing identity for the provided `permission`.

This method should be used for verifying the identity of a package when the UID / PID is not available. For instance, this should be used within an activity that was started with `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)` where the package name is available from `https://developer.android.com/reference/android/app/Activity.html#getCallingPackage()`. For instances where the calling UID is available but the calling PID is not available, (`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int)` should be preferred.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |

| Returns |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED()` if the specified `packageName` has the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH()` if the specified `packageName` does not have the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE()` if the specified `packageName` does not exist on the device, |

### checkCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public int checkCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission,
    int uid
)
```

Checks the specified `packageName` running under `uid` has the expected signing identity for the provided `permission`.

This method should be used for verifying the identity of a package when the UID is available but the PID is not. For instance, this should be used within an activity that is started with `https://developer.android.com/reference/android/app/ActivityOptions.html#setShareIdentityEnabled(boolean)` set to true; the package name would then be accessible via `https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromPackage()` and the UID from `https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromUid()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `int uid` | the expected uid of the package |

| Returns |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED()` if the specified `packageName` has the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH()` if the specified `packageName` does not have the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE()` if the specified `packageName` does not exist on the device,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_PACKAGE_UID_MISMATCH()` if the specified `uid` does not match the uid assigned to the package |

### checkCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public int checkCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission,
    int pid,
    int uid
)
```

Checks the specified `packageName` running with `pid` and `uid` has the expected signing identity for the provided `permission`.

This method should be used for verifying the identity of a calling process of an IPC.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `int pid` | the expected pid of the process |
| `int uid` | the expected uid of the package |

| Returns |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED()` if the specified `packageName` has the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH()` if the specified `packageName` does not have the expected signing identity for the provided `permission`,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE()` if the specified `packageName` does not exist on the device,`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_PACKAGE_UID_MISMATCH()` if the specified `uid` does not match the uid assigned to the package |

### createFromInputStream

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static @NonNull AppAuthenticator createFromInputStream(
    @NonNull Context context,
    @NonNull InputStream xmlInputStream
)
```

Creates a new `AppAuthenticator` that can be used to guard resources based on package name / signing identity as well as allow verification of expected signing identities before interacting with other apps on a device using the configuration defined in the provided `xmlInputStream`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | the context within which to create the `AppAuthenticator` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/InputStream.html xmlInputStream` | the XML `https://developer.android.com/reference/java/io/InputStream.html` containing the definitions for the permissions and expected identities based on packages / expected signing certificate digests |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator` | a new `AppAuthenticator` that can be used to enforce the signing identities defined in the provided XML `InputStream` |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticatorXmlException` | if the provided XML `InputStream` is not in the proper format to create a new `AppAuthenticator` |
| `https://developer.android.com/reference/java/io/IOException.html` | if an IO error is encountered when attempting to read the XML `InputStream` |

### createFromResource

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public static @NonNull AppAuthenticator createFromResource(@NonNull Context context, @XmlRes int xmlResource)
```

Creates a new `AppAuthenticator` that can be used to guard resources based on package name / signing identity as well as allow verification of expected signing identities before interacting with other apps on a device using the configuration defined in the provided XML resource.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | the context within which to create the `AppAuthenticator` |
| `@https://developer.android.com/reference/androidx/annotation/XmlRes int xmlResource` | the ID of the XML resource containing the definitions for the permissions and expected identities based on package / expected signing certificate digests |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator` | a new `AppAuthenticator` that can be used to enforce the signing identities defined in the provided XML resource |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticatorXmlException` | if the provided XML resource is not in the proper format to create a new `AppAuthenticator` |
| `https://developer.android.com/reference/java/io/IOException.html` | if an IO error is encountered when attempting to read the XML resource |

### enforceAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public void enforceAppIdentity(@NonNull String packageName)
```

Enforces the specified `packageName` has the expected signing identity as declared in the `<expected-identity>` tag.

This method should be used when an app's signing identity must be verified; for instance before a client connects to an exported service this method can be used to verify that the app comes from the expected developer.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the signing identity of the package does not match that defined in the `<expected-identity>` tag |

### enforceCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public void enforceCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission
)
```

Enforces the specified `packageName` has the expected signing identity for the provided `permission`.

This method should be used for verifying the identity of a package when the UID / PID is not available. For instance, this should be used within an activity that was started with `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)` where the package name is available from `https://developer.android.com/reference/android/app/Activity.html#getCallingPackage()`. For instances where the calling UID is available but the calling PID is not available, (`https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int)` should be preferred.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the signing identity of the package does not match that defined for the permission |

### enforceCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public void enforceCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission,
    int uid
)
```

Enforces the specified `packageName` belongs to the provided `uid` and has the expected signing identity for the `permission`.

This method should be used for verifying the identity of a package when the UID is available but the PID is not. For instance, this should be used within an activity that is started with `https://developer.android.com/reference/android/app/ActivityOptions.html#setShareIdentityEnabled(boolean)` set to true; the package name would then be accessible via `https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromPackage()` and the UID from `https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromUid()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `int uid` | the expected uid of the package |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the uid does not belong to the specified package, or if the signing identity of the package does not match that defined for the permission |

### enforceCallingAppIdentity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/security#1.0.0)

```
public void enforceCallingAppIdentity(
    @NonNull String packageName,
    @NonNull String permission,
    int pid,
    int uid
)
```

Enforces the specified `packageName` belongs to the provided `pid` / `uid` and has the expected signing identity for the `permission`.

This method should be used for verifying the identity of a calling process of an IPC.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | the name of the package to be verified |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `int pid` | the expected pid of the process |
| `int uid` | the expected uid of the package |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the uid does not belong to the specified package, or if the signing identity of the package does not match that defined for the permission |