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

Commit d79fe1e2 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Only check uid when comparing apps

Without a sandbox sdk exception

Test: NotificationManagerServiceTest
Bug: 396667508
Fixes: 317957802
Flag: EXEMPT bug fix

Change-Id: Iac361101839083527333148c9d0aa579efcd110c
parent e60537b7
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -5018,8 +5018,8 @@ public class NotificationManagerService extends SystemService {
        public NotificationChannel getConversationNotificationChannel(String callingPkg, int userId,
                String targetPkg, String channelId, boolean returnParentIfNoConversationChannel,
                String conversationId) {
            if (canNotifyAsPackage(callingPkg, targetPkg, userId)
                    || isCallerSystemOrSystemUiOrShell()) {
            if (isCallerSystemOrSystemUiOrShell()
                    || canNotifyAsPackage(callingPkg, targetPkg, userId)) {
                int targetUid = -1;
                try {
                    targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId);
@@ -6400,7 +6400,7 @@ public class NotificationManagerService extends SystemService {
                String wellbeingPackage = getContext().getResources().getString(
                        com.android.internal.R.string.config_systemWellbeing);
                boolean isCallerWellbeing = !TextUtils.isEmpty(wellbeingPackage)
                        && mPackageManagerInternal.isSameApp(wellbeingPackage, uid, userId);
                        && isCallerSameApp(wellbeingPackage, uid, userId);
                if (!isCallerWellbeing) {
                    throw new IllegalArgumentException(
                            "Only the 'Wellbeing' package can use AutomaticZenRules with "
@@ -6686,7 +6686,7 @@ public class NotificationManagerService extends SystemService {
                    ? mEffectsSuppressors.get(0)
                    : null;
            if (isCallerSystemOrSystemUiOrShell() || suppressor == null
                    || mPackageManagerInternal.isSameApp(suppressor.getPackageName(),
                    || isCallerSameApp(suppressor.getPackageName(),
                    Binder.getCallingUid(), UserHandle.getUserId(Binder.getCallingUid()))) {
                return suppressor;
            }
@@ -11920,7 +11920,7 @@ public class NotificationManagerService extends SystemService {
        if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) {
            return;
        }
        if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) {
        if (!UserHandle.isSameApp(uid, mPackageManagerInternal.getPackageUid(pkg, 0L, userId))) {
            throw new SecurityException("Package " + pkg + " is not owned by uid " + uid);
        }
    }
+8 −1
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@ package com.android.server;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@@ -93,7 +95,12 @@ public class UiServiceTestCase {
                            return Build.VERSION_CODES.CUR_DEVELOPMENT;
                    }
                });

        when(mPmi.getPackageUid(eq(PKG_N_MR1), anyLong(), anyInt())).thenReturn(UID_N_MR1);
        when(mPmi.getPackageUid(eq(PKG_O), anyLong(), anyInt())).thenReturn(UID_O);
        when(mPmi.getPackageUid(eq(PKG_P), anyLong(), anyInt())).thenReturn(UID_P);
        when(mPmi.getPackageUid(eq(PKG_R), anyLong(), anyInt())).thenReturn(UID_R);
        when(mPmi.getPackageUid(eq(mContext.getPackageName()), anyLong(), eq(mUserId)))
                .thenReturn(mUid);
        LocalServices.removeServiceForTest(UserManagerInternal.class);
        LocalServices.addService(UserManagerInternal.class, mUmi);
        LocalServices.removeServiceForTest(UriGrantsManagerInternal.class);
+155 −101

File changed.

Preview size limit exceeded, changes collapsed.