When a shortcut is deleted remove it from xml as well

Bug: 204586850
Test: atest BubblesTest NewNotifPipelineBubblesTest
Change-Id: I99cfacf773a0aae7ebcf13830d24ff32c5c35b2b
This commit is contained in:
Mady Mellor
2021-11-01 15:11:41 -07:00
parent 38b65a1565
commit a542c24b6a
4 changed files with 63 additions and 1 deletions

View File

@@ -1134,7 +1134,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())) {

View File

@@ -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) {

View File

@@ -185,6 +185,8 @@ public class BubblesTest extends SysuiTestCase {
private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor;
@Captor
private ArgumentCaptor<NotificationRemoveInterceptor> mRemoveInterceptorCaptor;
@Captor
private ArgumentCaptor<List<Bubble>> 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.

View File

@@ -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<NotifCollectionListener> mNotifListenerCaptor;
@Captor
private ArgumentCaptor<List<Bubble>> 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);