# AppOpsManagerCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/app/AppOpsManagerCompat.java+class:androidx.core.app.AppOpsManagerCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class AppOpsManagerCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/app/AppOpsManager.html`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED() = 0` Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)`: the given caller is allowed to perform the given operation. |
| `static final int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_DEFAULT() = 3` Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)`: the given caller should use its default security check. |
| `static final int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED() = 2` Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOpNoThrow(android.content.Context,java.lang.String,int,java.lang.String)`: the given caller is not allowed to perform the given operation, and this attempt should cause it to have a fatal error, typically a `https://developer.android.com/reference/java/lang/SecurityException.html`. |
| `static final int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED() = 1` Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.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 methods |
|---|---|
| `static int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#checkOrNoteProxyOp(android.content.Context,int,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, int proxyUid, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxiedPackageName )` Check op for both proxy and proxied packages. |
| `static int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op, int uid, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName )` Make note of an application performing an operation. |
| `static int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOpNoThrow(android.content.Context,java.lang.String,int,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op, int uid, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName )` Like `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)` but instead of throwing a `https://developer.android.com/reference/java/lang/SecurityException.html` it returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()`. |
| `static int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteProxyOp(android.content.Context,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxiedPackageName )` Make note of an application performing an operation on behalf of another application when handling an IPC. |
| `static int` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteProxyOpNoThrow(android.content.Context,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxiedPackageName )` Like `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteProxyOp(android.content.Context,java.lang.String,java.lang.String)` but instead of throwing a `https://developer.android.com/reference/java/lang/SecurityException.html` it returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#permissionToOp(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission)` Gets the app op name associated with a given permission. |

## Constants

### MODE_ALLOWED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int MODE_ALLOWED = 0
```

Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)`: the given caller is allowed to perform the given operation.

### MODE_DEFAULT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int MODE_DEFAULT = 3
```

Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.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.

### MODE_ERRORED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int MODE_ERRORED = 2
```

Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOpNoThrow(android.content.Context,java.lang.String,int,java.lang.String)`: the given caller is not allowed to perform the given operation, and this attempt should cause it to have a fatal error, typically a `https://developer.android.com/reference/java/lang/SecurityException.html`.

### MODE_IGNORED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int MODE_IGNORED = 1
```

Result from `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.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 methods

### checkOrNoteProxyOp

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
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 28 and lower, fallback to `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteProxyOpNoThrow(android.content.Context,java.lang.String,java.lang.String)`

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Your context. |
| `int proxyUid` | The uid of the proxy application. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op` | The operation to note. One of the OPSTR_\* constants. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxiedPackageName` | The name of the application calling into the proxy application. |

| Returns |
|---|---|
| `int` | Returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED()` if the operation is allowed, or |

### noteOp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
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 `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED()`. If this call succeeds, the last execution time of the operation for this app will be updated to the current time.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Your context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op` | The operation to note. One of the OPSTR_\* constants. |
| `int uid` | The user id of the application attempting to perform the operation. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | The name of the application attempting to perform the operation. |

| Returns |
|---|---|
| `int` | Returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED()` if the operation is allowed, or `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED()` if it is not allowed and should be silently ignored (without causing the app to crash). |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If the app has been configured to crash on this op. |

### noteOpNoThrow

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static int noteOpNoThrow(
    @NonNull Context context,
    @NonNull String op,
    int uid,
    @NonNull String packageName
)
```

Like `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)` but instead of throwing a `https://developer.android.com/reference/java/lang/SecurityException.html` it returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()`.

### noteProxyOp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
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 `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | Your context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html op` | The operation to note. One of the OPSTR_\* constants. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html proxiedPackageName` | The name of the application calling into the proxy application. |

| Returns |
|---|---|
| `int` | Returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED()` if the operation is allowed, or `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED()` if it is not allowed and should be silently ignored (without causing the app to crash). |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If the app has been configured to crash on this op. |

### noteProxyOpNoThrow

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static int noteProxyOpNoThrow(
    @NonNull Context context,
    @NonNull String op,
    @NonNull String proxiedPackageName
)
```

Like `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#noteProxyOp(android.content.Context,java.lang.String,java.lang.String)` but instead of throwing a `https://developer.android.com/reference/java/lang/SecurityException.html` it returns `https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()`.

### permissionToOp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @Nullable String permissionToOp(@NonNull String permission)
```

Gets the app op name associated with a given permission.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html permission` | The permission. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | The app op associated with the permission or null. |