Stay organized with collections
Save and categorize content based on your preferences.
OnOpNotedCallback
abstract class OnOpNotedCallback
Callback an app can #setOnOpNotedCallback to monitor the app-ops the system has tracked for it. I.e. each time any app calls #noteOp or #startOp one of a method of this object is called.
There will be a call for all app-ops related to runtime permissions, but not necessarily for all other app-ops.
<b>
setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() {
ArraySet
<pair<string, string>
> opsNotedForThisProcess = new ArraySet<>(); private synchronized void addAccess(String op, String accessLocation) { // Ops are often noted when runtime permission protected APIs were called. // In this case permissionToOp() allows to resolve the permission<->op opsNotedForThisProcess.add(new Pair(accessType, accessLocation)); } public void onNoted(SyncNotedAppOp op) { // Accesses is currently happening, hence stack trace describes location of access addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace())); } public void onSelfNoted(SyncNotedAppOp op) { onNoted(op); } public void onAsyncNoted(AsyncNotedAppOp asyncOp) { // Stack trace is not useful for async ops as accessed happened on different thread addAccess(asyncOp.getOp(), asyncOp.getMessage()); } });
</pair<string,></b>
Summary
Public methods |
abstract Unit |
Called when an app-op was noted for this package which cannot be delivered via the other two mechanisms.
|
abstract Unit |
Called when an app-op was #noteOp for this package inside of a synchronous API call, i.
|
abstract Unit |
Called when this app noted an app-op for its own package,
|
Public constructors
OnOpNotedCallback
OnOpNotedCallback()
Public methods
onAsyncNoted
abstract fun onAsyncNoted(asyncOp: AsyncNotedAppOp): Unit
Called when an app-op was noted for this package which cannot be delivered via the other two mechanisms.
Called as soon as possible after the app-op was noted, but the delivery delay is not guaranteed. Due to how async calls work in Android this might even be delivered slightly before the private data is delivered to the app.
If the app is not running or no OnOpNotedCallback
is registered a small amount of noted app-ops are buffered and then delivered as soon as a listener is registered.
onNoted
abstract fun onNoted(op: SyncNotedAppOp): Unit
Called when an app-op was #noteOp for this package inside of a synchronous API call, i.e. a API call that returned data or waited until the action was performed.
Called on the calling thread before the API returns. This allows the app to e.g. collect stack traces to figure out where the access came from.
onSelfNoted
abstract fun onSelfNoted(op: SyncNotedAppOp): Unit
Called when this app noted an app-op for its own package,
This is very similar to onNoted
only that the tracking was not caused by the API provider in a separate process, but by one in the app's own process.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-13 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-13 UTC."],[],[],null,["# AppOpsManager.OnOpNotedCallback\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnOpNotedCallback\n=================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/app/AppOpsManager.OnOpNotedCallback \"View this page in Java\") \n\n```\nabstract class OnOpNotedCallback\n```\n\n|---|--------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.app.AppOpsManager.OnOpNotedCallback](#) |\n\nCallback an app can #setOnOpNotedCallback to monitor the app-ops the system has tracked for it. I.e. each time any app calls #noteOp or #startOp one of a method of this object is called.\n\n**There will be a call for all app-ops related to runtime permissions, but not necessarily for all other app-ops.** \n\n```kotlin\n\u003cb\u003e\n setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() {\n ArraySet\n \u003cpair\u003cstring, string\u003e\n > opsNotedForThisProcess = new ArraySet<>(); private synchronized void addAccess(String op, String accessLocation) { // Ops are often noted when runtime permission protected APIs were called. // In this case permissionToOp() allows to resolve the permission<->op opsNotedForThisProcess.add(new Pair(accessType, accessLocation)); } public void onNoted(SyncNotedAppOp op) { // Accesses is currently happening, hence stack trace describes location of access addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace())); } public void onSelfNoted(SyncNotedAppOp op) { onNoted(op); } public void onAsyncNoted(AsyncNotedAppOp asyncOp) { // Stack trace is not useful for async ops as accessed happened on different thread addAccess(asyncOp.getOp(), asyncOp.getMessage()); } }); \n \u003c/pair\u003cstring,\u003e\u003c/b\u003e\n```\n\nSummary\n-------\n\n| Public constructors ||\n|------------------------------------------------------|---|\n| [OnOpNotedCallback](#OnOpNotedCallback())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onAsyncNoted](#onAsyncNoted(android.app.AsyncNotedAppOp))`(`asyncOp:` `[AsyncNotedAppOp](/reference/kotlin/android/app/AsyncNotedAppOp)`)` Called when an app-op was noted for this package which cannot be delivered via the other two mechanisms. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onNoted](#onNoted(android.app.SyncNotedAppOp))`(`op:` `[SyncNotedAppOp](/reference/kotlin/android/app/SyncNotedAppOp)`)` Called when an app-op was #noteOp for this package inside of a synchronous API call, i. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSelfNoted](#onSelfNoted(android.app.SyncNotedAppOp))`(`op:` `[SyncNotedAppOp](/reference/kotlin/android/app/SyncNotedAppOp)`)` Called when this app noted an app-op for its own package, |\n\nPublic constructors\n-------------------\n\n### OnOpNotedCallback\n\n```\nOnOpNotedCallback()\n```\n\nPublic methods\n--------------\n\n### onAsyncNoted\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onAsyncNoted(asyncOp: AsyncNotedAppOp): Unit\n```\n\nCalled when an app-op was noted for this package which cannot be delivered via the other two mechanisms.\n\nCalled as soon as possible after the app-op was noted, but the delivery delay is not guaranteed. Due to how async calls work in Android this might even be delivered slightly before the private data is delivered to the app.\n\nIf the app is not running or no [OnOpNotedCallback](#) is registered a small amount of noted app-ops are buffered and then delivered as soon as a listener is registered.\n\n| Parameters ||\n|-----------|---------------------------------------------------------------------------------------------------------|\n| `asyncOp` | [AsyncNotedAppOp](/reference/kotlin/android/app/AsyncNotedAppOp): op noted This value cannot be `null`. |\n\n### onNoted\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onNoted(op: SyncNotedAppOp): Unit\n```\n\nCalled when an app-op was #noteOp for this package inside of a synchronous API call, i.e. a API call that returned data or waited until the action was performed.\n\nCalled on the calling thread before the API returns. This allows the app to e.g. collect stack traces to figure out where the access came from.\n\n| Parameters ||\n|------|-------------------------------------------------------------------------------------------------------|\n| `op` | [SyncNotedAppOp](/reference/kotlin/android/app/SyncNotedAppOp): op noted This value cannot be `null`. |\n\n### onSelfNoted\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onSelfNoted(op: SyncNotedAppOp): Unit\n```\n\nCalled when this app noted an app-op for its own package,\n\nThis is very similar to [onNoted](#onNoted(android.app.SyncNotedAppOp)) only that the tracking was not caused by the API provider in a separate process, but by one in the app's own process.\n\n| Parameters ||\n|------|-------------------------------------------------------------------------------------------------------|\n| `op` | [SyncNotedAppOp](/reference/kotlin/android/app/SyncNotedAppOp): op noted This value cannot be `null`. |"]]