# AppAuthenticator

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/security/app/authenticator/AppAuthenticator "View this page in Java")

<br />

```
class AppAuthenticator
```

<br />

*** ** * ** ***

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

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_DENIED_NO_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH())` = -3` This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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.                                                                                                                                                                                                                  |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_DENIED_PACKAGE_UID_MISMATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_PACKAGE_UID_MISMATCH())` = -5` This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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[getCallingUid](https://developer.android.com/reference/android/os/Binder.html#getCallingUid()). |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_DENIED_UNKNOWN_PACKAGE](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE())` = -4` This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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.                                                                                                                                                                                                                                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_GRANTED](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED())` = 0` This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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.                                                                                                                                                                                                                                                      |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SIGNATURE_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#SIGNATURE_MATCH())` = 0` This is returned by[checkAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String))when the specified package name has the expected signing identity.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SIGNATURE_NO_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#SIGNATURE_NO_MATCH())` = -1` This is returned by[checkAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String))when the specified package name does not have the expected signing identity.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

|                                                         ### Public functions                                                          |
|---------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                           | [checkAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkAppIdentity(java.lang.String))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Checks the specified`packageName`has the expected signing identity as specified in the`<expected-identity>`tag.                                                                                                                                                                                                                                                                                                                                                                   |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                           | [checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Checks the specified`packageName`has the expected signing identity for the provided`permission`.                                                                                                                                                                                                                                                  |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                           | [checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Checks the specified`packageName`running under`uid`has the expected signing identity for the provided`permission`.                                                                                                                                        |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                           | [checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int,int))`(` ` packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` pid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Checks the specified`packageName`running with`pid`and`uid`has the expected signing identity for the provided`permission`.                           |
| `java-static `[AppAuthenticator](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator) | [createFromInputStream](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#createFromInputStream(android.content.Context,java.io.InputStream))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, xmlInputStream: `[InputStream](https://developer.android.com/reference/java/io/InputStream.html)`)` 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`.                                                        |
| `java-static `[AppAuthenticator](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator) | [createFromResource](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#createFromResource(android.content.Context,int))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, xmlResource: @`[XmlRes](https://developer.android.com/reference/kotlin/androidx/annotation/XmlRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` 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. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [enforceAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#enforceAppIdentity(java.lang.String))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Enforces the specified`packageName`has the expected signing identity as declared in the`<expected-identity>`tag.                                                                                                                                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [enforceCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Enforces the specified`packageName`has the expected signing identity for the provided`permission`.                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [enforceCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String,int))`(` ` packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Enforces the specified`packageName`belongs to the provided`uid`and has the expected signing identity for the`permission`.                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                         | [enforceCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#enforceCallingAppIdentity(java.lang.String,java.lang.String,int,int))`(` ` packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` pid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` 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)  

```
const val PERMISSION_DENIED_NO_MATCH = -3: Int
```

This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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                                                          |
|---------------------------------------------------------------------------------------------------------------------------|---|
| [SIGNATURE_NO_MATCH](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)  

```
const val PERMISSION_DENIED_PACKAGE_UID_MISMATCH = -5: Int
```

This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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[getCallingUid](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)  

```
const val PERMISSION_DENIED_UNKNOWN_PACKAGE = -4: Int
```

This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------|---|
| [SIGNATURE_UNKNOWN_PACKAGE](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)  

```
const val PERMISSION_GRANTED = 0: Int
```

This is returned by[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String))and[checkCallingAppIdentity](https://developer.android.com/reference/kotlin/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)  

```
const val SIGNATURE_MATCH = 0: Int
```

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

|                                                      See also                                                       |
|---------------------------------------------------------------------------------------------------------------------|---|
| [SIGNATURE_MATCH](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)  

```
const val SIGNATURE_NO_MATCH = -1: Int
```

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

|                                                         See also                                                          |
|---------------------------------------------------------------------------------------------------------------------------|---|
| [SIGNATURE_NO_MATCH](https://developer.android.com/reference/android/content/pm/PackageManager.html#SIGNATURE_NO_MATCH()) |   |

## Public functions

### checkAppIdentity

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

```
fun checkAppIdentity(packageName: String): Int
```

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                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SIGNATURE_MATCH](https://developer.android.com/reference/kotlin/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)  

```
fun checkCallingAppIdentity(packageName: String, permission: String): Int
```

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[startActivityForResult](https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int))where the package name is available from[getCallingPackage](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, ([checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int))should be preferred.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_GRANTED](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED())if the specified`packageName`has the expected signing identity for the provided`permission`,[PERMISSION_DENIED_NO_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH())if the specified`packageName`does not have the expected signing identity for the provided`permission`,[PERMISSION_DENIED_UNKNOWN_PACKAGE](https://developer.android.com/reference/kotlin/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)  

```
fun checkCallingAppIdentity(packageName: String, permission: String, uid: Int): Int
```

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[setShareIdentityEnabled](https://developer.android.com/reference/android/app/ActivityOptions.html#setShareIdentityEnabled(boolean))set to true; the package name would then be accessible via[getLaunchedFromPackage](https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromPackage())and the UID from[getLaunchedFromUid](https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromUid()).  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected uid of the package                                                                        |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_GRANTED](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED())if the specified`packageName`has the expected signing identity for the provided`permission`,[PERMISSION_DENIED_NO_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH())if the specified`packageName`does not have the expected signing identity for the provided`permission`,[PERMISSION_DENIED_UNKNOWN_PACKAGE](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE())if the specified`packageName`does not exist on the device,[PERMISSION_DENIED_PACKAGE_UID_MISMATCH](https://developer.android.com/reference/kotlin/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)  

```
fun checkCallingAppIdentity(
    packageName: String,
    permission: String,
    pid: Int,
    uid: Int
): Int
```

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                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `pid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected pid of the process                                                                        |
| `uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected uid of the package                                                                        |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [PERMISSION_GRANTED](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_GRANTED())if the specified`packageName`has the expected signing identity for the provided`permission`,[PERMISSION_DENIED_NO_MATCH](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_NO_MATCH())if the specified`packageName`does not have the expected signing identity for the provided`permission`,[PERMISSION_DENIED_UNKNOWN_PACKAGE](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#PERMISSION_DENIED_UNKNOWN_PACKAGE())if the specified`packageName`does not exist on the device,[PERMISSION_DENIED_PACKAGE_UID_MISMATCH](https://developer.android.com/reference/kotlin/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)  

```
java-static fun createFromInputStream(context: Context, xmlInputStream: InputStream): AppAuthenticator
```

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                                             |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)        | the context within which to create the`AppAuthenticator`                                                                                                                                                              |
| `xmlInputStream: `[InputStream](https://developer.android.com/reference/java/io/InputStream.html) | the XML[InputStream](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                                                         |
|-------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [AppAuthenticator](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator) | a new`AppAuthenticator`that can be used to enforce the signing identities defined in the provided XML`InputStream` |

|                                                                                       Throws                                                                                        |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [androidx.security.app.authenticator.AppAuthenticatorXmlException](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticatorXmlException) | if the provided XML`InputStream`is not in the proper format to create a new`AppAuthenticator` |
| [java.io.IOException](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)  

```
java-static fun createFromResource(context: Context, xmlResource: @XmlRes Int): AppAuthenticator
```

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                                                                                     |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                        | the context within which to create the`AppAuthenticator`                                                                                                  |
| `xmlResource: @`[XmlRes](https://developer.android.com/reference/kotlin/androidx/annotation/XmlRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | the ID of the XML resource containing the definitions for the permissions and expected identities based on package / expected signing certificate digests |

|                                                         Returns                                                         |
|-------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| [AppAuthenticator](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator) | a new`AppAuthenticator`that can be used to enforce the signing identities defined in the provided XML resource |

|                                                                                       Throws                                                                                        |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| [androidx.security.app.authenticator.AppAuthenticatorXmlException](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticatorXmlException) | if the provided XML resource is not in the proper format to create a new`AppAuthenticator` |
| [java.io.IOException](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)  

```
fun enforceAppIdentity(packageName: String): Unit
```

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                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified |

|                                                 Throws                                                  |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| [java.lang.SecurityException](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)  

```
fun enforceCallingAppIdentity(packageName: String, permission: String): Unit
```

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[startActivityForResult](https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int))where the package name is available from[getCallingPackage](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, ([checkCallingAppIdentity](https://developer.android.com/reference/kotlin/androidx/security/app/authenticator/AppAuthenticator#checkCallingAppIdentity(java.lang.String,java.lang.String,int))should be preferred.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |

|                                                 Throws                                                  |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|
| [java.lang.SecurityException](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)  

```
fun enforceCallingAppIdentity(
    packageName: String,
    permission: String,
    uid: Int
): Unit
```

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[setShareIdentityEnabled](https://developer.android.com/reference/android/app/ActivityOptions.html#setShareIdentityEnabled(boolean))set to true; the package name would then be accessible via[getLaunchedFromPackage](https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromPackage())and the UID from[getLaunchedFromUid](https://developer.android.com/reference/android/app/Activity.html#getLaunchedFromUid()).  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected uid of the package                                                                        |

|                                                 Throws                                                  |
|---------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.SecurityException](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)  

```
fun enforceCallingAppIdentity(
    packageName: String,
    permission: String,
    pid: Int,
    uid: Int
): Unit
```

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                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the name of the package to be verified                                                                 |
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | the name of the permission as specified in the XML from which to verify the package / signing identity |
| `pid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected pid of the process                                                                        |
| `uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)               | the expected uid of the package                                                                        |

|                                                 Throws                                                  |
|---------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.SecurityException](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 |