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

Commit 1fc468c1 authored by Gavin Corkery's avatar Gavin Corkery Committed by Automerger Merge Worker
Browse files

Merge "Add isSameApp to PackageManagerInternal" into tm-dev am: 4682aac6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16932092

Change-Id: Ic95175845427ac38051db7ca998f9c453cb910b5
parents 712b52bd 4682aac6
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -194,6 +194,19 @@ public abstract class PackageManagerInternal {
     */
    public abstract boolean isPermissionsReviewRequired(String packageName, int userId);


    /**
     * Gets whether a given package name belongs to the calling uid. If the calling uid is an
     * {@link Process#isSdkSandboxUid(int) sdk sandbox uid}, checks whether the package name is
     * equal to {@link PackageManager#getSdkSandboxPackageName()}.
     *
     * @param packageName The package name to check.
     * @param callingUid The calling uid.
     * @param userId The user under which to check.
     * @return True if the package name belongs to the calling uid.
     */
    public abstract boolean isSameApp(String packageName, int callingUid, int userId);

    /**
     * Retrieve all of the information we know about a particular package/application.
     * @param filterCallingUid The results will be filtered in the context of this UID instead
+2 −21
Original line number Diff line number Diff line
@@ -9650,27 +9650,8 @@ public class NotificationManagerService extends SystemService {
        if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) {
            return;
        }
        try {
            ApplicationInfo ai = mPackageManager.getApplicationInfo(
                    pkg, 0, userId);
            if (ai == null) {
                throw new SecurityException("Unknown package " + pkg);
            }
            if (!UserHandle.isSameApp(ai.uid, uid)) {
                throw new SecurityException("Calling uid " + uid + " gave package "
                        + pkg + " which is owned by uid " + ai.uid);
            }
        } catch (RemoteException re) {
            throw new SecurityException("Unknown package " + pkg + "\n" + re);
        }
    }
    private boolean isCallerSameApp(String pkg) {
        try {
            checkCallerIsSameApp(pkg);
            return true;
        } catch (SecurityException e) {
            return false;
        if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) {
            throw new SecurityException("Package " + pkg + " is not owned by uid " + uid);
        }
    }
+13 −0
Original line number Diff line number Diff line
@@ -6964,6 +6964,19 @@ public class PackageManagerService extends IPackageManager.Stub
            return PackageManagerService.this.getKnownPackageNamesInternal(knownPackage, userId);
        }

        @Override
        public boolean isSameApp(@Nullable String packageName, int callingUid, int userId) {
            if (packageName == null) {
                return false;
            }

            if (Process.isSdkSandboxUid(callingUid)) {
                return packageName.equals(getSdkSandboxPackageName());
            }
            int uid = getPackageUid(packageName, 0, userId);
            return UserHandle.isSameApp(uid, callingUid);
        }

        @Override
        public boolean isResolveActivityComponent(ComponentInfo component) {
            return mResolveActivity.packageName.equals(component.packageName)
+2 −12
Original line number Diff line number Diff line
@@ -2232,18 +2232,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     * Return true if callingUid is system, or packageName belongs to that callingUid.
     */
    private boolean isSameApp(int callingUid, @Nullable String packageName) {
        try {
        if (callingUid != 0 && callingUid != SYSTEM_UID) {
                if (packageName == null) {
                    return false;
                }
                final int uid = AppGlobals.getPackageManager().getPackageUid(packageName,
                        PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                        UserHandle.getUserId(callingUid));
                return UserHandle.isSameApp(callingUid, uid);
            }
        } catch (RemoteException e) {
            // Should not happen
            return mPmInternal.isSameApp(packageName, callingUid, UserHandle.getUserId(callingUid));
        }
        return true;
    }
+5 −0
Original line number Diff line number Diff line
@@ -420,6 +420,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                    return getApplicationInfo((String) args[0], mUid);
                });
        when(mPackageManagerClient.getPackageUidAsUser(any(), anyInt())).thenReturn(mUid);
        when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenAnswer(
                (Answer<Boolean>) invocation -> {
                    Object[] args = invocation.getArguments();
                    return (int) args[1] == mUid;
                });
        final LightsManager mockLightsManager = mock(LightsManager.class);
        when(mockLightsManager.getLight(anyInt())).thenReturn(mock(LogicalLight.class));
        when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
Loading