Don't set REVOKED_COMPAT for background permission that isn't granted.

Fixes: 148890737
Fixes: 148891305
Test: atest SplitPermissionTest
Test: atest PermissionFlagsTest
Change-Id: I4960334160bbe5f7e02c75f46e51c68b0119ae90
This commit is contained in:
Hai Zhang
2020-02-05 01:36:25 -08:00
parent c5794df21a
commit 29674ddab6

View File

@@ -2126,24 +2126,27 @@ public class AppOpsService extends IAppOpsService.Stub {
UserHandle user = UserHandle.getUserHandleForUid(uid);
boolean isRevokedCompat;
if (permissionInfo.backgroundPermission != null) {
boolean isBackgroundRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
if (packageManager.checkPermission(permissionInfo.backgroundPermission, packageName)
== PackageManager.PERMISSION_GRANTED) {
boolean isBackgroundRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
if (isBackgroundRevokedCompat && supportsRuntimePermissions) {
Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
+ " permission state, this is discouraged and you should revoke the"
+ " runtime permission instead: uid=" + uid + ", switchCode="
+ switchCode + ", mode=" + mode + ", permission="
+ permissionInfo.backgroundPermission);
}
if (isBackgroundRevokedCompat && supportsRuntimePermissions) {
Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
+ " permission state, this is discouraged and you should revoke the"
+ " runtime permission instead: uid=" + uid + ", switchCode="
+ switchCode + ", mode=" + mode + ", permission="
+ permissionInfo.backgroundPermission);
}
long identity = Binder.clearCallingIdentity();
try {
packageManager.updatePermissionFlags(permissionInfo.backgroundPermission,
packageName, PackageManager.FLAG_PERMISSION_REVOKED_COMPAT,
isBackgroundRevokedCompat
? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
} finally {
Binder.restoreCallingIdentity(identity);
long identity = Binder.clearCallingIdentity();
try {
packageManager.updatePermissionFlags(permissionInfo.backgroundPermission,
packageName, PackageManager.FLAG_PERMISSION_REVOKED_COMPAT,
isBackgroundRevokedCompat
? PackageManager.FLAG_PERMISSION_REVOKED_COMPAT : 0, user);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED