# 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)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/core/app/AppOpsManagerCompat "View this page in Java")


```
class AppOpsManagerCompat
```

<br />

*** ** * ** ***

Helper for accessing features in [android.app.AppOpsManager](https://developer.android.com/reference/android/app/AppOpsManager.html).

## Summary

| ### Constants |
|---|---|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [MODE_ALLOWED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED())` = 0` Result from [noteOp](https://developer.android.com/reference/kotlin/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. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [MODE_DEFAULT](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_DEFAULT())` = 3` Result from [noteOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)): the given caller should use its default security check. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [MODE_ERRORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED())` = 2` Result from [noteOpNoThrow](https://developer.android.com/reference/kotlin/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 [SecurityException](https://developer.android.com/reference/java/lang/SecurityException.html). |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [MODE_IGNORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED())` = 1` Result from [noteOp](https://developer.android.com/reference/kotlin/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 functions |
|---|---|
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [checkOrNoteProxyOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#checkOrNoteProxyOp(android.content.Context,int,java.lang.String,java.lang.String))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` proxyUid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` proxiedPackageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) `)` Check op for both proxy and proxied packages. |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [noteOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Make note of an application performing an operation. |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [noteOpNoThrow](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteOpNoThrow(android.content.Context,java.lang.String,int,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Like [noteOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteOp(android.content.Context,java.lang.String,int,java.lang.String)) but instead of throwing a [SecurityException](https://developer.android.com/reference/java/lang/SecurityException.html) it returns [MODE_ERRORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()). |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [noteProxyOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteProxyOp(android.content.Context,java.lang.String,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, proxiedPackageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Make note of an application performing an operation on behalf of another application when handling an IPC. |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [noteProxyOpNoThrow](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteProxyOpNoThrow(android.content.Context,java.lang.String,java.lang.String))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` proxiedPackageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) `)` Like [noteProxyOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#noteProxyOp(android.content.Context,java.lang.String,java.lang.String)) but instead of throwing a [SecurityException](https://developer.android.com/reference/java/lang/SecurityException.html) it returns [MODE_ERRORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ERRORED()). |
| `java-static `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | [permissionToOp](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#permissionToOp(java.lang.String))`(permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` 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)  

```
const val MODE_ALLOWED = 0: Int
```

Result from [noteOp](https://developer.android.com/reference/kotlin/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)  

```
const val MODE_DEFAULT = 3: Int
```

Result from [noteOp](https://developer.android.com/reference/kotlin/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)  

```
const val MODE_ERRORED = 2: Int
```

Result from [noteOpNoThrow](https://developer.android.com/reference/kotlin/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 [SecurityException](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)  

```
const val MODE_IGNORED = 1: Int
```

Result from [noteOp](https://developer.android.com/reference/kotlin/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 functions

### checkOrNoteProxyOp

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 28 and lower, fallback to [noteProxyOpNoThrow](https://developer.android.com/reference/kotlin/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 |
|---|---|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | Your context. |
| `proxyUid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The uid of the proxy application. |
| `op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The operation to note. One of the OPSTR_\* constants. |
| `proxiedPackageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The name of the application calling into the proxy application. |

| Returns |
|---|---|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Returns [MODE_ALLOWED](https://developer.android.com/reference/kotlin/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)  

```
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](https://developer.android.com/reference/kotlin/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 |
|---|---|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | Your context. |
| `op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The operation to note. One of the OPSTR_\* constants. |
| `uid: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The user id of the application attempting to perform the operation. |
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The name of the application attempting to perform the operation. |

| Returns |
|---|---|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Returns [MODE_ALLOWED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED()) if the operation is allowed, or [MODE_IGNORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED()) if it is not allowed and should be silently ignored (without causing the app to crash). |

| Throws |
|---|---|
| [java.lang.SecurityException](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)  

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

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

### noteProxyOp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/kotlin/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 |
|---|---|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | Your context. |
| `op: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The operation to note. One of the OPSTR_\* constants. |
| `proxiedPackageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The name of the application calling into the proxy application. |

| Returns |
|---|---|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Returns [MODE_ALLOWED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_ALLOWED()) if the operation is allowed, or [MODE_IGNORED](https://developer.android.com/reference/kotlin/androidx/core/app/AppOpsManagerCompat#MODE_IGNORED()) if it is not allowed and should be silently ignored (without causing the app to crash). |

| Throws |
|---|---|
| [java.lang.SecurityException](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)  

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

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

### permissionToOp

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

```
java-static fun permissionToOp(permission: String): String?
```

Gets the app op name associated with a given permission.  

| Parameters |
|---|---|
| `permission: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The permission. |

| Returns |
|---|---|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The app op associated with the permission or null. |