Merge "Bubbles shouldn't be available on low ram device" into qt-dev
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index e2033c6..21a862a 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -4816,10 +4816,11 @@
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 34bb0a8..cbca087 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 @@
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);
+
+ }
}