Class ShadowAppOpsManager
AppOpsManager
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class holding usage mode and exception packages. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
protected static final long
protected static final String
protected static final int
protected static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
__constructor__
(Context context, com.android.internal.app.IAppOpsService service) protected static void
protected int
Checks whether op was previously set usingsetMode(java.lang.String, int, java.lang.String, int)
int
checkOpNoThrow
(int op, int uid, String packageName) LikeAppOpsManager.checkOp(java.lang.String, int, java.lang.String)
but instead of throwing aSecurityException
it returnsAppOpsManager.MODE_ERRORED
.protected int
checkOpNoThrow
(String op, int uid, String packageName) Deprecated.protected void
checkPackage
(int uid, String packageName) protected void
Removes a fake long-running operation from the set.protected void
Removes a fake long-running operation from the set.getOpsForPackage
(int uid, String packageName, int[] ops) protected List<AppOpsManager.PackageOps>
getOpsForPackage
(int uid, String packageName, String[] ops) protected String
getOpString
(int opCode) protected List<AppOpsManager.PackageOps>
getPackagesForOps
(int[] ops) Returns app op details for all packages for which one ofsetMode(java.lang.String, int, java.lang.String, int)
methods was used to set the value of one of the given app ops (it does return those set to 'default' mode, while the true implementation usually doesn't).protected List<AppOpsManager.PackageOps>
getPackagesForOps
(String[] ops) Returns app op details for all packages for which one ofsetMode(java.lang.String, int, java.lang.String, int)
methods was used to set the value of one of the given app ops (it does return those set to 'default' mode, while the true implementation usually doesn't).getRestriction
(int code, int usage) boolean
isOpActive
(String op, int uid, String packageName) Checks whether the given op is active, i.e.int
protected int
protected int
noteOpNoThrow
(int op, int uid, String packageName) protected int
noteOpNoThrow
(int op, int uid, String packageName, String attributionTag, String message) protected int
noteProxyOpNoThrow
(int op, Object attributionSource, String message, boolean skipProxyOperation) protected int
noteProxyOpNoThrow
(int op, String proxiedPackageName) protected int
noteProxyOpNoThrow
(int op, String proxiedPackageName, int proxiedUid) protected int
noteProxyOpNoThrow
(int op, String proxiedPackageName, int proxiedUid, String proxiedAttributionTag, String message) static void
reset()
void
Int version ofsetMode(String, int, String, int)
.void
Change the operating mode for the given op in the given app package.void
setRestriction
(int code, int usage, int mode, String[] exceptionPackages) Sets audio restrictions.protected void
setUidMode
(int op, int uid, int mode) Int version ofsetUidMode(String, int, int)
.protected void
setUidMode
(String op, int uid, int mode) Change the operating mode for the given op in the given uid space.protected int
Stores a fake long-running operation.protected int
startOpNoThrow
(int op, int uid, String packageName) Stores a fake long-running operation.protected int
startOpNoThrow
(String op, int uid, String packageName, String attributionTag, String message) Stores a fake long-running operation.protected void
startWatchingMode
(int op, String packageName, int flags, AppOpsManager.OnOpChangedListener callback) protected void
startWatchingMode
(int op, String packageName, AppOpsManager.OnOpChangedListener callback) protected void
protected AppOpsManager.OpEntry
int
unsafeCheckOpNoThrow
(String op, int uid, String packageName) protected int
unsafeCheckOpRawNoThrow
(int op, int uid, String packageName) int
unsafeCheckOpRawNoThrow
(String op, int uid, String packageName) LikeunsafeCheckOpNoThrow(String, int, String)
but returns the raw mode associated with the op.
-
Field Details
-
OP_TIME
protected static final long OP_TIME- See Also:
-
REJECT_TIME
protected static final long REJECT_TIME- See Also:
-
DURATION
protected static final int DURATION- See Also:
-
PROXY_UID
protected static final int PROXY_UID- See Also:
-
PROXY_PACKAGE
- See Also:
-
-
Constructor Details
-
ShadowAppOpsManager
public ShadowAppOpsManager()
-
-
Method Details
-
__constructor__
@Implementation protected void __constructor__(Context context, com.android.internal.app.IAppOpsService service) -
__staticInitializer__
-
setMode
@Implementation(minSdk=28) @HiddenApi public void setMode(String op, int uid, String packageName, int mode) Change the operating mode for the given op in the given app package. You must pass in both the uid and name of the application whose mode is being modified; if these do not match, the modification will still be applied.This method is public for testing
checkOpNoThrow(java.lang.String, int, java.lang.String)
. IfcheckOpNoThrow(java.lang.String, int, java.lang.String)
is called afterwards with theop
,uid
, andpackageName
provided, it will return themode
set here.The mode set by this method takes precedence over the mode set by
setMode(String, int, String, int)
. This may not reflect the true implementation.- Parameters:
op
- The operation to modify. One of the OPSTR_* constants.uid
- The user id of the application whose mode will be changed.packageName
- The name of the application package name whose mode will be changed.
-
setMode
Int version ofsetMode(String, int, String, int)
.This method is public for testing
checkOpNoThrow(java.lang.String, int, java.lang.String)
. IfcheckOpNoThrow(java.lang.String, int, java.lang.String)
is called afterwards with theop
,uid
, andpackageName
provided, it will return themode
set here. -
setUidMode
Change the operating mode for the given op in the given uid space.This method is public for testing
checkOpNoThrow(java.lang.String, int, java.lang.String)
. IfcheckOpNoThrow(java.lang.String, int, java.lang.String)
is called afterwards with theop
anduid
provided, and anypackageName
, it will return themode
set here.The mode set by
setMode(String, int, String, int)
takes precedence over the mode set by this method. This may not reflect the true implementation.- Parameters:
op
- The operation to modify. One of the OPSTR_* constants.uid
- The user id of the application whose mode will be changed.
-
setUidMode
Int version ofsetUidMode(String, int, int)
.This method is public for testing
checkOpNoThrow(java.lang.String, int, java.lang.String)
. IfcheckOpNoThrow(java.lang.String, int, java.lang.String)
is called afterwards with theop
,ui
, andpackageName
provided, it will return themode
set here. -
getOpString
-
getPackagesForOps
@Implementation(minSdk=29) @HiddenApi protected List<AppOpsManager.PackageOps> getPackagesForOps(String[] ops) Returns app op details for all packages for which one ofsetMode(java.lang.String, int, java.lang.String, int)
methods was used to set the value of one of the given app ops (it does return those set to 'default' mode, while the true implementation usually doesn't). Also, we don't enforce any permission checks which might be needed in the true implementation.- Parameters:
ops
- The set of operations you are interested in, or null if you want all of them.- Returns:
- app ops information about each package, containing only ops that were specified as an argument
-
getPackagesForOps
Returns app op details for all packages for which one ofsetMode(java.lang.String, int, java.lang.String, int)
methods was used to set the value of one of the given app ops (it does return those set to 'default' mode, while the true implementation usually doesn't). Also, we don't enforce any permission checks which might be needed in the true implementation.- Parameters:
ops
- The set of operations you are interested in, or null if you want all of them.- Returns:
- app ops information about each package, containing only ops that were specified as an argument
-
unsafeCheckOpNoThrow
-
unsafeCheckOpRawNoThrow
@Implementation(minSdk=30) protected int unsafeCheckOpRawNoThrow(int op, int uid, String packageName) -
unsafeCheckOpRawNoThrow
@Implementation(minSdk=29) public int unsafeCheckOpRawNoThrow(String op, int uid, String packageName) LikeunsafeCheckOpNoThrow(String, int, String)
but returns the raw mode associated with the op. Does not throw a security exception, does not translateAppOpsManager.MODE_FOREGROUND
. -
startOp
@Implementation(minSdk=30) protected int startOp(String op, int uid, String packageName, String attributionTag, String message) Stores a fake long-running operation. It does not throw if a wrong uid is passed. -
startOpNoThrow
Stores a fake long-running operation. It does not throw if a wrong uid is passed. -
startOpNoThrow
@Implementation(minSdk=30) protected int startOpNoThrow(String op, int uid, String packageName, String attributionTag, String message) Stores a fake long-running operation. It does not throw if a wrong uid is passed. -
finishOp
Removes a fake long-running operation from the set. -
finishOp
@Implementation(minSdk=30) protected void finishOp(String op, int uid, String packageName, String attributionTag) Removes a fake long-running operation from the set. -
checkOp
Checks whether op was previously set usingsetMode(java.lang.String, int, java.lang.String, int)
-
isOpActive
Checks whether the given op is active, i.e. did someone callstartOp(String, int, String, String, String)
withoutfinishOp(String, int, String, String)
yet. -
checkOpNoThrow
@Implementation(minSdk=28) @Deprecated protected int checkOpNoThrow(String op, int uid, String packageName) Deprecated. -
checkOpNoThrow
LikeAppOpsManager.checkOp(java.lang.String, int, java.lang.String)
but instead of throwing aSecurityException
it returnsAppOpsManager.MODE_ERRORED
.Made public for testing
setMode(java.lang.String, int, java.lang.String, int)
as the method is@hide
. -
noteOp
-
noteOp
@Implementation(minSdk=30) protected int noteOp(int op, int uid, String packageName, String attributionTag, String message) -
noteOpNoThrow
-
noteOpNoThrow
@Implementation(minSdk=30) protected int noteOpNoThrow(int op, int uid, String packageName, String attributionTag, String message) -
noteProxyOpNoThrow
@Implementation(minSdk=23, maxSdk=29) @HiddenApi protected int noteProxyOpNoThrow(int op, String proxiedPackageName) -
noteProxyOpNoThrow
@Implementation(minSdk=29, maxSdk=29) @HiddenApi protected int noteProxyOpNoThrow(int op, String proxiedPackageName, int proxiedUid) -
noteProxyOpNoThrow
@Implementation(minSdk=30, maxSdk=30) @HiddenApi protected int noteProxyOpNoThrow(int op, String proxiedPackageName, int proxiedUid, String proxiedAttributionTag, String message) -
noteProxyOpNoThrow
@RequiresApi(api=31) @Implementation(minSdk=31) protected int noteProxyOpNoThrow(int op, Object attributionSource, String message, boolean skipProxyOperation) -
getOpsForPackage
@Implementation @HiddenApi public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) -
getOpsForPackage
@Implementation(minSdk=29) @HiddenApi protected List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, String[] ops) -
checkPackage
-
setRestriction
@Implementation @HiddenApi public void setRestriction(int code, int usage, int mode, String[] exceptionPackages) Sets audio restrictions.This method is public for testing, as the original method is
@hide
. -
getRestriction
-
startWatchingMode
@Implementation protected void startWatchingMode(int op, String packageName, AppOpsManager.OnOpChangedListener callback) -
startWatchingMode
@Implementation(minSdk=29) protected void startWatchingMode(int op, String packageName, int flags, AppOpsManager.OnOpChangedListener callback) -
stopWatchingMode
-
toOpEntry
-
reset
-