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

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

Fix crashes running android.appsecurity.cts.EphemeralTest

- test whether the caller is an instant app, not
the target app of the notification (if they are
different)
- Allow apps that share an app id to post as one
another

Test: runtest systemui-notification
Test: android.appsecurity.cts.EphemeralTest
Change-Id: I6bf7d42adb821ef22455d01f27e00276c0483220
Fixes: 116799402
Fixes: 116637376
parent 96f2ef48
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
@@ -3428,17 +3428,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