From 6ce11e74008458f5ee9d9c369bcd3b396ffcebfa Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Fri, 29 May 2020 14:07:24 -0700 Subject: [PATCH] Require shortcut to bubble Fixes: 155104372 Test: atest SystemUITests Change-Id: I9030837114f100ffef0f6497ad4b0a19ffb3cda2 --- .../server/notification/BubbleExtractor.java | 1 + .../notification/BubbleExtractorTest.java | 22 +++++++++++++++++-- .../NotificationManagerServiceTest.java | 22 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/BubbleExtractor.java b/services/core/java/com/android/server/notification/BubbleExtractor.java index 0fa339f65cdb5..fd92c4c82f24f 100644 --- a/services/core/java/com/android/server/notification/BubbleExtractor.java +++ b/services/core/java/com/android/server/notification/BubbleExtractor.java @@ -78,6 +78,7 @@ public class BubbleExtractor implements NotificationSignalExtractor { boolean canPresentAsBubble = canPresentAsBubble(record) && !mActivityManager.isLowRamDevice() && record.isConversation() + && record.getShortcutInfo() != null && (record.getNotification().flags & FLAG_FOREGROUND_SERVICE) == 0; if (!mConfig.bubblesEnabled() diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java index 13457f0a284cc..162b2c4ac2d01 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/BubbleExtractorTest.java @@ -430,6 +430,25 @@ public class BubbleExtractorTest extends UiServiceTestCase { assertFalse(r.getNotification().isBubbleNotification()); } + @Test + public void testFlagBubble_false_noShortcut() { + setUpBubblesEnabled(true /* feature */, + BUBBLE_PREFERENCE_ALL /* app */, + DEFAULT_ALLOW_BUBBLE /* channel */); + when(mActivityManager.isLowRamDevice()).thenReturn(false); + setUpIntentBubble(true /* isValid */); + + NotificationRecord r = getNotificationRecord(true /* bubble */); + r.setShortcutInfo(null); + r.getNotification().extras.putString(Notification.EXTRA_TEMPLATE, null); + + mBubbleExtractor.process(r); + + assertFalse(r.canBubble()); + assertNull(r.getNotification().getBubbleMetadata()); + assertFalse(r.getNotification().isBubbleNotification()); + } + @Test public void testFlagBubble_false_notConversation() { setUpBubblesEnabled(true /* feature */, @@ -439,8 +458,7 @@ public class BubbleExtractorTest extends UiServiceTestCase { setUpIntentBubble(true /* isValid */); NotificationRecord r = getNotificationRecord(true /* bubble */); - // No longer a conversation: - r.setShortcutInfo(null); + r.userDemotedAppFromConvoSpace(true); r.getNotification().extras.putString(Notification.EXTRA_TEMPLATE, null); mBubbleExtractor.process(r); 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 2bea491949dec..8f4b78c034423 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -5308,6 +5308,28 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nr.getSbn().getKey()).getNotification().isBubbleNotification()); } + @Test + public void testFlagBubbleNotifs_noFlag_noShortcut() throws RemoteException { + setUpPrefsForBubbles(PKG, mUid, + true /* global */, + BUBBLE_PREFERENCE_ALL /* app */, + true /* channel */); + + Notification.Builder nb = getMessageStyleNotifBuilder(true, null, false); + nb.setShortcutId(null); + StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + null, mUid, 0, + nb.build(), new UserHandle(mUid), null, 0); + + mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + sbn.getId(), sbn.getNotification(), sbn.getUserId()); + waitForIdle(); + + // no shortcut no bubble + assertFalse(mService.getNotificationRecord( + sbn.getKey()).getNotification().isBubbleNotification()); + } + @Test public void testFlagBubbleNotifs_noFlag_messaging_appNotAllowed() throws RemoteException { setUpPrefsForBubbles(PKG, mUid,