Send package to permission check
While splitting the permissions from the package manager service,
we adjusted the implementation of checkUidPermission() which queried
for package objects separately from obtaining the package names
belonging to a UID. This caused some subtle timing issue where the
package object sometimes failed to be present.
Instead, send the affected package while in a sycnhronized block
to avoid the timing issue.
Fixes: 68260103
Test: Manual
Change-Id: I0b0e124ffd12a31569a1ed0d8a6a7b82cf824d63
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
index cb3b107..12aef53 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
@@ -242,7 +242,8 @@
return PackageManager.PERMISSION_DENIED;
}
- private int checkUidPermission(String permName, int uid, int callingUid) {
+ private int checkUidPermission(String permName, PackageParser.Package pkg, int uid,
+ int callingUid) {
final int callingUserId = UserHandle.getUserId(callingUid);
final boolean isCallerInstantApp =
mPackageManagerInt.getInstantAppPackageName(callingUid) != null;
@@ -253,28 +254,13 @@
return PackageManager.PERMISSION_DENIED;
}
- final String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
- if (packages != null && packages.length > 0) {
- PackageParser.Package pkg = null;
- for (String packageName : packages) {
- pkg = mPackageManagerInt.getPackage(packageName);
- if (pkg != null) {
- break;
- }
- }
- if (pkg == null) {
-Slog.e(TAG, "TODD: No package not found; UID: " + uid);
-Slog.e(TAG, "TODD: Packages: " + Arrays.toString(packages));
- return PackageManager.PERMISSION_DENIED;
- }
+ if (pkg != null) {
if (pkg.mSharedUserId != null) {
if (isCallerInstantApp) {
return PackageManager.PERMISSION_DENIED;
}
- } else {
- if (mPackageManagerInt.filterAppAccess(pkg, callingUid, callingUserId)) {
- return PackageManager.PERMISSION_DENIED;
- }
+ } else if (mPackageManagerInt.filterAppAccess(pkg, callingUid, callingUserId)) {
+ return PackageManager.PERMISSION_DENIED;
}
final PermissionsState permissionsState =
((PackageSetting) pkg.mExtras).getPermissionsState();
@@ -2054,8 +2040,9 @@
permName, packageName, callingUid, userId);
}
@Override
- public int checkUidPermission(String permName, int uid, int callingUid) {
- return PermissionManagerService.this.checkUidPermission(permName, uid, callingUid);
+ public int checkUidPermission(String permName, PackageParser.Package pkg, int uid,
+ int callingUid) {
+ return PermissionManagerService.this.checkUidPermission(permName, pkg, uid, callingUid);
}
@Override
public PermissionGroupInfo getPermissionGroupInfo(String groupName, int flags,