Stay organized with collections
Save and categorize content based on your preferences.
AppOpsManager.OnOpNotedCallback
public
static
abstract
class
AppOpsManager.OnOpNotedCallback
extends Object
Callback an app can set
to monitor the app-ops the
system has tracked for it. I.e. each time any app calls AppOpsManager.noteOp(String, int, String)
or AppOpsManager.startOp(String, int, String)
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.
setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() {
ArraySet> 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());
}
});
Summary
Public methods |
abstract
void
|
onAsyncNoted(AsyncNotedAppOp asyncOp)
Called when an app-op was noted for this package which cannot be delivered via the other
two mechanisms.
|
abstract
void
|
onNoted(SyncNotedAppOp op)
Called when an app-op was noted for this package inside of a synchronous
API call, i.e.
|
abstract
void
|
onSelfNoted(SyncNotedAppOp op)
Called when this app noted an app-op for its own package,
This is very similar to onNoted(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.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public constructors
OnOpNotedCallback
public OnOpNotedCallback ()
Public methods
onAsyncNoted
public abstract void onAsyncNoted (AsyncNotedAppOp asyncOp)
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.
Parameters |
asyncOp |
AsyncNotedAppOp : op noted
This value cannot be null . |
onNoted
public abstract void onNoted (SyncNotedAppOp op)
Called when an app-op was noted
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.
Parameters |
op |
SyncNotedAppOp : op noted
This value cannot be null . |
onSelfNoted
public abstract void onSelfNoted (SyncNotedAppOp op)
Called when this app noted an app-op for its own package,
This is very similar to onNoted(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.
Parameters |
op |
SyncNotedAppOp : op noted
This value cannot be null . |
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-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# AppOpsManager.OnOpNotedCallback\n\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nAppOpsManager.OnOpNotedCallback\n===============================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/app/AppOpsManager.OnOpNotedCallback \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\nabstract\nclass\nAppOpsManager.OnOpNotedCallback\n`\n\n\n`\n\nextends `[Object](/reference/java/lang/Object)`\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------------------------|\n| [java.lang.Object](/reference/java/lang/Object) ||\n| ↳ | android.app.AppOpsManager.OnOpNotedCallback |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nCallback an app can [set](/reference/android/app/AppOpsManager#setOnOpNotedCallback(java.util.concurrent.Executor,%20android.app.AppOpsManager.OnOpNotedCallback)) to monitor the app-ops the\nsystem has tracked for it. I.e. each time any app calls [AppOpsManager.noteOp(String, int, String)](/reference/android/app/AppOpsManager#noteOp(java.lang.String,%20int,%20java.lang.String)) or [AppOpsManager.startOp(String, int, String)](/reference/android/app/AppOpsManager#startOp(java.lang.String,%20int,%20java.lang.String))\none 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\nnecessarily for all other app-ops.** \n\n```\n setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() {\n ArraySet\u003e opsNotedForThisProcess = new ArraySet\u003c\u003e();\n\n private synchronized void addAccess(String op, String accessLocation) {\n // Ops are often noted when runtime permission protected APIs were called.\n // In this case permissionToOp() allows to resolve the permission\u003c-\u003eop\n opsNotedForThisProcess.add(new Pair(accessType, accessLocation));\n }\n\n public void onNoted(SyncNotedAppOp op) {\n // Accesses is currently happening, hence stack trace describes location of access\n addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace()));\n }\n\n public void onSelfNoted(SyncNotedAppOp op) {\n onNoted(op);\n }\n\n public void onAsyncNoted(AsyncNotedAppOp asyncOp) {\n // Stack trace is not useful for async ops as accessed happened on different thread\n addAccess(asyncOp.getOp(), asyncOp.getMessage());\n }\n });\n \n```\n\n\u003cbr /\u003e\n\n****See also:**\n- [AppOpsManager.setOnOpNotedCallback(Executor, OnOpNotedCallback)](/reference/android/app/AppOpsManager#setOnOpNotedCallback(java.util.concurrent.Executor,%20android.app.AppOpsManager.OnOpNotedCallback))\nSummary\n-------\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------|---|\n| ` `[OnOpNotedCallback](/reference/android/app/AppOpsManager.OnOpNotedCallback#OnOpNotedCallback())`() ` |\n| ### Public methods ||\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onAsyncNoted](/reference/android/app/AppOpsManager.OnOpNotedCallback#onAsyncNoted(android.app.AsyncNotedAppOp))`(`[AsyncNotedAppOp](/reference/android/app/AsyncNotedAppOp)` asyncOp) ` Called when an app-op was noted for this package which cannot be delivered via the other two mechanisms. |\n| ` abstract void` | ` `[onNoted](/reference/android/app/AppOpsManager.OnOpNotedCallback#onNoted(android.app.SyncNotedAppOp))`(`[SyncNotedAppOp](/reference/android/app/SyncNotedAppOp)` op) ` Called when an app-op was [noted](/reference/android/app/AppOpsManager#noteOp(java.lang.String,%20int,%20java.lang.String)) for this package inside of a synchronous API call, i.e. |\n| ` abstract void` | ` `[onSelfNoted](/reference/android/app/AppOpsManager.OnOpNotedCallback#onSelfNoted(android.app.SyncNotedAppOp))`(`[SyncNotedAppOp](/reference/android/app/SyncNotedAppOp)` op) ` Called when this app noted an app-op for its own package, This is very similar to [onNoted(SyncNotedAppOp)](/reference/android/app/AppOpsManager.OnOpNotedCallback#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| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.lang.Object](/reference/java/lang/Object)` ` |---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](/reference/java/lang/Object) | ` `[clone](/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object. | | ` boolean` | ` `[equals](/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](/reference/java/lang/Object)` obj) ` Indicates whether some other object is \"equal to\" this one. | | ` void` | ` `[finalize](/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final `[Class](/reference/java/lang/Class)`\u003c?\u003e` | ` `[getClass](/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`. | | ` int` | ` `[hashCode](/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object. | | ` final void` | ` `[notify](/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` `[notifyAll](/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor. | | ` `[String](/reference/java/lang/String) | ` `[toString](/reference/java/lang/Object#toString())`() ` Returns a string representation of the object. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||\nPublic constructors\n-------------------\n### OnOpNotedCallback\n```\npublic OnOpNotedCallback ()\n```\n\u003cbr /\u003e\n\u003cbr /\u003e\nPublic methods\n--------------\n### onAsyncNoted\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels)\n```\npublic abstract void onAsyncNoted (AsyncNotedAppOp asyncOp)\n```\nCalled when an app-op was noted for this package which cannot be delivered via the other\ntwo mechanisms.\nCalled as soon as possible after the app-op was noted, but the delivery delay is not\nguaranteed. Due to how async calls work in Android this might even be delivered slightly\nbefore the private data is delivered to the app.\nIf the app is not running or no [OnOpNotedCallback](/reference/android/app/AppOpsManager.OnOpNotedCallback) is registered a small amount\nof noted app-ops are buffered and then delivered as soon as a listener is registered.\n\u003cbr /\u003e\n| Parameters ||\n|-----------|-----------------------------------------------------------------|\n| `asyncOp` | `AsyncNotedAppOp`: op noted This value cannot be `null`. \u003cbr /\u003e |\n### onNoted\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels)\n```\npublic abstract void onNoted (SyncNotedAppOp op)\n```\nCalled when an app-op was [noted](/reference/android/app/AppOpsManager#noteOp(java.lang.String,%20int,%20java.lang.String)) for this package inside of a synchronous\nAPI call, i.e. a API call that returned data or waited until the action was performed.\nCalled on the calling thread before the API returns. This allows the app to e.g.\ncollect stack traces to figure out where the access came from.\n\u003cbr /\u003e\n| Parameters ||\n|------|----------------------------------------------------------------|\n| `op` | `SyncNotedAppOp`: op noted This value cannot be `null`. \u003cbr /\u003e |\n### onSelfNoted\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels)\n```\npublic abstract void onSelfNoted (SyncNotedAppOp op)\n```\nCalled when this app noted an app-op for its own package,\nThis is very similar to [onNoted(SyncNotedAppOp)](/reference/android/app/AppOpsManager.OnOpNotedCallback#onNoted(android.app.SyncNotedAppOp)) only that the tracking was not caused by the\nAPI provider in a separate process, but by one in the app's own process.\n\u003cbr /\u003e\n| Parameters ||\n|------|----------------------------------------------------------------|\n| `op` | `SyncNotedAppOp`: op noted This value cannot be `null`. \u003cbr /\u003e |**"]]