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
diff --git a/api/system-current.txt b/api/system-current.txt
index d8da475..0837a20 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -300,8 +300,8 @@
     method public static java.lang.String[] getOpStrs();
     method public java.util.List<android.app.AppOpsManager.PackageOps> getOpsForPackage(int, java.lang.String, int[]);
     method public java.util.List<android.app.AppOpsManager.PackageOps> 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 7df8de0..1e2244e 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -1612,6 +1612,20 @@
     }
 
     /**
+     * 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 @@
         }
     }
 
-    /**
-     * 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);