2022-04-04 21:48:14 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: inthewaves <inthewaves@pm.me>
|
|
|
|
Date: Sat, 12 Sep 2020 12:28:34 -0700
|
|
|
|
Subject: [PATCH] support new special runtime permissions
|
|
|
|
|
|
|
|
These are treated as a runtime permission even for legacy apps. They
|
|
|
|
need to be granted by default for all apps to maintain compatibility.
|
|
|
|
|
|
|
|
Ported from 10: 4d5d82f4e2fb9ff68158bf30f3944591bb74dd04
|
|
|
|
|
|
|
|
Changes from 10:
|
|
|
|
- It seems like parts of PackageManagerService#resetUserChangesToRuntimePermissionsAndFlagsLPw
|
|
|
|
were refactored into PermissionManagerService#resetRuntimePermissionsInternal.
|
|
|
|
As a result, PackageManagerService is no longer modified.
|
|
|
|
|
|
|
|
[kdrag0n: Ported to Android 12]
|
|
|
|
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
|
|
|
|
---
|
|
|
|
.../permission/PermissionManagerService.java | 25 +++++++++++++++----
|
|
|
|
1 file changed, 20 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
2023-02-17 17:33:47 -05:00
|
|
|
index 9d0b2543e5ef..41128e4c617e 100644
|
2022-04-04 21:48:14 -04:00
|
|
|
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
|
|
|
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
|
|
|
@@ -1525,7 +1525,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
|
|
|
// their permissions as always granted runtime ones since we need
|
|
|
|
// to keep the review required permission flag per user while an
|
|
|
|
// install permission's state is shared across all users.
|
|
|
|
- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime()) {
|
|
|
|
+ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime() &&
|
|
|
|
+ !isSpecialRuntimePermission(permName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1568,7 +1569,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
|
|
|
+ " for package " + packageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M) {
|
|
|
|
+ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M &&
|
|
|
|
+ !isSpecialRuntimePermission(permName)) {
|
|
|
|
Slog.w(TAG, "Cannot grant runtime permission to a legacy app");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
@@ -1693,7 +1695,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
|
|
|
// their permissions as always granted runtime ones since we need
|
|
|
|
// to keep the review required permission flag per user while an
|
|
|
|
// install permission's state is shared across all users.
|
|
|
|
- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime()) {
|
|
|
|
+ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime() &&
|
|
|
|
+ !isSpecialRuntimePermission(permName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1898,7 +1901,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
|
|
|
|
|
|
|
// If this permission was granted by default or role, make sure it is.
|
|
|
|
if ((oldFlags & FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0
|
|
|
|
- || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0) {
|
|
|
|
+ || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0
|
|
|
|
+ || isSpecialRuntimePermission(permName)) {
|
|
|
|
// PermissionPolicyService will handle the app op for runtime permissions later.
|
|
|
|
grantRuntimePermissionInternal(packageName, permName, false,
|
|
|
|
Process.SYSTEM_UID, userId, delayingPermCallback);
|
2023-01-06 03:18:57 -05:00
|
|
|
@@ -2627,6 +2631,10 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-04 21:48:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean isSpecialRuntimePermission(final String permission) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Restore the permission state for a package.
|
|
|
|
*
|
2023-01-06 03:18:57 -05:00
|
|
|
@@ -2969,6 +2977,13 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-04 21:48:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ if (isSpecialRuntimePermission(permName) &&
|
|
|
|
+ origPermState == null) {
|
|
|
|
+ if (uidState.grantPermission(bp)) {
|
|
|
|
+ wasChanged = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
} else {
|
|
|
|
if (origPermState == null) {
|
|
|
|
// New permission
|
2023-01-06 03:18:57 -05:00
|
|
|
@@ -3806,7 +3821,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-04 21:48:14 -04:00
|
|
|
if (shouldGrantPermission) {
|
|
|
|
final int flags = getPermissionFlagsInternal(pkg.getPackageName(), permission,
|
|
|
|
myUid, userId);
|
|
|
|
- if (supportsRuntimePermissions) {
|
|
|
|
+ if (supportsRuntimePermissions || isSpecialRuntimePermission(permission)) {
|
|
|
|
// Installer cannot change immutable permissions.
|
|
|
|
if ((flags & immutableFlags) == 0) {
|
|
|
|
grantRuntimePermissionInternal(pkg.getPackageName(), permission, false,
|