AppOpsManager
public
class
AppOpsManager
extends Object
| java.lang.Object | |
| ↳ | android.app.AppOpsManager |
API for interacting with "application operation" tracking.
This API is not generally intended for third party application developers; most
features are only available to system applications. Obtain an instance of it through
Context.getSystemService with
Context.APP_OPS_SERVICE.
Summary
Nested classes | |
|---|---|
interface |
AppOpsManager.OnOpChangedListener
Callback for notification of changes to operation state. |
Constants | |
|---|---|
int |
MODE_ALLOWED
Result from |
int |
MODE_DEFAULT
Result from |
int |
MODE_ERRORED
Result from |
int |
MODE_IGNORED
Result from |
String |
OPSTR_ADD_VOICEMAIL
Required to access phone state related information. |
String |
OPSTR_ANSWER_PHONE_CALLS
Answer incoming phone calls |
String |
OPSTR_BODY_SENSORS
Access to body sensors such as heart rate, etc. |
String |
OPSTR_CALL_PHONE
Allows an application to initiate a phone call. |
String |
OPSTR_CAMERA
Required to be able to access the camera device. |
String |
OPSTR_COARSE_LOCATION
Access to coarse location information. |
String |
OPSTR_FINE_LOCATION
Access to fine location information. |
String |
OPSTR_GET_USAGE_STATS
Access to |
String |
OPSTR_MOCK_LOCATION
Inject mock location into the system. |
String |
OPSTR_MONITOR_HIGH_POWER_LOCATION
Continually monitoring location data with a relatively high power request. |
String |
OPSTR_MONITOR_LOCATION
Continually monitoring location data. |
String |
OPSTR_PICTURE_IN_PICTURE
Access to picture-in-picture. |
String |
OPSTR_PROCESS_OUTGOING_CALLS
Access APIs for diverting outgoing calls |
String |
OPSTR_READ_CALENDAR
Allows an application to read the user's calendar data. |
String |
OPSTR_READ_CALL_LOG
Allows an application to read the user's call log. |
String |
OPSTR_READ_CELL_BROADCASTS
Read previously received cell broadcast messages. |
String |
OPSTR_READ_CONTACTS
Allows an application to read the user's contacts data. |
String |
OPSTR_READ_EXTERNAL_STORAGE
Read external storage. |
String |
OPSTR_READ_PHONE_NUMBERS
|
String |
OPSTR_READ_PHONE_STATE
Required to access phone state related information. |
String |
OPSTR_READ_SMS
Allows an application to read SMS messages. |
String |
OPSTR_RECEIVE_MMS
Allows an application to receive MMS messages. |
String |
OPSTR_RECEIVE_SMS
Allows an application to receive SMS messages. |
String |
OPSTR_RECEIVE_WAP_PUSH
Allows an application to receive WAP push messages. |
String |
OPSTR_RECORD_AUDIO
Required to be able to access the microphone device. |
String |
OPSTR_SEND_SMS
Allows an application to send SMS messages. |
String |
OPSTR_SYSTEM_ALERT_WINDOW
Required to draw on top of other apps. |
String |
OPSTR_USE_FINGERPRINT
Use the fingerprint API. |
String |
OPSTR_USE_SIP
Access APIs for SIP calling over VOIP or WiFi |
String |
OPSTR_WRITE_CALENDAR
Allows an application to write to the user's calendar data. |
String |
OPSTR_WRITE_CALL_LOG
Allows an application to write to the user's call log. |
String |
OPSTR_WRITE_CONTACTS
Allows an application to write to the user's contacts data. |
String |
OPSTR_WRITE_EXTERNAL_STORAGE
Write external storage. |
String |
OPSTR_WRITE_SETTINGS
Required to write/modify/update system settingss. |
Public methods | |
|---|---|
int
|
checkOp(String op, int uid, String packageName)
Do a quick check for whether an application might be able to perform an operation. |
int
|
checkOpNoThrow(String op, int uid, String packageName)
Like |
void
|
checkPackage(int uid, String packageName)
Do a quick check to validate if a package name belongs to a UID. |
void
|
finishOp(String op, int uid, String packageName)
Report that an application is no longer performing an operation that had previously
been started with |
int
|
noteOp(String op, int uid, String packageName)
Make note of an application performing an operation. |
int
|
noteOpNoThrow(String op, int uid, String packageName)
Like |
int
|
noteProxyOp(String op, String proxiedPackageName)
Make note of an application performing an operation on behalf of another application when handling an IPC. |
int
|
noteProxyOpNoThrow(String op, String proxiedPackageName)
Like |
static
String
|
permissionToOp(String permission)
Gets the app op name associated with a given permission. |
int
|
startOp(String op, int uid, String packageName)
Report that an application has started executing a long-running operation. |
int
|
startOpNoThrow(String op, int uid, String packageName)
Like |
void
|
startWatchingMode(String op, String packageName, AppOpsManager.OnOpChangedListener callback)
Monitor for changes to the operating mode for the given op in the given app package. |
void
|
stopWatchingMode(AppOpsManager.OnOpChangedListener callback)
Stop monitoring that was previously started with |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
MODE_ALLOWED
int MODE_ALLOWED
Result from checkOp(String, int, String), noteOp(String, int, String), startOp(String, int, String): the given caller is
allowed to perform the given operation.
Constant Value: 0 (0x00000000)
MODE_DEFAULT
int MODE_DEFAULT
Result from checkOp(String, int, String), noteOp(String, int, String), startOp(String, int, 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.
Constant Value: 3 (0x00000003)
MODE_ERRORED
int MODE_ERRORED
Result from checkOpNoThrow(String, int, String), noteOpNoThrow(String, int, String), startOpNoThrow(String, int, 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.
Constant Value: 2 (0x00000002)
MODE_IGNORED
int MODE_IGNORED
Result from checkOp(String, int, String), noteOp(String, int, String), startOp(String, int, 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).
Constant Value: 1 (0x00000001)
OPSTR_ADD_VOICEMAIL
String OPSTR_ADD_VOICEMAIL
Required to access phone state related information.
Constant Value: "android:add_voicemail"
OPSTR_ANSWER_PHONE_CALLS
String OPSTR_ANSWER_PHONE_CALLS
Answer incoming phone calls
Constant Value: "android:answer_phone_calls"
OPSTR_BODY_SENSORS
String OPSTR_BODY_SENSORS
Access to body sensors such as heart rate, etc.
Constant Value: "android:body_sensors"
OPSTR_CALL_PHONE
String OPSTR_CALL_PHONE
Allows an application to initiate a phone call.
Constant Value: "android:call_phone"
OPSTR_CAMERA
String OPSTR_CAMERA
Required to be able to access the camera device.
Constant Value: "android:camera"
OPSTR_COARSE_LOCATION
String OPSTR_COARSE_LOCATION
Access to coarse location information.
Constant Value: "android:coarse_location"
OPSTR_FINE_LOCATION
String OPSTR_FINE_LOCATION
Access to fine location information.
Constant Value: "android:fine_location"
OPSTR_GET_USAGE_STATS
String OPSTR_GET_USAGE_STATS
Access to UsageStatsManager.
Constant Value: "android:get_usage_stats"
OPSTR_MOCK_LOCATION
String OPSTR_MOCK_LOCATION
Inject mock location into the system.
Constant Value: "android:mock_location"
OPSTR_MONITOR_HIGH_POWER_LOCATION
String OPSTR_MONITOR_HIGH_POWER_LOCATION
Continually monitoring location data with a relatively high power request.
Constant Value: "android:monitor_location_high_power"
OPSTR_MONITOR_LOCATION
String OPSTR_MONITOR_LOCATION
Continually monitoring location data.
Constant Value: "android:monitor_location"
OPSTR_PICTURE_IN_PICTURE
String OPSTR_PICTURE_IN_PICTURE
Access to picture-in-picture.
Constant Value: "android:picture_in_picture"
OPSTR_PROCESS_OUTGOING_CALLS
String OPSTR_PROCESS_OUTGOING_CALLS
Access APIs for diverting outgoing calls
Constant Value: "android:process_outgoing_calls"
OPSTR_READ_CALENDAR
String OPSTR_READ_CALENDAR
Allows an application to read the user's calendar data.
Constant Value: "android:read_calendar"
OPSTR_READ_CALL_LOG
String OPSTR_READ_CALL_LOG
Allows an application to read the user's call log.
Constant Value: "android:read_call_log"
OPSTR_READ_CELL_BROADCASTS
String OPSTR_READ_CELL_BROADCASTS
Read previously received cell broadcast messages.
Constant Value: "android:read_cell_broadcasts"
OPSTR_READ_CONTACTS
String OPSTR_READ_CONTACTS
Allows an application to read the user's contacts data.
Constant Value: "android:read_contacts"
OPSTR_READ_EXTERNAL_STORAGE
String OPSTR_READ_EXTERNAL_STORAGE
Read external storage.
Constant Value: "android:read_external_storage"
OPSTR_READ_PHONE_NUMBERS
String OPSTR_READ_PHONE_NUMBERS
Constant Value: "android:read_phone_numbers"
OPSTR_READ_PHONE_STATE
String OPSTR_READ_PHONE_STATE
Required to access phone state related information.
Constant Value: "android:read_phone_state"
OPSTR_READ_SMS
String OPSTR_READ_SMS
Allows an application to read SMS messages.
Constant Value: "android:read_sms"
OPSTR_RECEIVE_MMS
String OPSTR_RECEIVE_MMS
Allows an application to receive MMS messages.
Constant Value: "android:receive_mms"
OPSTR_RECEIVE_SMS
String OPSTR_RECEIVE_SMS
Allows an application to receive SMS messages.
Constant Value: "android:receive_sms"
OPSTR_RECEIVE_WAP_PUSH
String OPSTR_RECEIVE_WAP_PUSH
Allows an application to receive WAP push messages.
Constant Value: "android:receive_wap_push"
OPSTR_RECORD_AUDIO
String OPSTR_RECORD_AUDIO
Required to be able to access the microphone device.
Constant Value: "android:record_audio"
OPSTR_SEND_SMS
String OPSTR_SEND_SMS
Allows an application to send SMS messages.
Constant Value: "android:send_sms"
OPSTR_SYSTEM_ALERT_WINDOW
String OPSTR_SYSTEM_ALERT_WINDOW
Required to draw on top of other apps.
Constant Value: "android:system_alert_window"
OPSTR_USE_FINGERPRINT
String OPSTR_USE_FINGERPRINT
Use the fingerprint API.
Constant Value: "android:use_fingerprint"
OPSTR_USE_SIP
String OPSTR_USE_SIP
Access APIs for SIP calling over VOIP or WiFi
Constant Value: "android:use_sip"
OPSTR_WRITE_CALENDAR
String OPSTR_WRITE_CALENDAR
Allows an application to write to the user's calendar data.
Constant Value: "android:write_calendar"
OPSTR_WRITE_CALL_LOG
String OPSTR_WRITE_CALL_LOG
Allows an application to write to the user's call log.
Constant Value: "android:write_call_log"
OPSTR_WRITE_CONTACTS
String OPSTR_WRITE_CONTACTS
Allows an application to write to the user's contacts data.
Constant Value: "android:write_contacts"
OPSTR_WRITE_EXTERNAL_STORAGE
String OPSTR_WRITE_EXTERNAL_STORAGE
Write external storage.
Constant Value: "android:write_external_storage"
OPSTR_WRITE_SETTINGS
String OPSTR_WRITE_SETTINGS
Required to write/modify/update system settingss.
Constant Value: "android:write_settings"
Public methods
checkOp
int checkOp (String op, int uid, String packageName)
Do a quick check for whether an application might be able to perform an operation.
This is not a security check; you must use noteOp(String, int, String)
or startOp(String, int, String) for your actual security checks, which also
ensure that the given uid and package name are consistent. This function can just be
used for a quick check to see if an operation has been disabled for the application,
as an early reject of some work. This does not modify the time stamp or other data
about the operation.
| Parameters | |
|---|---|
op |
String: The operation to check. 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. |
| Returns | |
|---|---|
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). |
| Throws | |
|---|---|
SecurityException |
If the app has been configured to crash on this op. |
checkOpNoThrow
int checkOpNoThrow (String op, int uid, String packageName)
Like checkOp(String, int, String) but instead of throwing a SecurityException it
returns MODE_ERRORED.
| Parameters | |
|---|---|
op |
String |
uid |
int |
packageName |
String |
| Returns | |
|---|---|
int |
|
checkPackage
void checkPackage (int uid,
String packageName)
Do a quick check to validate if a package name belongs to a UID.
| Parameters | |
|---|---|
uid |
int |
packageName |
String |
| Throws | |
|---|---|
SecurityException |
if the package name doesn't belong to the given UID, or if ownership cannot be verified. |
finishOp
void finishOp (String op, int uid, String packageName)
Report that an application is no longer performing an operation that had previously
been started with startOp(String, int, String). There is no validation of input
or result; the parameters supplied here must be the exact same ones previously passed
in when starting the operation.
| Parameters | |
|---|---|
op |
String |
uid |
int |
packageName |
String |
noteOp
int noteOp (String op, int uid, 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 MODE_IGNORED. If this call
succeeds, the last execution time of the operation for this app will be updated to
the current time.
| Parameters | |
|---|---|
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. |
| Returns | |
|---|---|
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). |
| Throws | |
|---|---|
SecurityException |
If the app has been configured to crash on this op. |
noteOpNoThrow
int noteOpNoThrow (String op, int uid, String packageName)
Like noteOp(String, int, String) but instead of throwing a SecurityException it
returns MODE_ERRORED.
| Parameters | |
|---|---|
op |
String |
uid |
int |
packageName |
String |
| Returns | |
|---|---|
int |
|
noteProxyOp
int noteProxyOp (String op, 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 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 | |
|---|---|
op |
String: The operation to note. One of the OPSTR_* constants. |
proxiedPackageName |
String: The name of the application calling into the proxy application. |
| Returns | |
|---|---|
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). |
| Throws | |
|---|---|
SecurityException |
If the app has been configured to crash on this op. |
noteProxyOpNoThrow
int noteProxyOpNoThrow (String op, String proxiedPackageName)
Like noteProxyOp(String, String) but instead
of throwing a SecurityException it returns MODE_ERRORED.
| Parameters | |
|---|---|
op |
String |
proxiedPackageName |
String |
| Returns | |
|---|---|
int |
|
permissionToOp
String permissionToOp (String permission)
Gets the app op name associated with a given permission.
The app op name is one of the public constants defined
in this class such as OPSTR_COARSE_LOCATION.
This API is intended to be used for mapping runtime
permissions to the corresponding app op.
| Parameters | |
|---|---|
permission |
String: The permission. |
| Returns | |
|---|---|
String |
The app op associated with the permission or null. |
startOp
int startOp (String op, int uid, String packageName)
Report that an application has started executing a long-running 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 and the operation will be marked as "running". In this case you must
later call finishOp(String, int, String) to report when the application is no
longer performing the operation.
| Parameters | |
|---|---|
op |
String: The operation to start. 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. |
| Returns | |
|---|---|
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). |
| Throws | |
|---|---|
SecurityException |
If the app has been configured to crash on this op. |
startOpNoThrow
int startOpNoThrow (String op, int uid, String packageName)
Like startOp(String, int, String) but instead of throwing a SecurityException it
returns MODE_ERRORED.
| Parameters | |
|---|---|
op |
String |
uid |
int |
packageName |
String |
| Returns | |
|---|---|
int |
|
startWatchingMode
void startWatchingMode (String op, String packageName, AppOpsManager.OnOpChangedListener callback)
Monitor for changes to the operating mode for the given op in the given app package.
| Parameters | |
|---|---|
op |
String: The operation to monitor, one of OPSTR_*. |
packageName |
String: The name of the application to monitor. |
callback |
AppOpsManager.OnOpChangedListener: Where to report changes.
|
stopWatchingMode
void stopWatchingMode (AppOpsManager.OnOpChangedListener callback)
Stop monitoring that was previously started with startWatchingMode(String, String, AppOpsManager.OnOpChangedListener). All
monitoring associated with this callback will be removed.
| Parameters | |
|---|---|
callback |
AppOpsManager.OnOpChangedListener |
Interfaces
- ActionBar.OnMenuVisibilityListener
- ActionBar.OnNavigationListener
- ActionBar.TabListener
- AlarmManager.OnAlarmListener
- Application.ActivityLifecycleCallbacks
- Application.OnProvideAssistDataListener
- AppOpsManager.OnOpChangedListener
- DatePickerDialog.OnDateSetListener
- FragmentBreadCrumbs.OnBreadCrumbClickListener
- FragmentManager.BackStackEntry
- FragmentManager.OnBackStackChangedListener
- KeyguardManager.OnKeyguardExitResult
- LoaderManager.LoaderCallbacks
- Notification.Action.Extender
- Notification.Extender
- PendingIntent.OnFinished
- SearchManager.OnCancelListener
- SearchManager.OnDismissListener
- SharedElementCallback.OnSharedElementsReadyListener
- TimePickerDialog.OnTimeSetListener
- UiAutomation.AccessibilityEventFilter
- UiAutomation.OnAccessibilityEventListener
Classes
- ActionBar
- ActionBar.LayoutParams
- ActionBar.Tab
- Activity
- ActivityGroup
- ActivityManager
- ActivityManager.AppTask
- ActivityManager.MemoryInfo
- ActivityManager.ProcessErrorStateInfo
- ActivityManager.RecentTaskInfo
- ActivityManager.RunningAppProcessInfo
- ActivityManager.RunningServiceInfo
- ActivityManager.RunningTaskInfo
- ActivityManager.TaskDescription
- ActivityOptions
- AlarmManager
- AlarmManager.AlarmClockInfo
- AlertDialog
- AlertDialog.Builder
- AliasActivity
- Application
- ApplicationErrorReport
- ApplicationErrorReport.AnrInfo
- ApplicationErrorReport.BatteryInfo
- ApplicationErrorReport.CrashInfo
- ApplicationErrorReport.RunningServiceInfo
- AppOpsManager
- AutomaticZenRule
- DatePickerDialog
- Dialog
- DialogFragment
- DownloadManager
- DownloadManager.Query
- DownloadManager.Request
- ExpandableListActivity
- Fragment
- Fragment.SavedState
- FragmentBreadCrumbs
- FragmentContainer
- FragmentController
- FragmentHostCallback
- FragmentManager
- FragmentManager.FragmentLifecycleCallbacks
- FragmentManagerNonConfig
- FragmentTransaction
- Instrumentation
- Instrumentation.ActivityMonitor
- Instrumentation.ActivityResult
- IntentService
- KeyguardManager
- KeyguardManager.KeyguardDismissCallback
- KeyguardManager.KeyguardLock
- LauncherActivity
- LauncherActivity.IconResizer
- LauncherActivity.ListItem
- ListActivity
- ListFragment
- LoaderManager
- LocalActivityManager
- MediaRouteActionProvider
- MediaRouteButton
- NativeActivity
- Notification
- Notification.Action
- Notification.Action.Builder
- Notification.Action.WearableExtender
- Notification.BigPictureStyle
- Notification.BigTextStyle
- Notification.Builder
- Notification.CarExtender
- Notification.CarExtender.Builder
- Notification.CarExtender.UnreadConversation
- Notification.DecoratedCustomViewStyle
- Notification.DecoratedMediaCustomViewStyle
- Notification.InboxStyle
- Notification.MediaStyle
- Notification.MessagingStyle
- Notification.MessagingStyle.Message
- Notification.Style
- Notification.WearableExtender
- NotificationChannel
- NotificationChannelGroup
- NotificationManager
- NotificationManager.Policy
- PendingIntent
- PictureInPictureParams
- PictureInPictureParams.Builder
- Presentation
- ProgressDialog
- RemoteAction
- RemoteInput
- RemoteInput.Builder
- SearchableInfo
- SearchManager
- Service
- SharedElementCallback
- TabActivity
- TaskStackBuilder
- TimePickerDialog
- UiAutomation
- UiModeManager
- VoiceInteractor
- VoiceInteractor.AbortVoiceRequest
- VoiceInteractor.CommandRequest
- VoiceInteractor.CompleteVoiceRequest
- VoiceInteractor.ConfirmationRequest
- VoiceInteractor.PickOptionRequest
- VoiceInteractor.PickOptionRequest.Option
- VoiceInteractor.Prompt
- VoiceInteractor.Request
- WallpaperInfo
- WallpaperManager
Exceptions