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

Commit d6a2733d authored by Valentin Iftime's avatar Valentin Iftime Committed by Iavor-Valentin Iftime
Browse files

Do not snooze autogroup summary notifications

 The notifications are reposted, GroupHelper will create a new summary notification.
 Not snoozing the original one avoids having duplicate summary notifications.

Test: atest NotificationManagerServiceTest
Bug: 232930386
Change-Id: I9f798ecb6b42178ecdd6028668a964bc8c7b35b8
parent 4de0ce30
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -7429,6 +7429,7 @@ public class NotificationManagerService extends SystemService {
            cancelNotificationLocked(r, false, REASON_SNOOZED, wasPosted, null,
                    SystemClock.elapsedRealtime());
            updateLightsLocked();
            if (isSnoozable(r)) {
                if (mSnoozeCriterionId != null) {
                    mAssistants.notifyAssistantSnoozedLocked(r, mSnoozeCriterionId);
                    mSnoozeHelper.snooze(r, mSnoozeCriterionId);
@@ -7440,6 +7441,16 @@ public class NotificationManagerService extends SystemService {
            }
        }
        /**
         * Autogroup summaries are not snoozable
         * They will be recreated as needed when the group children are unsnoozed
         */
        private boolean isSnoozable(NotificationRecord record) {
            return !(record.getNotification().isGroupSummary() && GroupHelper.AUTOGROUP_KEY.equals(
                    record.getNotification().getGroup()));
        }
    }
    protected class CancelNotificationRunnable implements Runnable {
        private final int mCallingUid;
        private final int mCallingPid;
+31 −1
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MAX;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CONVERSATIONS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
@@ -3775,6 +3774,37 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                mNotificationRecordLogger.event(1));
    }
    @Test
    public void testSnoozeRunnable_snoozeAutoGroupChild_summaryNotSnoozed() throws Exception {
        final NotificationRecord parent = generateNotificationRecord(
                mTestNotificationChannel, 1, GroupHelper.AUTOGROUP_KEY, true);
        final NotificationRecord child = generateNotificationRecord(
                mTestNotificationChannel, 2, GroupHelper.AUTOGROUP_KEY, false);
        mService.addNotification(parent);
        mService.addNotification(child);
        when(mSnoozeHelper.canSnooze(anyInt())).thenReturn(true);
        // snooze child only
        NotificationManagerService.SnoozeNotificationRunnable snoozeNotificationRunnable =
                mService.new SnoozeNotificationRunnable(
                        child.getKey(), 100, null);
        snoozeNotificationRunnable.run();
        // only child should be snoozed
        verify(mSnoozeHelper, times(1)).snooze(any(NotificationRecord.class), anyLong());
        // both group summary and child should be cancelled
        assertNull(mService.getNotificationRecord(parent.getKey()));
        assertNull(mService.getNotificationRecord(child.getKey()));
        assertEquals(4, mNotificationRecordLogger.numCalls());
        assertEquals(NotificationRecordLogger.NotificationEvent.NOTIFICATION_SNOOZED,
                mNotificationRecordLogger.event(0));
        assertEquals(
                NotificationRecordLogger.NotificationCancelledEvent.NOTIFICATION_CANCEL_SNOOZED,
                mNotificationRecordLogger.event(1));
    }
    @Test
    public void testPostGroupChild_unsnoozeParent() throws Exception {
        final NotificationRecord child = generateNotificationRecord(