Loading services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -4816,10 +4816,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 = Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -4816,10 +4816,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 = Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -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); } }