diff options
2 files changed, 54 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 9af5b667fc44..f42e734b96ec 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2558,14 +2558,8 @@ public class NotificationManagerService extends SystemService { @Override public void addAutoGroupSummary(int userId, String pkg, String triggeringKey, boolean needsOngoingFlag) { - NotificationRecord r = createAutoGroupSummary( + NotificationManagerService.this.addAutoGroupSummary( userId, pkg, triggeringKey, needsOngoingFlag); - if (r != null) { - final boolean isAppForeground = - mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND; - mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, - SystemClock.elapsedRealtime())); - } } @Override @@ -5758,17 +5752,30 @@ public class NotificationManagerService extends SystemService { r.addAdjustment(adjustment); } + @VisibleForTesting + void addAutoGroupSummary(int userId, String pkg, String triggeringKey, + boolean needsOngoingFlag) { + NotificationRecord r = createAutoGroupSummary( + userId, pkg, triggeringKey, needsOngoingFlag); + if (r != null) { + final boolean isAppForeground = + mActivityManager.getPackageImportance(pkg) == IMPORTANCE_FOREGROUND; + mHandler.post(new EnqueueNotificationRunnable(userId, r, isAppForeground, + SystemClock.elapsedRealtime())); + } + } + // Clears the 'fake' auto-group summary. + @VisibleForTesting @GuardedBy("mNotificationLock") - private void clearAutogroupSummaryLocked(int userId, String pkg) { + void clearAutogroupSummaryLocked(int userId, String pkg) { ArrayMap<String, String> summaries = mAutobundledSummaries.get(userId); if (summaries != null && summaries.containsKey(pkg)) { - // Clear summary. final NotificationRecord removed = findNotificationByKeyLocked(summaries.remove(pkg)); if (removed != null) { - boolean wasPosted = removeFromNotificationListsLocked(removed); - cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED, wasPosted, null, - SystemClock.elapsedRealtime()); + final StatusBarNotification sbn = removed.getSbn(); + cancelNotification(MY_UID, MY_PID, pkg, sbn.getTag(), sbn.getId(), 0, 0, false, + userId, REASON_UNAUTOBUNDLED, null); } } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 67382bfacab4..1cf96972c225 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -20,7 +20,6 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREG import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.AppOpsManager.MODE_ALLOWED; -import static android.app.AppOpsManager.MODE_IGNORED; import static android.app.Notification.FLAG_AUTO_CANCEL; import static android.app.Notification.FLAG_BUBBLE; import static android.app.Notification.FLAG_CAN_COLORIZE; @@ -9161,4 +9160,39 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } } } + + @Test + public void testUngroupingOngoingAutoSummary() throws Exception { + NotificationRecord nr0 = + generateNotificationRecord(mTestNotificationChannel, 0); + NotificationRecord nr1 = + generateNotificationRecord(mTestNotificationChannel, 0); + nr1.getSbn().getNotification().flags |= FLAG_ONGOING_EVENT; + + mService.addNotification(nr0); + mService.addNotification(nr1); + + // grouphelper is a mock here, so make the calls it would make + + // add summary; wait for it to be posted + mService.addAutoGroupSummary(nr1.getUserId(), nr1.getSbn().getPackageName(), nr1.getKey(), + true); + waitForIdle(); + + // cancel both children + mBinderService.cancelNotificationWithTag(PKG, PKG, nr0.getSbn().getTag(), + nr0.getSbn().getId(), nr0.getSbn().getUserId()); + mBinderService.cancelNotificationWithTag(PKG, PKG, nr1.getSbn().getTag(), + nr1.getSbn().getId(), nr1.getSbn().getUserId()); + waitForIdle(); + + // group helper would send 'remove flag' and then 'remove summary' events + mService.updateAutobundledSummaryFlags(nr1.getUserId(), nr1.getSbn().getPackageName(), + false, false); + mService.clearAutogroupSummaryLocked(nr1.getUserId(), nr1.getSbn().getPackageName()); + waitForIdle(); + + // make sure the summary was removed and not re-posted + assertThat(mService.getNotificationRecordCount()).isEqualTo(0); + } } |