diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index f38001b15a7cd..f7af4e1dd1d12 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -1137,7 +1137,8 @@ public class BubbleController { if (reason == DISMISS_USER_CHANGED || reason == DISMISS_NO_BUBBLE_UP) { continue; } - if (reason == DISMISS_NOTIF_CANCEL) { + if (reason == DISMISS_NOTIF_CANCEL + || reason == DISMISS_SHORTCUT_REMOVED) { bubblesToBeRemovedFromRepository.add(bubble); } if (!mBubbleData.hasBubbleInStackWithKey(bubble.getKey())) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java index 42aecfdc11bdf..c5d1e3acb2b94 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java @@ -254,6 +254,22 @@ public class NotificationTestHelper { return row; } + /** + * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble. + */ + public ExpandableNotificationRow createShortcutBubble(String shortcutId) + throws Exception { + Notification n = createNotification(false /* isGroupSummary */, + null /* groupKey */, makeShortcutBubbleMetadata(shortcutId)); + n.flags |= FLAG_BUBBLE; + ExpandableNotificationRow row = generateRow(n, PKG, UID, USER_HANDLE, + 0 /* extraInflationFlags */, IMPORTANCE_HIGH); + modifyRanking(row.getEntry()) + .setCanBubble(true) + .build(); + return row; + } + /** * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble and is part * of a group of notifications. @@ -506,6 +522,12 @@ public class NotificationTestHelper { .build(); } + private BubbleMetadata makeShortcutBubbleMetadata(String shortcutId) { + return new BubbleMetadata.Builder(shortcutId) + .setDesiredHeight(314) + .build(); + } + private static class MockSmartReplyInflater implements SmartReplyStateInflater { @Override public InflatedSmartReplyState inflateSmartReplyState(NotificationEntry entry) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java index 1159e0912926b..15a92dcf26b78 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/BubblesTest.java @@ -185,6 +185,8 @@ public class BubblesTest extends SysuiTestCase { private ArgumentCaptor mEntryListenerCaptor; @Captor private ArgumentCaptor mRemoveInterceptorCaptor; + @Captor + private ArgumentCaptor> mBubbleListCaptor; private BubblesManager mBubblesManager; // TODO(178618782): Move tests on the controller directly to the shell @@ -1165,6 +1167,22 @@ public class BubblesTest extends SysuiTestCase { verify(mDataRepository, times(1)).loadBubbles(anyInt(), any()); } + /** + * Verifies that shortcut deletions triggers that bubble being removed from XML. + */ + @Test + public void testDeleteShortcutsDeletesXml() throws Exception { + ExpandableNotificationRow row = mNotificationTestHelper.createShortcutBubble("shortcutId"); + BubbleEntry shortcutBubbleEntry = BubblesManager.notifToBubbleEntry(row.getEntry()); + mBubbleController.updateBubble(shortcutBubbleEntry); + + mBubbleData.dismissBubbleWithKey(shortcutBubbleEntry.getKey(), + Bubbles.DISMISS_SHORTCUT_REMOVED); + + verify(mDataRepository, atLeastOnce()).removeBubbles(anyInt(), mBubbleListCaptor.capture()); + assertThat(mBubbleListCaptor.getValue().get(0).getKey()).isEqualTo( + shortcutBubbleEntry.getKey()); + } /** * Verifies that the package manager for the user is used when loading info for the bubble. diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java index 05c4822f288e1..43b181ed3ab94 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/NewNotifPipelineBubblesTest.java @@ -93,6 +93,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.WindowManagerShellWrapper; +import com.android.wm.shell.bubbles.Bubble; import com.android.wm.shell.bubbles.BubbleData; import com.android.wm.shell.bubbles.BubbleDataRepository; import com.android.wm.shell.bubbles.BubbleEntry; @@ -167,6 +168,9 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase { @Captor private ArgumentCaptor mNotifListenerCaptor; + @Captor + private ArgumentCaptor> mBubbleListCaptor; + private BubblesManager mBubblesManager; private TestableBubbleController mBubbleController; private NotificationShadeWindowControllerImpl mNotificationShadeWindowController; @@ -1013,6 +1017,23 @@ public class NewNotifPipelineBubblesTest extends SysuiTestCase { verify(mDataRepository, times(1)).loadBubbles(anyInt(), any()); } + /** + * Verifies that shortcut deletions triggers that bubble being removed from XML. + */ + @Test + public void testDeleteShortcutsDeletesXml() throws Exception { + ExpandableNotificationRow row = mNotificationTestHelper.createShortcutBubble("shortcutId"); + BubbleEntry shortcutBubbleEntry = BubblesManager.notifToBubbleEntry(row.getEntry()); + mBubbleController.updateBubble(shortcutBubbleEntry); + + mBubbleData.dismissBubbleWithKey(shortcutBubbleEntry.getKey(), + Bubbles.DISMISS_SHORTCUT_REMOVED); + + verify(mDataRepository, atLeastOnce()).removeBubbles(anyInt(), mBubbleListCaptor.capture()); + assertThat(mBubbleListCaptor.getValue().get(0).getKey()).isEqualTo( + shortcutBubbleEntry.getKey()); + } + @Test public void testShowManageMenuChangesSysuiState() { mBubbleController.updateBubble(mBubbleEntry);