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

Commit 5bc56484 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Use a real pkg name and uid

Rather than trying to reconstruct it, as some apps use | in their tag.

Test: atest NotificationManagerServiceTest
Test: atest NotificationPermissionMigrationTest
Test: make sure an app that uses | in its tag can post notifs
Fixes: 218812985
Change-Id: Ic6332bdb827a3b603efe5b79d242bfe0bb61917d
parent ed3cc1bb
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -5805,6 +5805,7 @@ public class NotificationManagerService extends SystemService {
                            || channel.isImportanceLockedByCriticalDeviceFunction());
            final StatusBarNotification adjustedSbn = notificationRecord.getSbn();
            userId = adjustedSbn.getUser().getIdentifier();
            int uid =  adjustedSbn.getUid();
            ArrayMap<String, String> summaries = mAutobundledSummaries.get(userId);
            if (summaries == null) {
                summaries = new ArrayMap<>();
@@ -5851,7 +5852,7 @@ public class NotificationManagerService extends SystemService {
                        notificationRecord.getIsAppImportanceLocked());
                summaries.put(pkg, summarySbn.getKey());
            }
            if (summaryRecord != null && checkDisqualifyingFeatures(userId, MY_UID,
            if (summaryRecord != null && checkDisqualifyingFeatures(userId, uid,
                    summaryRecord.getSbn().getId(), summaryRecord.getSbn().getTag(), summaryRecord,
                    true)) {
                return summaryRecord;
@@ -6822,7 +6823,6 @@ public class NotificationManagerService extends SystemService {
            return false;
        }
        // blocked apps
        boolean isBlocked = !areNotificationsEnabledForPackageInt(pkg, uid);
        synchronized (mNotificationLock) {
@@ -7215,10 +7215,12 @@ public class NotificationManagerService extends SystemService {
                if (mAssistants.isEnabled()) {
                    mAssistants.onNotificationEnqueuedLocked(r);
                    mHandler.postDelayed(
                            new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs),
                            new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                                    r.getUid(), enqueueElapsedTimeMs),
                            DELAY_FOR_ASSISTANT_TIME);
                } else {
                    mHandler.post(new PostNotificationRunnable(r.getKey(), enqueueElapsedTimeMs));
                    mHandler.post(new PostNotificationRunnable(r.getKey(),
                            r.getSbn().getPackageName(), r.getUid(), enqueueElapsedTimeMs));
                }
            }
        }
@@ -7242,16 +7244,19 @@ public class NotificationManagerService extends SystemService {
    protected class PostNotificationRunnable implements Runnable {
        private final String key;
        private final long postElapsedTimeMs;
        private final String pkg;
        private final int uid;
        PostNotificationRunnable(String key, @ElapsedRealtimeLong long postElapsedTimeMs) {
        PostNotificationRunnable(String key, String pkg, int uid,
                @ElapsedRealtimeLong long postElapsedTimeMs) {
            this.key = key;
            this.pkg = pkg;
            this.uid = uid;
            this.postElapsedTimeMs = postElapsedTimeMs;
        }
        @Override
        public void run() {
            String pkg = StatusBarNotification.getPkgFromKey(key);
            int uid = StatusBarNotification.getUidFromKey(key);
            boolean appBanned = !areNotificationsEnabledForPackageInt(pkg, uid);
            synchronized (mNotificationLock) {
                try {
+20 −8
Original line number Diff line number Diff line
@@ -1338,7 +1338,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment);

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -1359,7 +1360,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mPreferencesHelper.getImportance(anyString(), anyInt())).thenReturn(IMPORTANCE_NONE);

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -3921,7 +3923,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, null, false);
        mService.addEnqueuedNotification(r);
        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -3938,7 +3941,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        r = generateNotificationRecord(mTestNotificationChannel, 0, null, false);
        mService.addEnqueuedNotification(r);
        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -3954,7 +3958,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.addEnqueuedNotification(r);

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -3967,12 +3972,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW);
        mService.addEnqueuedNotification(r);
        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();

        r = generateNotificationRecord(mTestNotificationChannel, 1, null, false);
        r.setCriticality(CriticalNotificationExtractor.CRITICAL);
        runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
        runnable = mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                r.getUid(), SystemClock.elapsedRealtime());
        mService.addEnqueuedNotification(r);

        runnable.run();
@@ -4416,6 +4423,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(original.getKey(),
                        original.getSbn().getPackageName(),
                        original.getUid(),
                        SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();
@@ -4438,6 +4447,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(update.getKey(),
                        update.getSbn().getPackageName(),
                        update.getUid(),
                        SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();
@@ -6533,7 +6544,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertNull(update.getSbn().getNotification().getSmallIcon());

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(update.getKey(),
                mService.new PostNotificationRunnable(update.getKey(), r.getSbn().getPackageName(),
                        r.getUid(),
                        SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();
+8 −4
Original line number Diff line number Diff line
@@ -657,7 +657,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
        when(mPermissionHelper.hasPermission(anyInt())).thenReturn(false);

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -790,7 +791,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {

        mService.addEnqueuedNotification(r);
        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
                mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                        r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -806,7 +808,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
        r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);

        mService.addEnqueuedNotification(r);
        runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
        runnable = mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();

@@ -822,7 +825,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
        r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);

        mService.addEnqueuedNotification(r);
        runnable = mService.new PostNotificationRunnable(r.getKey(), SystemClock.elapsedRealtime());
        runnable = mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(),
                r.getUid(), SystemClock.elapsedRealtime());
        runnable.run();
        waitForIdle();