AppOpsManagerCompat

Added in 1.1.0

class AppOpsManagerCompat


Helper for accessing features in android.app.AppOpsManager.

Summary

Constants

const Int

Result from noteOp: the given caller is allowed to perform the given operation.

const Int

Result from noteOp: the given caller should use its default security check.

const Int

Result from noteOpNoThrow: the given caller is not allowed to perform the given operation, and this attempt should cause it to have a fatal error, typically a SecurityException.

const Int

Result from noteOp: the given caller is not allowed to perform the given operation, and this attempt should silently fail (it should not cause the app to crash).

Public functions

java-static Int
checkOrNoteProxyOp(
    context: Context,
    proxyUid: Int,
    op: String,
    proxiedPackageName: String
)

Check op for both proxy and proxied packages.

java-static Int
noteOp(context: Context, op: String, uid: Int, packageName: String)

Make note of an application performing an operation.

java-static Int
noteOpNoThrow(context: Context, op: String, uid: Int, packageName: String)

Like noteOp but instead of throwing a SecurityException it returns MODE_ERRORED.

java-static Int
noteProxyOp(context: Context, op: String, proxiedPackageName: String)

Make note of an application performing an operation on behalf of another application when handling an IPC.

java-static Int
noteProxyOpNoThrow(
    context: Context,
    op: String,
    proxiedPackageName: String
)

Like noteProxyOp but instead of throwing a SecurityException it returns MODE_ERRORED.

java-static String?
permissionToOp(permission: String)

Gets the app op name associated with a given permission.

Constants

MODE_ALLOWED

Added in 1.1.0
const val MODE_ALLOWED = 0: Int

Result from noteOp: the given caller is allowed to perform the given operation.

MODE_DEFAULT

Added in 1.1.0
const val MODE_DEFAULT = 3: Int

Result from noteOp: the given caller should use its default security check. This mode is not normally used; it should only be used with appop permissions, and callers must explicitly check for it and deal with it.

MODE_ERRORED

Added in 1.1.0
const val MODE_ERRORED = 2: Int

Result from noteOpNoThrow: the given caller is not allowed to perform the given operation, and this attempt should cause it to have a fatal error, typically a SecurityException.

MODE_IGNORED

Added in 1.1.0
const val MODE_IGNORED = 1: Int

Result from noteOp: the given caller is not allowed to perform the given operation, and this attempt should silently fail (it should not cause the app to crash).

Public functions

checkOrNoteProxyOp

Added in 1.7.0
java-static fun checkOrNoteProxyOp(
    context: Context,
    proxyUid: Int,
    op: String,
    proxiedPackageName: String
): Int

Check op for both proxy and proxied packages. Do a quick check for whether an application might be able to perform an operation. This is not a security check. On API 23-28, fallback to noteProxyOpNoThrow On API 22 and lower, this method always returns MODE_IGNORED

#MODE_IGNORED} if it is not allowed and should be silently ignored (without causing the app to crash).

Parameters
context: Context

Your context.

proxyUid: Int

The uid of the proxy application.

op: String

The operation to note. One of the OPSTR_* constants.

proxiedPackageName: String

The name of the application calling into the proxy application.

Returns
Int

Returns MODE_ALLOWED if the operation is allowed, or

noteOp

Added in 1.1.0
java-static fun noteOp(context: Context, op: String, uid: Int, packageName: String): Int

Make note of an application performing an operation. Note that you must pass in both the uid and name of the application to be checked; this function will verify that these two match, and if not, return MODE_IGNORED. If this call succeeds, the last execution time of the operation for this app will be updated to the current time.

Compatibility

  • On API 18 and lower, this method always returns MODE_IGNORED
Parameters
context: Context

Your context.

op: String

The operation to note. One of the OPSTR_* constants.

uid: Int

The user id of the application attempting to perform the operation.

packageName: String

The name of the application attempting to perform the operation.

Returns
Int

Returns MODE_ALLOWED if the operation is allowed, or MODE_IGNORED if it is not allowed and should be silently ignored (without causing the app to crash).

Throws
java.lang.SecurityException

If the app has been configured to crash on this op.

noteOpNoThrow

Added in 1.1.0
java-static fun noteOpNoThrow(context: Context, op: String, uid: Int, packageName: String): Int

Like noteOp but instead of throwing a SecurityException it returns MODE_ERRORED.

Compatibility

  • On API 18 and lower, this method always returns MODE_IGNORED

noteProxyOp

Added in 1.1.0
java-static fun noteProxyOp(context: Context, op: String, proxiedPackageName: String): Int

Make note of an application performing an operation on behalf of another application when handling an IPC. Note that you must pass the package name of the application that is being proxied while its UID will be inferred from the IPC state; this function will verify that the calling uid and proxied package name match, and if not, return MODE_IGNORED. If this call succeeds, the last execution time of the operation for the proxied app and your app will be updated to the current time.

Compatibility

  • On API 22 and lower, this method always returns MODE_IGNORED
Parameters
context: Context

Your context.

op: String

The operation to note. One of the OPSTR_* constants.

proxiedPackageName: String

The name of the application calling into the proxy application.

Returns
Int

Returns MODE_ALLOWED if the operation is allowed, or MODE_IGNORED if it is not allowed and should be silently ignored (without causing the app to crash).

Throws
java.lang.SecurityException

If the app has been configured to crash on this op.

noteProxyOpNoThrow

Added in 1.1.0
java-static fun noteProxyOpNoThrow(
    context: Context,
    op: String,
    proxiedPackageName: String
): Int

Like noteProxyOp but instead of throwing a SecurityException it returns MODE_ERRORED.

Compatibility

  • On API 22 and lower, this method always returns MODE_IGNORED

permissionToOp

Added in 1.1.0
java-static fun permissionToOp(permission: String): String?

Gets the app op name associated with a given permission.

Compatibility

  • On API 22 and lower, this method always returns null
Parameters
permission: String

The permission.

Returns
String?

The app op associated with the permission or null.