Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a856e583 authored by rambowang's avatar rambowang
Browse files

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
parent 3606ee41
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -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);
    }
}