Class ShadowAppOpsManager

java.lang.Object
org.robolectric.shadows.ShadowAppOpsManager

@Implements(value=android.app.AppOpsManager.class, looseSignatures=true) public class ShadowAppOpsManager extends Object
Shadow for AppOpsManager.
  • Field Details

  • Constructor Details

    • ShadowAppOpsManager

      public ShadowAppOpsManager()
  • Method Details

    • __constructor__

      @Implementation protected void __constructor__(Context context, com.android.internal.app.IAppOpsService service)
    • __staticInitializer__

      @Implementation protected static void __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 not be applied.

      This method is public for testing checkOpNoThrow(java.lang.String, int, java.lang.String). If checkOpNoThrow(java.lang.String, int, java.lang.String) is called afterwards with the op, ui, and packageName provided, it will return the mode set here.

      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

      @Implementation @HiddenApi public void setMode(int op, int uid, String packageName, int mode)
      Int version of setMode(String, int, String, int).

      This method is public for testing checkOpNoThrow(java.lang.String, int, java.lang.String). If checkOpNoThrow(java.lang.String, int, java.lang.String) is * called afterwards with the op, ui, and packageName provided, it will * return the mode set here.

    • getOpString

      protected String getOpString(int opCode)
    • getPackagesForOps

      @Implementation(minSdk=29) @HiddenApi protected List<AppOpsManager.PackageOps> getPackagesForOps(String[] ops)
      Returns app op details for all packages for which one of setMode(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

      @Implementation @HiddenApi protected List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops)
      Returns app op details for all packages for which one of setMode(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

      @Implementation(minSdk=29) public int unsafeCheckOpNoThrow(String op, int uid, String packageName)
    • 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)
      Like unsafeCheckOpNoThrow(String, int, String) but returns the raw mode associated with the op. Does not throw a security exception, does not translate AppOpsManager.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

      @Implementation(maxSdk=29) protected int startOpNoThrow(int op, int uid, String packageName)
      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

      @Implementation(maxSdk=29) protected void finishOp(int op, int uid, String packageName)
      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

      @Implementation(minSdk=30) protected int checkOp(String op, int uid, String packageName)
      Checks whether op was previously set using setMode(java.lang.String, int, java.lang.String, int)
    • isOpActive

      @Implementation(minSdk=30) public boolean isOpActive(String op, int uid, String packageName)
      Checks whether the given op is active, i.e. did someone call startOp(String, int, String, String, String) without finishOp(String, int, String, String) yet.
    • checkOpNoThrow

      @Implementation(minSdk=28) @Deprecated protected int checkOpNoThrow(String op, int uid, String packageName)
      Deprecated.
    • checkOpNoThrow

      @Implementation @HiddenApi public int checkOpNoThrow(int op, int uid, String packageName)
    • noteOp

      @Implementation public int noteOp(int op, int uid, String packageName)
    • noteOp

      @Implementation(minSdk=30) protected int noteOp(int op, int uid, String packageName, String attributionTag, String message)
    • noteOpNoThrow

      @Implementation protected int noteOpNoThrow(int op, int uid, String packageName)
    • 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(Object op, Object attributionSource, Object message, Object ignoredSkipProxyOperation)
    • 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

      @Implementation protected void checkPackage(int uid, String packageName)
    • 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

      public ShadowAppOpsManager.ModeAndException getRestriction(int code, int usage)
    • 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

      @Implementation protected void stopWatchingMode(AppOpsManager.OnOpChangedListener callback)
    • toOpEntry

      protected AppOpsManager.OpEntry toOpEntry(Integer op, int mode)
    • reset

      @Resetter public static void reset()