Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff8d1f48 authored by Mady Mellor's avatar Mady Mellor Committed by android-build-merger
Browse files

Merge "Bubbles shouldn't be available on low ram device" into qt-dev

am: b8eb195e

Change-Id: Ib69a321cb6f2468271c78695a74cfe2bff5dd3b5
parents 8dff29c4 b8eb195e
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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 =
+37 −0
Original line number Diff line number Diff line
@@ -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);

    }
}