Android APIs
public class

AppOpsManagerCompat

extends Object
java.lang.Object
   ↳ android.support.v4.app.AppOpsManagerCompat

Class Overview

Helper for accessing features in android.app.AppOpsManager introduced after API level 4 in a backwards compatible fashion.

Summary

Constants
int MODE_ALLOWED Result from noteOp(Context, String, int, String): the given caller is allowed to perform the given operation.
int MODE_DEFAULT Result from noteOp(Context, String, int, String): the given caller should use its default security check.
int MODE_IGNORED Result from noteOp(Context, String, int, String): 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 Constructors
AppOpsManagerCompat()
Public Methods
static int noteOp(Context context, String op, int uid, String packageName)
Make note of an application performing an operation.
static int noteProxyOp(Context context, String op, String proxiedPackageName)
Make note of an application performing an operation on behalf of another application when handling an IPC.
static String permissionToOp(String permission)
Gets the app op name associated with a given permission.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MODE_ALLOWED

Result from noteOp(Context, String, int, String): the given caller is allowed to perform the given operation.

Constant Value: 0 (0x00000000)

public static final int MODE_DEFAULT

Result from noteOp(Context, String, int, String): 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.

Constant Value: 3 (0x00000003)

public static final int MODE_IGNORED

Result from noteOp(Context, String, int, String): 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).

Constant Value: 1 (0x00000001)

Public Constructors

public AppOpsManagerCompat ()

Public Methods

public static int noteOp (Context context, String op, int uid, String packageName)

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.

Parameters
context Your context.
op The operation to note. One of the OPSTR_* constants.
uid The user id of the application attempting to perform the operation.
packageName The name of the application attempting to perform the operation.
Returns
  • 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
SecurityException If the app has been configured to crash on this op.

public static int noteProxyOp (Context context, String op, String proxiedPackageName)

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.

Parameters
context Your context.
op The operation to note. One of the OPSTR_* constants.
proxiedPackageName The name of the application calling into the proxy application.
Returns
  • 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
SecurityException If the app has been configured to crash on this op.

public static String permissionToOp (String permission)

Gets the app op name associated with a given permission.

Parameters
permission The permission.
Returns
  • The app op associated with the permission or null.