AppAuthenticator
class AppAuthenticator
Provides methods to verify the signing identity of other apps on the device.
Summary
Constants |
|
|---|---|
const Int |
This is returned by |
const Int |
This is returned by |
const Int |
This is returned by |
const Int |
This is returned by |
const Int |
SIGNATURE_MATCH = 0This is returned by |
const Int |
SIGNATURE_NO_MATCH = -1This is returned by |
Public functions |
|
|---|---|
Int |
checkAppIdentity(packageName: String)Checks the specified |
Int |
checkCallingAppIdentity(packageName: String, permission: String)Checks the specified |
Int |
checkCallingAppIdentity(packageName: String, permission: String, uid: Int)Checks the specified |
Int |
checkCallingAppIdentity(Checks the specified |
java-static AppAuthenticator |
createFromInputStream(context: Context, xmlInputStream: InputStream)Creates a new |
java-static AppAuthenticator |
createFromResource(context: Context, xmlResource: @XmlRes Int)Creates a new |
Unit |
enforceAppIdentity(packageName: String)Enforces the specified |
Unit |
enforceCallingAppIdentity(packageName: String, permission: String)Enforces the specified |
Unit |
enforceCallingAppIdentity(Enforces the specified |
Unit |
enforceCallingAppIdentity(Enforces the specified |
Constants
PERMISSION_DENIED_NO_MATCH
const val PERMISSION_DENIED_NO_MATCH = -3: Int
This is returned by checkCallingAppIdentity and checkCallingAppIdentity when the specified package name does not have any of the expected signing identities for the provided permission.
| See also | |
|---|---|
SIGNATURE_NO_MATCH |
PERMISSION_DENIED_PACKAGE_UID_MISMATCH
const val PERMISSION_DENIED_PACKAGE_UID_MISMATCH = -5: Int
This is returned by checkCallingAppIdentity and checkCallingAppIdentity 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.
PERMISSION_DENIED_UNKNOWN_PACKAGE
const val PERMISSION_DENIED_UNKNOWN_PACKAGE = -4: Int
This is returned by checkCallingAppIdentity and checkCallingAppIdentity when the specified package name does not belong to an app installed on the device.
| See also | |
|---|---|
SIGNATURE_UNKNOWN_PACKAGE |
PERMISSION_GRANTED
const val PERMISSION_GRANTED = 0: Int
This is returned by checkCallingAppIdentity and checkCallingAppIdentity when the specified package name has the expected signing identity for the provided permission.
SIGNATURE_MATCH
const val SIGNATURE_MATCH = 0: Int
This is returned by checkAppIdentity when the specified package name has the expected signing identity.
| See also | |
|---|---|
SIGNATURE_MATCH |
SIGNATURE_NO_MATCH
const val SIGNATURE_NO_MATCH = -1: Int
This is returned by checkAppIdentity when the specified package name does not have the expected signing identity.
| See also | |
|---|---|
SIGNATURE_NO_MATCH |
Public functions
checkAppIdentity
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 |
the name of the package to be verified |
| Returns | |
|---|---|
Int |
|
checkCallingAppIdentity
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 where the package name is available from getCallingPackage. For instances where the calling UID is available but the calling PID is not available, (checkCallingAppIdentity should be preferred.
| Parameters | |
|---|---|
packageName: String |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
| Returns | |
|---|---|
Int |
|
checkCallingAppIdentity
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 set to true; the package name would then be accessible via getLaunchedFromPackage and the UID from getLaunchedFromUid.
| Parameters | |
|---|---|
packageName: String |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
uid: Int |
the expected uid of the package |
| Returns | |
|---|---|
Int |
|
checkCallingAppIdentity
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 |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
pid: Int |
the expected pid of the process |
uid: Int |
the expected uid of the package |
| Returns | |
|---|---|
Int |
|
createFromInputStream
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 |
the context within which to create the |
xmlInputStream: InputStream |
the XML |
| Returns | |
|---|---|
AppAuthenticator |
a new |
| Throws | |
|---|---|
androidx.security.app.authenticator.AppAuthenticatorXmlException |
if the provided XML |
java.io.IOException |
if an IO error is encountered when attempting to read the XML |
createFromResource
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 |
the context within which to create the |
xmlResource: @XmlRes Int |
the ID of the XML resource containing the definitions for the permissions and expected identities based on package / expected signing certificate digests |
| Returns | |
|---|---|
AppAuthenticator |
a new |
| Throws | |
|---|---|
androidx.security.app.authenticator.AppAuthenticatorXmlException |
if the provided XML resource is not in the proper format to create a new |
java.io.IOException |
if an IO error is encountered when attempting to read the XML resource |
enforceAppIdentity
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 |
the name of the package to be verified |
| Throws | |
|---|---|
java.lang.SecurityException |
if the signing identity of the package does not match that defined in the |
enforceCallingAppIdentity
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 where the package name is available from getCallingPackage. For instances where the calling UID is available but the calling PID is not available, (checkCallingAppIdentity should be preferred.
| Parameters | |
|---|---|
packageName: String |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
| Throws | |
|---|---|
java.lang.SecurityException |
if the signing identity of the package does not match that defined for the permission |
enforceCallingAppIdentity
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 set to true; the package name would then be accessible via getLaunchedFromPackage and the UID from getLaunchedFromUid.
| Parameters | |
|---|---|
packageName: String |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
uid: Int |
the expected uid of the package |
| Throws | |
|---|---|
java.lang.SecurityException |
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
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 |
the name of the package to be verified |
permission: String |
the name of the permission as specified in the XML from which to verify the package / signing identity |
pid: Int |
the expected pid of the process |
uid: Int |
the expected uid of the package |
| Throws | |
|---|---|
java.lang.SecurityException |
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 |