AppOpsManagerCompat
class AppOpsManagerCompat
kotlin.Any | |
↳ | androidx.core.app.AppOpsManagerCompat |
Helper for accessing features in android.app.AppOpsManager
.
Summary
Constants | |
---|---|
static Int |
Result from |
static Int |
Result from |
static Int |
Result from |
static Int |
Result from |
Public methods | |
---|---|
static Int |
Make note of an application performing an operation. |
static Int |
noteOpNoThrow(@NonNull context: Context, @NonNull op: String, uid: Int, @NonNull packageName: String) Like |
static Int |
noteProxyOp(@NonNull context: Context, @NonNull op: String, @NonNull proxiedPackageName: String) Make note of an application performing an operation on behalf of another application when handling an IPC. |
static Int |
noteProxyOpNoThrow(@NonNull context: Context, @NonNull op: String, @NonNull proxiedPackageName: String) Like |
static String? |
permissionToOp(@NonNull permission: String) Gets the app op name associated with a given permission. |
Constants
MODE_ALLOWED
static val MODE_ALLOWED: Int
Result from noteOp
: the given caller is allowed to perform the given operation.
Value: AppOpsManager.MODE_ALLOWED
MODE_DEFAULT
static val MODE_DEFAULT: 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.
Value: AppOpsManager.MODE_DEFAULT
MODE_ERRORED
static val MODE_ERRORED: 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
.
Value: AppOpsManager.MODE_ERRORED
MODE_IGNORED
static val MODE_IGNORED: 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).
Value: AppOpsManager.MODE_IGNORED
Public methods
noteOp
static fun noteOp(
@NonNull context: Context,
@NonNull op: String,
uid: Int,
@NonNull 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. |
Return | |
---|---|
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). |
Exceptions | |
---|---|
SecurityException |
If the app has been configured to crash on this op. |