Loading services/core/java/com/android/server/notification/NotificationManagerService.java +8 −1 Original line number Diff line number Diff line Loading @@ -4015,7 +4015,7 @@ public class NotificationManagerService extends SystemService { private void cancelNotificationFromListenerLocked(ManagedServiceInfo info, int callingUid, int callingPid, String pkg, String tag, int id, int userId) { cancelNotification(callingUid, callingPid, pkg, tag, id, 0, FLAG_ONGOING_EVENT | FLAG_FOREGROUND_SERVICE | FLAG_BUBBLE, FLAG_ONGOING_EVENT | FLAG_FOREGROUND_SERVICE, true, userId, REASON_LISTENER_CANCEL, info); } Loading Loading @@ -6248,6 +6248,13 @@ public class NotificationManagerService extends SystemService { mUsageStats.registerClickedByUser(r); } if (mReason == REASON_LISTENER_CANCEL && (r.getNotification().flags & FLAG_BUBBLE) != 0) { mNotificationDelegate.onBubbleNotificationSuppressionChanged( r.getKey(), /* suppressed */ true); return; } if ((r.getNotification().flags & mMustHaveFlags) != mMustHaveFlags) { return; } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +35 −11 Original line number Diff line number Diff line Loading @@ -5455,27 +5455,51 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test public void testCancelNotificationsFromListener_ignoresBubbles() throws Exception { final NotificationRecord nrNormal = generateNotificationRecord(mTestNotificationChannel); final NotificationRecord nrBubble = generateNotificationRecord(mTestNotificationChannel); nrBubble.getSbn().getNotification().flags |= FLAG_BUBBLE; mService.addNotification(nrNormal); mService.addNotification(nrBubble); public void testCancelNotificationsFromListener_cancelsNonBubble() throws Exception { // Add non-bubble notif final NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(nr); String[] keys = {nrNormal.getSbn().getKey(), nrBubble.getSbn().getKey()}; // Cancel via listener String[] keys = {nr.getSbn().getKey()}; mService.getBinderService().cancelNotificationsFromListener(null, keys); waitForIdle(); // Notif not active anymore StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); // Cancel event is logged assertEquals(1, mNotificationRecordLogger.numCalls()); assertEquals(NotificationRecordLogger.NotificationCancelledEvent .NOTIFICATION_CANCEL_LISTENER_CANCEL, mNotificationRecordLogger.event(0)); } @Test public void testCancelNotificationsFromListener_suppressesBubble() throws Exception { // Add bubble notif setUpPrefsForBubbles(PKG, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag"); mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Cancel via listener String[] keys = {nr.getSbn().getKey()}; mService.getBinderService().cancelNotificationsFromListener(null, keys); waitForIdle(); // Bubble notif active and suppressed StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); assertTrue(notifs[0].getNotification().getBubbleMetadata().isNotificationSuppressed()); } @Test public void testCancelAllNotificationsFromStatusBar_ignoresBubble() throws Exception { // GIVEN a notification bubble Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +8 −1 Original line number Diff line number Diff line Loading @@ -4015,7 +4015,7 @@ public class NotificationManagerService extends SystemService { private void cancelNotificationFromListenerLocked(ManagedServiceInfo info, int callingUid, int callingPid, String pkg, String tag, int id, int userId) { cancelNotification(callingUid, callingPid, pkg, tag, id, 0, FLAG_ONGOING_EVENT | FLAG_FOREGROUND_SERVICE | FLAG_BUBBLE, FLAG_ONGOING_EVENT | FLAG_FOREGROUND_SERVICE, true, userId, REASON_LISTENER_CANCEL, info); } Loading Loading @@ -6248,6 +6248,13 @@ public class NotificationManagerService extends SystemService { mUsageStats.registerClickedByUser(r); } if (mReason == REASON_LISTENER_CANCEL && (r.getNotification().flags & FLAG_BUBBLE) != 0) { mNotificationDelegate.onBubbleNotificationSuppressionChanged( r.getKey(), /* suppressed */ true); return; } if ((r.getNotification().flags & mMustHaveFlags) != mMustHaveFlags) { return; } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +35 −11 Original line number Diff line number Diff line Loading @@ -5455,27 +5455,51 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test public void testCancelNotificationsFromListener_ignoresBubbles() throws Exception { final NotificationRecord nrNormal = generateNotificationRecord(mTestNotificationChannel); final NotificationRecord nrBubble = generateNotificationRecord(mTestNotificationChannel); nrBubble.getSbn().getNotification().flags |= FLAG_BUBBLE; mService.addNotification(nrNormal); mService.addNotification(nrBubble); public void testCancelNotificationsFromListener_cancelsNonBubble() throws Exception { // Add non-bubble notif final NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(nr); String[] keys = {nrNormal.getSbn().getKey(), nrBubble.getSbn().getKey()}; // Cancel via listener String[] keys = {nr.getSbn().getKey()}; mService.getBinderService().cancelNotificationsFromListener(null, keys); waitForIdle(); // Notif not active anymore StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); // Cancel event is logged assertEquals(1, mNotificationRecordLogger.numCalls()); assertEquals(NotificationRecordLogger.NotificationCancelledEvent .NOTIFICATION_CANCEL_LISTENER_CANCEL, mNotificationRecordLogger.event(0)); } @Test public void testCancelNotificationsFromListener_suppressesBubble() throws Exception { // Add bubble notif setUpPrefsForBubbles(PKG, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag"); mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Cancel via listener String[] keys = {nr.getSbn().getKey()}; mService.getBinderService().cancelNotificationsFromListener(null, keys); waitForIdle(); // Bubble notif active and suppressed StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); assertTrue(notifs[0].getNotification().getBubbleMetadata().isNotificationSuppressed()); } @Test public void testCancelAllNotificationsFromStatusBar_ignoresBubble() throws Exception { // GIVEN a notification bubble Loading