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

Commit 0a145a53 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix crashes running android.appsecurity.cts.EphemeralTest"

parents e1251df8 ecc1b57f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -4289,7 +4289,8 @@ public class NotificationManagerService extends SystemService {
        }
        // posted from app A on behalf of app A
        if (isCallerSameApp(targetPkg, callingUid, userId)
                && TextUtils.equals(callingPkg, targetPkg)) {
                && (TextUtils.equals(callingPkg, targetPkg)
                || isCallerSameApp(callingPkg, callingUid, userId))) {
            return callingUid;
        }

@@ -4306,7 +4307,8 @@ public class NotificationManagerService extends SystemService {
            return targetUid;
        }

        throw new SecurityException("Caller " + callingUid + " cannot post for pkg " + targetPkg);
        throw new SecurityException("Caller " + callingPkg + ":" + callingUid
                + " cannot post for pkg " + targetPkg + " in user " + userId);
    }

    /**
@@ -4326,7 +4328,7 @@ public class NotificationManagerService extends SystemService {
        if (!isSystemNotification && !isNotificationFromListener) {
            synchronized (mNotificationLock) {
                if (mNotificationsByKey.get(r.sbn.getKey()) == null
                        && isCallerInstantApp(pkg, callingUid, r.getUserId())) {
                        && isCallerInstantApp(pkg, Binder.getCallingUid(), userId)) {
                    // Ephemeral apps have some special constraints for notifications.
                    // They are not allowed to create new notifications however they are allowed to
                    // update notifications created by the system (e.g. a foreground service
+5 −8
Original line number Diff line number Diff line
@@ -3448,17 +3448,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }

    @Test
    public void testResolveNotificationUid_sameAppWrongPkg() throws Exception {
    public void testResolveNotificationUid_sameAppDiffPackage() throws Exception {
        ApplicationInfo info = new ApplicationInfo();
        info.uid = Binder.getCallingUid();
        when(mPackageManager.getApplicationInfo(anyString(), anyInt(), anyInt())).thenReturn(info);
        when(mPackageManager.getApplicationInfo(anyString(), anyInt(), eq(0))).thenReturn(info);

        try {
            mService.resolveNotificationUid("caller", "other", info.uid, 0);
            fail("Incorrect pkg didn't throw security exception");
        } catch (SecurityException e) {
            // yay
        }
        int actualUid = mService.resolveNotificationUid("caller", "callerAlso", info.uid, 0);

        assertEquals(info.uid, actualUid);
    }

    @Test