public class AppOpsManager extends Object
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
.
Modifier and Type | Class and Description |
---|---|
static class |
AppOpsManager.OnOpChangedInternalListener
Callback for notification of changes to operation state.
|
static interface |
AppOpsManager.OnOpChangedListener
Callback for notification of changes to operation state.
|
static class |
AppOpsManager.OpEntry
Class holding the information about one unique operation of an application.
|
static class |
AppOpsManager.PackageOps
Class holding all of the operation information associated with an app.
|
Modifier and Type | Field and Description |
---|---|
static int |
_NUM_OP |
static int |
MODE_ALLOWED
Result from
checkOp(java.lang.String, int, java.lang.String) , noteOp(java.lang.String, int, java.lang.String) , startOp(java.lang.String, int, java.lang.String) : the given caller is
allowed to perform the given operation. |
static int |
MODE_DEFAULT
Result from
checkOp(java.lang.String, int, java.lang.String) , noteOp(java.lang.String, int, java.lang.String) , startOp(java.lang.String, int, java.lang.String) : the given caller should
use its default security check. |
static int |
MODE_ERRORED
Result from
checkOpNoThrow(java.lang.String, int, java.lang.String) , noteOpNoThrow(java.lang.String, int, java.lang.String) , startOpNoThrow(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 . |
static int |
MODE_IGNORED
Result from
checkOp(java.lang.String, int, java.lang.String) , noteOp(java.lang.String, int, java.lang.String) , startOp(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). |
static int |
OP_ACCESS_NOTIFICATIONS |
static int |
OP_ACTIVATE_VPN |
static int |
OP_ADD_VOICEMAIL |
static int |
OP_ASSIST_SCREENSHOT |
static int |
OP_ASSIST_STRUCTURE |
static int |
OP_AUDIO_ALARM_VOLUME |
static int |
OP_AUDIO_BLUETOOTH_VOLUME |
static int |
OP_AUDIO_MASTER_VOLUME |
static int |
OP_AUDIO_MEDIA_VOLUME |
static int |
OP_AUDIO_NOTIFICATION_VOLUME |
static int |
OP_AUDIO_RING_VOLUME |
static int |
OP_AUDIO_VOICE_VOLUME |
static int |
OP_BODY_SENSORS |
static int |
OP_CALL_PHONE |
static int |
OP_CAMERA |
static int |
OP_COARSE_LOCATION |
static int |
OP_FINE_LOCATION |
static int |
OP_GET_ACCOUNTS |
static int |
OP_GET_USAGE_STATS |
static int |
OP_GPS |
static int |
OP_MOCK_LOCATION |
static int |
OP_MONITOR_HIGH_POWER_LOCATION |
static int |
OP_MONITOR_LOCATION |
static int |
OP_MUTE_MICROPHONE |
static int |
OP_NEIGHBORING_CELLS |
static int |
OP_NONE |
static int |
OP_PLAY_AUDIO |
static int |
OP_POST_NOTIFICATION |
static int |
OP_PROCESS_OUTGOING_CALLS |
static int |
OP_PROJECT_MEDIA |
static int |
OP_READ_CALENDAR |
static int |
OP_READ_CALL_LOG |
static int |
OP_READ_CELL_BROADCASTS |
static int |
OP_READ_CLIPBOARD |
static int |
OP_READ_CONTACTS |
static int |
OP_READ_EXTERNAL_STORAGE |
static int |
OP_READ_ICC_SMS |
static int |
OP_READ_PHONE_STATE |
static int |
OP_READ_SMS |
static int |
OP_RECEIVE_EMERGECY_SMS |
static int |
OP_RECEIVE_MMS |
static int |
OP_RECEIVE_SMS |
static int |
OP_RECEIVE_WAP_PUSH |
static int |
OP_RECORD_AUDIO |
static int |
OP_RUN_IN_BACKGROUND |
static int |
OP_SEND_SMS |
static int |
OP_SYSTEM_ALERT_WINDOW |
static int |
OP_TAKE_AUDIO_FOCUS |
static int |
OP_TAKE_MEDIA_BUTTONS |
static int |
OP_TOAST_WINDOW |
static int |
OP_TURN_SCREEN_ON |
static int |
OP_USE_FINGERPRINT |
static int |
OP_USE_SIP |
static int |
OP_VIBRATE |
static int |
OP_WAKE_LOCK |
static int |
OP_WIFI_SCAN |
static int |
OP_WRITE_CALENDAR |
static int |
OP_WRITE_CALL_LOG |
static int |
OP_WRITE_CLIPBOARD |
static int |
OP_WRITE_CONTACTS |
static int |
OP_WRITE_EXTERNAL_STORAGE |
static int |
OP_WRITE_ICC_SMS |
static int |
OP_WRITE_SETTINGS |
static int |
OP_WRITE_SMS |
static int |
OP_WRITE_WALLPAPER |
static String |
OPSTR_ACTIVATE_VPN
Activate a VPN connection without user intervention.
|
static String |
OPSTR_ADD_VOICEMAIL
Required to access phone state related information.
|
static String |
OPSTR_BODY_SENSORS
Access to body sensors such as heart rate, etc.
|
static String |
OPSTR_CALL_PHONE
Allows an application to initiate a phone call.
|
static String |
OPSTR_CAMERA
Required to be able to access the camera device.
|
static String |
OPSTR_COARSE_LOCATION
Access to coarse location information.
|
static String |
OPSTR_FINE_LOCATION
Access to fine location information.
|
static String |
OPSTR_GET_ACCOUNTS |
static String |
OPSTR_GET_USAGE_STATS
Access to
UsageStatsManager . |
static String |
OPSTR_MOCK_LOCATION
Inject mock location into the system.
|
static String |
OPSTR_MONITOR_HIGH_POWER_LOCATION
Continually monitoring location data with a relatively high power request.
|
static String |
OPSTR_MONITOR_LOCATION
Continually monitoring location data.
|
static String |
OPSTR_READ_CALENDAR
Allows an application to read the user's calendar data.
|
static String |
OPSTR_READ_CALL_LOG
Allows an application to read the user's call log.
|
static String |
OPSTR_READ_CELL_BROADCASTS
Read previously received cell broadcast messages.
|
static String |
OPSTR_READ_CONTACTS
Allows an application to read the user's contacts data.
|
static String |
OPSTR_READ_EXTERNAL_STORAGE
Read external storage.
|
static String |
OPSTR_READ_PHONE_STATE
Required to access phone state related information.
|
static String |
OPSTR_READ_SMS
Allows an application to read SMS messages.
|
static String |
OPSTR_RECEIVE_MMS
Allows an application to receive MMS messages.
|
static String |
OPSTR_RECEIVE_SMS
Allows an application to receive SMS messages.
|
static String |
OPSTR_RECEIVE_WAP_PUSH
Allows an application to receive WAP push messages.
|
static String |
OPSTR_RECORD_AUDIO
Required to be able to access the microphone device.
|
static String |
OPSTR_SEND_SMS
Allows an application to send SMS messages.
|
static String |
OPSTR_SYSTEM_ALERT_WINDOW
Required to draw on top of other apps.
|
static String |
OPSTR_USE_FINGERPRINT
Use the fingerprint API.
|
static String |
OPSTR_USE_SIP
Access APIs for SIP calling over VOIP or WiFi
|
static String |
OPSTR_WRITE_CALENDAR
Allows an application to write to the user's calendar data.
|
static String |
OPSTR_WRITE_CALL_LOG
Allows an application to write to the user's call log.
|
static String |
OPSTR_WRITE_CONTACTS
Allows an application to write to the user's contacts data.
|
static String |
OPSTR_WRITE_EXTERNAL_STORAGE
Write external storage.
|
static String |
OPSTR_WRITE_SETTINGS
Required to write/modify/update system settingss.
|
Modifier and Type | Method and Description |
---|---|
int |
checkAudioOp(int op,
int stream,
int uid,
String packageName)
Like
checkOp(java.lang.String, int, java.lang.String) but at a stream-level for audio operations. |
int |
checkAudioOpNoThrow(int op,
int stream,
int uid,
String packageName)
Like
checkAudioOp(int, int, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
int |
checkOp(int op,
int uid,
String packageName)
Do a quick check for whether an application might be able to perform an operation.
|
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(int op,
int uid,
String packageName)
Like
checkOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
int |
checkOpNoThrow(String op,
int uid,
String packageName)
Like
checkOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
void |
checkPackage(int uid,
String packageName)
Do a quick check to validate if a package name belongs to a UID.
|
void |
finishOp(int op) |
void |
finishOp(int op,
int uid,
String packageName)
Report that an application is no longer performing an operation that had previously
been started with
startOp(int, int, String) . |
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) . |
List<AppOpsManager.PackageOps> |
getOpsForPackage(int uid,
String packageName,
int[] ops)
Retrieve current operation state for one application.
|
List<AppOpsManager.PackageOps> |
getPackagesForOps(int[] ops)
Retrieve current operation state for all applications.
|
static IBinder |
getToken(IAppOpsService service) |
int |
noteOp(int op) |
int |
noteOp(int op,
int uid,
String packageName)
Make note of an application performing an operation.
|
int |
noteOp(String op,
int uid,
String packageName)
Make note of an application performing an operation.
|
int |
noteOpNoThrow(int op,
int uid,
String packageName)
Like
noteOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
int |
noteOpNoThrow(String op,
int uid,
String packageName)
Like
noteOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
int |
noteProxyOp(int op,
String proxiedPackageName)
Make note of an application performing an operation on behalf of another
application when handling an IPC.
|
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(int op,
String proxiedPackageName)
|
int |
noteProxyOpNoThrow(String op,
String proxiedPackageName)
Like
noteProxyOp(String, String) but instead
of throwing a SecurityException it returns MODE_ERRORED . |
static boolean |
opAllowsReset(int op)
Retrieve whether the op allows itself to be reset.
|
static boolean |
opAllowSystemBypassRestriction(int op)
Retrieve whether the op allows the system (and system ui) to
bypass the user restriction.
|
static int |
opToDefaultMode(int op)
Retrieve the default mode for the operation.
|
static String |
opToName(int op)
Retrieve a non-localized name for the operation, for debugging output.
|
static String |
opToPermission(int op)
Retrieve the permission associated with an operation, or null if there is not one.
|
static String |
opToRestriction(int op)
Retrieve the user restriction associated with an operation, or null if there is not one.
|
static int |
opToSwitch(int op)
Retrieve the op switch that controls the given operation.
|
static String |
permissionToOp(String permission)
Gets the app op name associated with a given permission.
|
static int |
permissionToOpCode(String permission)
Retrieve the app op code for a permission, or null if there is not one.
|
void |
resetAllModes() |
void |
setMode(int code,
int uid,
String packageName,
int mode) |
void |
setRestriction(int code,
int usage,
int mode,
String[] exceptionPackages)
Set a non-persisted restriction on an audio operation at a stream-level.
|
void |
setUidMode(int code,
int uid,
int mode)
Sets given app op in the specified mode for app ops in the UID.
|
void |
setUidMode(String appOp,
int uid,
int mode)
Sets given app op in the specified mode for app ops in the UID.
|
void |
setUserRestriction(int code,
boolean restricted,
IBinder token) |
void |
setUserRestriction(int code,
boolean restricted,
IBinder token,
String[] exceptionPackages) |
void |
setUserRestrictionForUser(int code,
boolean restricted,
IBinder token,
String[] exceptionPackages,
int userId) |
int |
startOp(int op) |
int |
startOp(int op,
int uid,
String packageName)
Report that an application has started executing a long-running operation.
|
int |
startOp(String op,
int uid,
String packageName)
Report that an application has started executing a long-running operation.
|
int |
startOpNoThrow(int op,
int uid,
String packageName)
Like
startOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
int |
startOpNoThrow(String op,
int uid,
String packageName)
Like
startOp(java.lang.String, int, java.lang.String) but instead of throwing a SecurityException it
returns MODE_ERRORED . |
void |
startWatchingMode(int op,
String packageName,
AppOpsManager.OnOpChangedListener callback)
Monitor for changes to the operating mode for the given op in the given app package.
|
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
startWatchingMode(java.lang.String, java.lang.String, android.app.AppOpsManager.OnOpChangedListener) . |
static int |
strDebugOpToOp(String op) |
static int |
strOpToOp(String op) |
public static final int MODE_ALLOWED
checkOp(java.lang.String, int, java.lang.String)
, noteOp(java.lang.String, int, java.lang.String)
, startOp(java.lang.String, int, java.lang.String)
: the given caller is
allowed to perform the given operation.public static final int MODE_IGNORED
checkOp(java.lang.String, int, java.lang.String)
, noteOp(java.lang.String, int, java.lang.String)
, startOp(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 static final int MODE_ERRORED
checkOpNoThrow(java.lang.String, int, java.lang.String)
, noteOpNoThrow(java.lang.String, int, java.lang.String)
, startOpNoThrow(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
.public static final int MODE_DEFAULT
checkOp(java.lang.String, int, java.lang.String)
, noteOp(java.lang.String, int, java.lang.String)
, startOp(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.public static final int OP_NONE
public static final int OP_COARSE_LOCATION
public static final int OP_FINE_LOCATION
public static final int OP_GPS
public static final int OP_VIBRATE
public static final int OP_READ_CONTACTS
public static final int OP_WRITE_CONTACTS
public static final int OP_READ_CALL_LOG
public static final int OP_WRITE_CALL_LOG
public static final int OP_READ_CALENDAR
public static final int OP_WRITE_CALENDAR
public static final int OP_WIFI_SCAN
public static final int OP_POST_NOTIFICATION
public static final int OP_NEIGHBORING_CELLS
public static final int OP_CALL_PHONE
public static final int OP_READ_SMS
public static final int OP_WRITE_SMS
public static final int OP_RECEIVE_SMS
public static final int OP_RECEIVE_EMERGECY_SMS
public static final int OP_RECEIVE_MMS
public static final int OP_RECEIVE_WAP_PUSH
public static final int OP_SEND_SMS
public static final int OP_READ_ICC_SMS
public static final int OP_WRITE_ICC_SMS
public static final int OP_WRITE_SETTINGS
public static final int OP_SYSTEM_ALERT_WINDOW
public static final int OP_ACCESS_NOTIFICATIONS
public static final int OP_CAMERA
public static final int OP_RECORD_AUDIO
public static final int OP_PLAY_AUDIO
public static final int OP_READ_CLIPBOARD
public static final int OP_WRITE_CLIPBOARD
public static final int OP_TAKE_MEDIA_BUTTONS
public static final int OP_TAKE_AUDIO_FOCUS
public static final int OP_AUDIO_MASTER_VOLUME
public static final int OP_AUDIO_VOICE_VOLUME
public static final int OP_AUDIO_RING_VOLUME
public static final int OP_AUDIO_MEDIA_VOLUME
public static final int OP_AUDIO_ALARM_VOLUME
public static final int OP_AUDIO_NOTIFICATION_VOLUME
public static final int OP_AUDIO_BLUETOOTH_VOLUME
public static final int OP_WAKE_LOCK
public static final int OP_MONITOR_LOCATION
public static final int OP_MONITOR_HIGH_POWER_LOCATION
public static final int OP_GET_USAGE_STATS
public static final int OP_MUTE_MICROPHONE
public static final int OP_TOAST_WINDOW
public static final int OP_PROJECT_MEDIA
public static final int OP_ACTIVATE_VPN
public static final int OP_WRITE_WALLPAPER
public static final int OP_ASSIST_STRUCTURE
public static final int OP_ASSIST_SCREENSHOT
public static final int OP_READ_PHONE_STATE
public static final int OP_ADD_VOICEMAIL
public static final int OP_USE_SIP
public static final int OP_PROCESS_OUTGOING_CALLS
public static final int OP_USE_FINGERPRINT
public static final int OP_BODY_SENSORS
public static final int OP_READ_CELL_BROADCASTS
public static final int OP_MOCK_LOCATION
public static final int OP_READ_EXTERNAL_STORAGE
public static final int OP_WRITE_EXTERNAL_STORAGE
public static final int OP_TURN_SCREEN_ON
public static final int OP_GET_ACCOUNTS
public static final int OP_RUN_IN_BACKGROUND
public static final int _NUM_OP
public static final String OPSTR_COARSE_LOCATION
public static final String OPSTR_FINE_LOCATION
public static final String OPSTR_MONITOR_LOCATION
public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION
public static final String OPSTR_GET_USAGE_STATS
UsageStatsManager
.public static final String OPSTR_ACTIVATE_VPN
public static final String OPSTR_READ_CONTACTS
public static final String OPSTR_WRITE_CONTACTS
public static final String OPSTR_READ_CALL_LOG
public static final String OPSTR_WRITE_CALL_LOG
public static final String OPSTR_READ_CALENDAR
public static final String OPSTR_WRITE_CALENDAR
public static final String OPSTR_CALL_PHONE
public static final String OPSTR_READ_SMS
public static final String OPSTR_RECEIVE_SMS
public static final String OPSTR_RECEIVE_MMS
public static final String OPSTR_RECEIVE_WAP_PUSH
public static final String OPSTR_SEND_SMS
public static final String OPSTR_CAMERA
public static final String OPSTR_RECORD_AUDIO
public static final String OPSTR_READ_PHONE_STATE
public static final String OPSTR_ADD_VOICEMAIL
public static final String OPSTR_USE_SIP
public static final String OPSTR_USE_FINGERPRINT
public static final String OPSTR_BODY_SENSORS
public static final String OPSTR_READ_CELL_BROADCASTS
public static final String OPSTR_MOCK_LOCATION
public static final String OPSTR_READ_EXTERNAL_STORAGE
public static final String OPSTR_WRITE_EXTERNAL_STORAGE
public static final String OPSTR_SYSTEM_ALERT_WINDOW
public static final String OPSTR_WRITE_SETTINGS
public static final String OPSTR_GET_ACCOUNTS
public static int opToSwitch(int op)
public static String opToName(int op)
public static int strDebugOpToOp(String op)
public static String opToPermission(int op)
public static String opToRestriction(int op)
public static int permissionToOpCode(String permission)
public static boolean opAllowSystemBypassRestriction(int op)
public static int opToDefaultMode(int op)
public static boolean opAllowsReset(int op)
public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops)
ops
- The set of operations you are interested in, or null if you want all of them.public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops)
uid
- The uid of the application of interest.packageName
- The name of the application of interest.ops
- The set of operations you are interested in, or null if you want all of them.public void setUidMode(int code, int uid, int mode)
code
- The app op.uid
- The UID for which to set the app.mode
- The app op mode to set.public void setUidMode(String appOp, int uid, int mode)
appOp
- The app op.uid
- The UID for which to set the app.mode
- The app op mode to set.public void setUserRestriction(int code, boolean restricted, IBinder token)
public void setUserRestriction(int code, boolean restricted, IBinder token, String[] exceptionPackages)
public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, String[] exceptionPackages, int userId)
public void setMode(int code, int uid, String packageName, int mode)
public void setRestriction(int code, int usage, int mode, String[] exceptionPackages)
setMode(int, int, java.lang.String, int)
.code
- The operation to restrict.usage
- The AudioAttributes
usage value.mode
- The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict.exceptionPackages
- Optional list of packages to exclude from the restriction.public void resetAllModes()
public static String permissionToOp(String permission)
OPSTR_COARSE_LOCATION
.
This API is intended to be used for mapping runtime
permissions to the corresponding app op.permission
- The permission.public void startWatchingMode(String op, String packageName, AppOpsManager.OnOpChangedListener callback)
op
- The operation to monitor, one of OPSTR_*.packageName
- The name of the application to monitor.callback
- Where to report changes.public void startWatchingMode(int op, String packageName, AppOpsManager.OnOpChangedListener callback)
op
- The operation to monitor, one of OP_*.packageName
- The name of the application to monitor.callback
- Where to report changes.public void stopWatchingMode(AppOpsManager.OnOpChangedListener callback)
startWatchingMode(java.lang.String, java.lang.String, android.app.AppOpsManager.OnOpChangedListener)
. All
monitoring associated with this callback will be removed.public static int strOpToOp(String op)
public int checkOp(String op, int uid, String packageName)
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.op
- The operation to check. One of the OPSTR_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int checkOpNoThrow(String op, int uid, String packageName)
checkOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public int noteOp(String op, int uid, String packageName)
MODE_IGNORED
. If this call
succeeds, the last execution time of the operation for this app will be updated to
the current time.op
- The operation to note. One of the OPSTR_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int noteOpNoThrow(String op, int uid, String packageName)
noteOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public int noteProxyOp(String op, String proxiedPackageName)
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.op
- The operation to note. One of the OPSTR_* constants.proxiedPackageName
- The name of the application calling into the proxy application.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).SecurityException
- If the app has been configured to crash on this op.public int noteProxyOpNoThrow(String op, String proxiedPackageName)
noteProxyOp(String, String)
but instead
of throwing a SecurityException
it returns MODE_ERRORED
.public int startOp(String op, int uid, String packageName)
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.op
- The operation to start. One of the OPSTR_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int startOpNoThrow(String op, int uid, String packageName)
startOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public void finishOp(String op, int uid, String packageName)
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.public int checkOp(int op, int uid, String packageName)
noteOp(int, int, String)
or startOp(int, 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.op
- The operation to check. One of the OP_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int checkOpNoThrow(int op, int uid, String packageName)
checkOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public void checkPackage(int uid, String packageName)
SecurityException
- if the package name doesn't belong to the given
UID, or if ownership cannot be verified.public int checkAudioOp(int op, int stream, int uid, String packageName)
checkOp(java.lang.String, int, java.lang.String)
but at a stream-level for audio operations.public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName)
checkAudioOp(int, int, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public int noteOp(int op, int uid, String packageName)
MODE_IGNORED
. If this call
succeeds, the last execution time of the operation for this app will be updated to
the current time.op
- The operation to note. One of the OP_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int noteProxyOp(int op, String proxiedPackageName)
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.op
- The operation to note. One of the OPSTR_* constants.proxiedPackageName
- The name of the application calling into the proxy application.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).SecurityException
- If the proxy or proxied app has been configured to
crash on this op.public int noteProxyOpNoThrow(int op, String proxiedPackageName)
public int noteOpNoThrow(int op, int uid, String packageName)
noteOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public int noteOp(int op)
public static IBinder getToken(IAppOpsService service)
public int startOp(int op, int uid, String packageName)
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(int, int, String)
to report when the application is no
longer performing the operation.op
- The operation to start. One of the OP_* constants.uid
- The user id of the application attempting to perform the operation.packageName
- The name of the application attempting to perform the operation.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).SecurityException
- If the app has been configured to crash on this op.public int startOpNoThrow(int op, int uid, String packageName)
startOp(java.lang.String, int, java.lang.String)
but instead of throwing a SecurityException
it
returns MODE_ERRORED
.public int startOp(int op)
public void finishOp(int op, int uid, String packageName)
startOp(int, 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.public void finishOp(int op)