Loading services/core/java/com/android/server/notification/NotificationManagerService.java +18 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -3774,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( Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +18 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -3774,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( Loading