From 5c11a2e104c6ef67eb5a59ccb249df581ee81c26 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 25 Apr 2019 17:26:15 -0700 Subject: [PATCH] Bubbles shouldn't be available on low ram device Bug: 130802184 Test: atest NotificationManagerServiceTest & there is a cts cl Change-Id: Ib36edacde166a5d2be5e56c1a7b3285a7272d161 --- .../NotificationManagerService.java | 5 ++- .../NotificationManagerServiceTest.java | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 9fc30ebc8cc7c..702f35ce818a0 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -4814,10 +4814,11 @@ public class NotificationManagerService extends SystemService { NotificationRecord oldRecord) { Notification notification = r.getNotification(); - // Does the app want to bubble & have permission to bubble? + // Does the app want to bubble & is able to bubble boolean canBubble = notification.getBubbleMetadata() != null && mPreferencesHelper.areBubblesAllowed(pkg, userId) - && r.getChannel().canBubble(); + && r.getChannel().canBubble() + && !mActivityManager.isLowRamDevice(); // Is the app in the foreground? final boolean appIsForeground = 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 34bb0a89227a1..cbca087872d96 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -5154,4 +5154,41 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(1, notifsAfter.length); assertEquals((notifsAfter[0].getNotification().flags & FLAG_BUBBLE), 0); } + + @Test + public void testNotificationBubbles_disabled_lowRamDevice() throws Exception { + // Bubbles are allowed! + mService.setPreferencesHelper(mPreferencesHelper); + when(mPreferencesHelper.areBubblesAllowed(anyString(), anyInt())).thenReturn(true); + when(mPreferencesHelper.getNotificationChannel( + anyString(), anyInt(), anyString(), anyBoolean())).thenReturn( + mTestNotificationChannel); + when(mPreferencesHelper.getImportance(anyString(), anyInt())).thenReturn( + mTestNotificationChannel.getImportance()); + + // Plain notification that has bubble metadata + NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, + null /* tvExtender */, true /* isBubble */); + mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", + nr.sbn.getId(), nr.sbn.getNotification(), nr.sbn.getUserId()); + waitForIdle(); + + // Would be a normal notification because wouldn't have met requirements to bubble + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + assertEquals(1, notifsBefore.length); + assertEquals((notifsBefore[0].getNotification().flags & FLAG_BUBBLE), 0); + + // Make the package foreground so that we're allowed to be a bubble + when(mActivityManager.getPackageImportance(nr.sbn.getPackageName())).thenReturn( + IMPORTANCE_FOREGROUND); + + // And we are low ram + when(mActivityManager.isLowRamDevice()).thenReturn(true); + + // We wouldn't be a bubble because the notification didn't meet requirements (low ram) + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + assertEquals(1, notifsAfter.length); + assertEquals((notifsAfter[0].getNotification().flags & FLAG_BUBBLE), 0); + + } }