AppOpsManagerCompat
public final class AppOpsManagerCompat
Helper for accessing features in android.app.AppOpsManager.
Summary
Constants |
|
|---|---|
static final int |
MODE_ALLOWED = 0Result from |
static final int |
MODE_DEFAULT = 3Result from |
static final int |
MODE_ERRORED = 2Result from |
static final int |
MODE_IGNORED = 1Result from |
Public methods |
|
|---|---|
static int |
checkOrNoteProxyOp(Check op for both proxy and proxied packages. |
static int |
Make note of an application performing an operation. |
static int |
Like |
static int |
Make note of an application performing an operation on behalf of another application when handling an IPC. |
static int |
noteProxyOpNoThrow(Like |
static @Nullable String |
permissionToOp(@NonNull String permission)Gets the app op name associated with a given permission. |
Constants
MODE_ALLOWED
public static final int MODE_ALLOWED = 0
Result from noteOp: the given caller is allowed to perform the given operation.
MODE_DEFAULT
public static final int MODE_DEFAULT = 3
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
public static final int MODE_ERRORED = 2
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
public static final int MODE_IGNORED = 1
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 methods
checkOrNoteProxyOp
public static int checkOrNoteProxyOp(
@NonNull Context context,
int proxyUid,
@NonNull String op,
@NonNull String proxiedPackageName
)
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 | |
|---|---|
@NonNull Context context |
Your context. |
int proxyUid |
The uid of the proxy application. |
@NonNull String op |
The operation to note. One of the OPSTR_* constants. |
@NonNull String proxiedPackageName |
The name of the application calling into the proxy application. |
| Returns | |
|---|---|
int |
Returns |
noteOp
public static int noteOp(
@NonNull Context context,
@NonNull String op,
int uid,
@NonNull 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.
Compatibility
- On API 18 and lower, this method always returns
MODE_IGNORED
| Parameters | |
|---|---|
@NonNull Context context |
Your context. |
@NonNull String op |
The operation to note. One of the OPSTR_* constants. |
int uid |
The user id of the application attempting to perform the operation. |
@NonNull String packageName |
The name of the application attempting to perform the operation. |
| Returns | |
|---|---|
int |
Returns |
| Throws | |
|---|---|
java.lang.SecurityException |
If the app has been configured to crash on this op. |
noteOpNoThrow
public static int noteOpNoThrow(
@NonNull Context context,
@NonNull String op,
int uid,
@NonNull String packageName
)
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
public static int noteProxyOp(
@NonNull Context context,
@NonNull String op,
@NonNull 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.
Compatibility
- On API 22 and lower, this method always returns
MODE_IGNORED
| Parameters | |
|---|---|
@NonNull Context context |
Your context. |
@NonNull String op |
The operation to note. One of the OPSTR_* constants. |
@NonNull String proxiedPackageName |
The name of the application calling into the proxy application. |
| Returns | |
|---|---|
int |
Returns |
| Throws | |
|---|---|
java.lang.SecurityException |
If the app has been configured to crash on this op. |
noteProxyOpNoThrow
public static int noteProxyOpNoThrow(
@NonNull Context context,
@NonNull String op,
@NonNull String proxiedPackageName
)
Like noteProxyOp but instead of throwing a SecurityException it returns MODE_ERRORED.
Compatibility
- On API 22 and lower, this method always returns
MODE_IGNORED