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

Commit c18c614a authored by Matías Hernández's avatar Matías Hernández
Browse files

Ensure group summary (and any notifications added directly by NMS) have the correct token

All notifications must have the same token so that their serialization works as intended.

Bug: 305695605
Bug: 346360609
Flag: android.app.secure_allowlist_token
Test: atest NotificationManagerServiceTest
Change-Id: I26784a729506169b3fe8481094cc4f5ab7b8a92b
parent 0380864e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -8565,6 +8565,13 @@ public class NotificationManagerService extends SystemService {
         */
        private boolean enqueueNotification() {
            synchronized (mNotificationLock) {
                if (android.app.Flags.secureAllowlistToken()) {
                    // allowlistToken is populated by unparceling, so it will be absent if the
                    // EnqueueNotificationRunnable is created directly by NMS (as we do for group
                    // summaries) instead of via notify(). Fix that.
                    r.getNotification().overrideAllowlistToken(ALLOWLIST_TOKEN);
                }
                final long snoozeAt =
                        mSnoozeHelper.getSnoozeTimeForUnpostedNotification(
                                r.getUser().getIdentifier(),
+23 −0
Original line number Diff line number Diff line
@@ -14333,6 +14333,29 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .isEqualTo(NotificationManagerService.ALLOWLIST_TOKEN);
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_SECURE_ALLOWLIST_TOKEN)
    public void enqueueNotification_directlyThroughRunnable_populatesAllowlistToken() {
        Notification receivedWithoutParceling = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                .setContentIntent(createPendingIntent("content"))
                .build();
        NotificationRecord record = new NotificationRecord(
                mContext,
                new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 44, receivedWithoutParceling,
                        mUser, "groupKey", 0),
                mTestNotificationChannel);
        assertThat(record.getNotification().getAllowlistToken()).isNull();
        mWorkerHandler.post(
                mService.new EnqueueNotificationRunnable(mUserId, record, false, false,
                mPostNotificationTrackerFactory.newTracker(null)));
        waitForIdle();
        assertThat(mService.mNotificationList).hasSize(1);
        assertThat(mService.mNotificationList.get(0).getNotification().getAllowlistToken())
                .isEqualTo(NotificationManagerService.ALLOWLIST_TOKEN);
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_SECURE_ALLOWLIST_TOKEN)
    public void enqueueNotification_rejectsOtherToken() throws RemoteException {