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
This commit is contained in:
Hai Zhang
2018-11-06 14:20:38 -08:00
parent d6a4c6768e
commit c595f112db
2 changed files with 15 additions and 21 deletions

View File

@@ -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);