Loading services/core/java/com/android/server/notification/NotificationManagerService.java +17 −7 Original line number Diff line number Diff line Loading @@ -9363,10 +9363,15 @@ public class NotificationManagerService extends SystemService { // a group summary or children (complete a group) mHandler.postDelayed(() -> { synchronized (mNotificationLock) { NotificationRecord record = mNotificationsByKey.get(key); if (record != null) { mGroupHelper.onNotificationPostedWithDelay( r, mNotificationList, mSummaryByGroupKey); record, mNotificationList, mSummaryByGroupKey); } } }, r.getKey(), DELAY_FORCE_REGROUP_TIME); }, key, DELAY_FORCE_REGROUP_TIME); } } Loading Loading @@ -9412,10 +9417,15 @@ public class NotificationManagerService extends SystemService { if (notificationForceGrouping()) { mHandler.postDelayed(() -> { synchronized (mNotificationLock) { mGroupHelper.onNotificationPostedWithDelay(r, mNotificationList, mSummaryByGroupKey); NotificationRecord record = mNotificationsByKey.get(key); if (record != null) { mGroupHelper.onNotificationPostedWithDelay( record, mNotificationList, mSummaryByGroupKey); } } }, r.getKey(), DELAY_FORCE_REGROUP_TIME); }, key, DELAY_FORCE_REGROUP_TIME); } } } Loading Loading @@ -10395,7 +10405,7 @@ public class NotificationManagerService extends SystemService { } mListeners.notifyRemovedLocked(r, reason, r.getStats()); if (notificationForceGrouping()) { mHandler.removeCallbacksAndMessages(r.getKey()); mHandler.removeCallbacksAndEqualMessages(r.getKey()); mHandler.post(() -> { synchronized (NotificationManagerService.this.mNotificationLock) { mGroupHelper.onNotificationRemoved(r, mNotificationList); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -2894,6 +2894,44 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPostedWithDelay(eq(r), any(), any()); } @Test @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, android.app.Flags.FLAG_CHECK_AUTOGROUP_BEFORE_POST}) public void testRemoveScheduledForceGroup_onNotificationCanceled() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, "tag", null, false); when(mGroupHelper.onNotificationPosted(any(), anyBoolean())).thenReturn(false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(), r.getUid(), mPostNotificationTrackerFactory.newTracker(null)); runnable.run(); waitForIdle(); // Post an update to the notification NotificationRecord r_update = generateNotificationRecord(mTestNotificationChannel, 0, "tag", null, false); mService.addEnqueuedNotification(r_update); runnable = mService.new PostNotificationRunnable(r_update.getKey(), r_update.getSbn().getPackageName(), r_update.getUid(), mPostNotificationTrackerFactory.newTracker(null)); runnable.run(); waitForIdle(); // Cancel the notification mBinderService.cancelNotificationWithTag(r.getSbn().getPackageName(), r.getSbn().getPackageName(), r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); mTestableLooper.moveTimeForward(DELAY_FORCE_REGROUP_TIME); waitForIdle(); // Check that onNotificationPostedWithDelay was canceled verify(mGroupHelper, times(1)).onNotificationPosted(any(), anyBoolean()); verify(mGroupHelper, never()).onNotificationPostedWithDelay(any(), any(), any()); } @Test @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING) public void testEnqueueNotification_forceGrouped_clearsSummaryFlag() throws Exception { Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +17 −7 Original line number Diff line number Diff line Loading @@ -9363,10 +9363,15 @@ public class NotificationManagerService extends SystemService { // a group summary or children (complete a group) mHandler.postDelayed(() -> { synchronized (mNotificationLock) { NotificationRecord record = mNotificationsByKey.get(key); if (record != null) { mGroupHelper.onNotificationPostedWithDelay( r, mNotificationList, mSummaryByGroupKey); record, mNotificationList, mSummaryByGroupKey); } } }, r.getKey(), DELAY_FORCE_REGROUP_TIME); }, key, DELAY_FORCE_REGROUP_TIME); } } Loading Loading @@ -9412,10 +9417,15 @@ public class NotificationManagerService extends SystemService { if (notificationForceGrouping()) { mHandler.postDelayed(() -> { synchronized (mNotificationLock) { mGroupHelper.onNotificationPostedWithDelay(r, mNotificationList, mSummaryByGroupKey); NotificationRecord record = mNotificationsByKey.get(key); if (record != null) { mGroupHelper.onNotificationPostedWithDelay( record, mNotificationList, mSummaryByGroupKey); } } }, r.getKey(), DELAY_FORCE_REGROUP_TIME); }, key, DELAY_FORCE_REGROUP_TIME); } } } Loading Loading @@ -10395,7 +10405,7 @@ public class NotificationManagerService extends SystemService { } mListeners.notifyRemovedLocked(r, reason, r.getStats()); if (notificationForceGrouping()) { mHandler.removeCallbacksAndMessages(r.getKey()); mHandler.removeCallbacksAndEqualMessages(r.getKey()); mHandler.post(() -> { synchronized (NotificationManagerService.this.mNotificationLock) { mGroupHelper.onNotificationRemoved(r, mNotificationList); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -2894,6 +2894,44 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPostedWithDelay(eq(r), any(), any()); } @Test @EnableFlags({FLAG_NOTIFICATION_FORCE_GROUPING, android.app.Flags.FLAG_CHECK_AUTOGROUP_BEFORE_POST}) public void testRemoveScheduledForceGroup_onNotificationCanceled() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, "tag", null, false); when(mGroupHelper.onNotificationPosted(any(), anyBoolean())).thenReturn(false); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey(), r.getSbn().getPackageName(), r.getUid(), mPostNotificationTrackerFactory.newTracker(null)); runnable.run(); waitForIdle(); // Post an update to the notification NotificationRecord r_update = generateNotificationRecord(mTestNotificationChannel, 0, "tag", null, false); mService.addEnqueuedNotification(r_update); runnable = mService.new PostNotificationRunnable(r_update.getKey(), r_update.getSbn().getPackageName(), r_update.getUid(), mPostNotificationTrackerFactory.newTracker(null)); runnable.run(); waitForIdle(); // Cancel the notification mBinderService.cancelNotificationWithTag(r.getSbn().getPackageName(), r.getSbn().getPackageName(), r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); mTestableLooper.moveTimeForward(DELAY_FORCE_REGROUP_TIME); waitForIdle(); // Check that onNotificationPostedWithDelay was canceled verify(mGroupHelper, times(1)).onNotificationPosted(any(), anyBoolean()); verify(mGroupHelper, never()).onNotificationPostedWithDelay(any(), any(), any()); } @Test @EnableFlags(FLAG_NOTIFICATION_FORCE_GROUPING) public void testEnqueueNotification_forceGrouped_clearsSummaryFlag() throws Exception { Loading