From a856e583b744bcd873a9ca500f9c69f5b8232c32 Mon Sep 17 00:00:00 2001 From: rambowang Date: Thu, 11 Jul 2024 13:55:31 -0500 Subject: Check phone or system process in PMS with multiple-user-aware way This CL checks phone or system process by the help of UserHandle.isSameApp which works not only for system user but also secondary users in which 1000/1001 is the app id instead of UID. Bug: 328511085 Test: atest PackageManagerServiceTest Flag: com.android.internal.telephony.flags.support_phone_uid_check_for_multiuser Change-Id: I97fabc526c3297f37fef71aeac9a37ea909ab4ef --- .../java/com/android/server/pm/PackageManagerService.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 2e63cdbf1823..f62a47515dc3 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -186,7 +186,6 @@ import com.android.internal.pm.pkg.component.ParsedInstrumentation; import com.android.internal.pm.pkg.component.ParsedMainComponent; import com.android.internal.pm.pkg.parsing.ParsingPackageUtils; import com.android.internal.telephony.CarrierAppUtils; -import com.android.internal.telephony.TelephonyPermissions; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.ConcurrentUtils; @@ -4493,7 +4492,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService void setSystemAppHiddenUntilInstalled(@NonNull Computer snapshot, String packageName, boolean hidden) { final int callingUid = Binder.getCallingUid(); - final boolean calledFromSystemOrPhone = TelephonyPermissions.isSystemOrPhone(callingUid); + final boolean calledFromSystemOrPhone = isSystemOrPhone(callingUid); if (!calledFromSystemOrPhone) { mContext.enforceCallingOrSelfPermission(Manifest.permission.SUSPEND_APPS, "setSystemAppHiddenUntilInstalled"); @@ -4518,8 +4517,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService boolean setSystemAppInstallState(@NonNull Computer snapshot, String packageName, boolean installed, int userId) { final int callingUid = Binder.getCallingUid(); - final boolean calledFromSystemOrPhone = callingUid == Process.PHONE_UID - || callingUid == Process.SYSTEM_UID; + final boolean calledFromSystemOrPhone = isSystemOrPhone(callingUid); if (!calledFromSystemOrPhone) { mContext.enforceCallingOrSelfPermission(Manifest.permission.SUSPEND_APPS, "setSystemAppHiddenUntilInstalled"); @@ -8123,4 +8121,9 @@ public class PackageManagerService implements PackageSender, TestUtilityService PackageManager.VERSION_CODE_HIGHEST, UserHandle.USER_SYSTEM, PackageManager.DELETE_ALL_USERS, true /*removedBySystem*/); } + + private static boolean isSystemOrPhone(int uid) { + return UserHandle.isSameApp(uid, Process.SYSTEM_UID) + || UserHandle.isSameApp(uid, Process.PHONE_UID); + } } -- cgit v1.2.3-59-g8ed1b