From c595f112dbbd9cd462fdfa2099408cf35a48c0dd Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Tue, 6 Nov 2018 14:20:38 -0800 Subject: [PATCH] Add AppOpsManager.opToDefaultMode() as system API. PermissionController needs to know the default mode of an app op and adjust it in case a background permission is fixed to revoked while a foreground permission is not for a pre-M app, because simply resetting the app op to its default mode might break the fixed state of the background permission. This change also removes AppOpsManager.resetUidMode() since it was introduced for the same use case in PermissionController but cannot handle the above case cleanly. Bug: 110557011 Test: build Change-Id: I53b1b375381a46b7dbece3cddaac460352d0336d --- api/system-current.txt | 2 +- core/java/android/app/AppOpsManager.java | 34 ++++++++++-------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index d8da475e3eec1..0837a20982ce9 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -300,8 +300,8 @@ package android.app { method public static java.lang.String[] getOpStrs(); method public java.util.List getOpsForPackage(int, java.lang.String, int[]); method public java.util.List getPackagesForOpStrs(java.lang.String[]); + method public static int opToDefaultMode(java.lang.String); method public static java.lang.String opToPermission(java.lang.String); - method public void resetUidMode(java.lang.String, int, boolean); method public void setMode(java.lang.String, int, java.lang.String, int); method public void setUidMode(java.lang.String, int, int); field public static final java.lang.String OPSTR_ACCEPT_HANDOVER = "android:accept_handover"; diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 7df8de0f7b666..1e2244e11bd25 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -1611,6 +1611,20 @@ public class AppOpsManager { return sOpDefaultMode[op]; } + /** + * Retrieve the default mode for the app op. + * + * @param appOp The app op name + * + * @return the default mode for the app op + * + * @hide + */ + @SystemApi + public static int opToDefaultMode(@NonNull String appOp) { + return opToDefaultMode(strOpToOp(appOp)); + } + /** * Retrieve the human readable mode. * @hide @@ -2483,26 +2497,6 @@ public class AppOpsManager { } } - /** - * Resets given app op in its default mode for app ops in the UID. - * This applies to all apps currently in the UID or installed in this UID in the future. - * - * @param appOp The app op. - * @param uid The UID for which to set the app. - * - * @hide - */ - @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) - @SystemApi - public void resetUidMode(String appOp, int uid, boolean force) { - int code = strOpToOp(appOp); - if (!(opAllowsReset(code) || force)) { - return; - } - int mode = opToDefaultMode(code); - setUidMode(code, uid, mode); - } - /** @hide */ public void setUserRestriction(int code, boolean restricted, IBinder token) { setUserRestriction(code, restricted, token, /*exceptionPackages*/null);