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

Commit 32267575 authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Don't push bubbles from distracting apps in focus mode

This change verifies that bubble entries are not suspended before pushing them to the user.

Flag: NA
Fixes: 290617203
Test: atest NotificationInterruptStateProviderImplTest
Test: Manual
      - Add the test Bubbles app, or any other app, to the list of distracting apps in focus mode settings
      - Turn on focus mode and generate a notification with the distracting app.
         - If you're using the test app, you'll have to use a foldable or a tablet
         - Open Settings and the test app in split screen
         - Tap on a chat and send a message -- this will generate a notification with a delay
         - Turn on focus mode immediately after sending the message
      - Observe that the bubble is not pushed to the user
      - Turn off focus mode
      - Observe that the bubble gets pushed
Change-Id: Ia0476556f1fc6aabddd4d8a9eac18f94fcfb6a52
parent 70bb706e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -204,6 +204,11 @@ class BubbleNotAllowedSuppressor() :
    override fun shouldSuppress(entry: NotificationEntry) = !entry.canBubble()
}

class BubbleAppSuspendedSuppressor :
    VisualInterruptionFilter(types = setOf(BUBBLE), reason = "app is suspended") {
    override fun shouldSuppress(entry: NotificationEntry) = entry.ranking.isSuspended
}

class BubbleNoMetadataSuppressor() :
    VisualInterruptionFilter(types = setOf(BUBBLE), reason = "has no or invalid bubble metadata") {

+8 −0
Original line number Diff line number Diff line
@@ -56,6 +56,14 @@ class NotificationInterruptLogger @Inject constructor(
        }
    }

    fun logSuspendedAppBubble(entry: NotificationEntry) {
        buffer.log(TAG, DEBUG, {
            str1 = entry.logKey
        }, {
            "No bubble up: notification: app $str1 is suspended"
        })
    }

    fun logNoBubbleNoMetadata(entry: NotificationEntry) {
        buffer.log(TAG, DEBUG, {
            str1 = entry.logKey
+5 −0
Original line number Diff line number Diff line
@@ -204,6 +204,11 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            return false;
        }

        if (entry.getRanking().isSuspended()) {
            mLogger.logSuspendedAppBubble(entry);
            return false;
        }

        if (entry.getBubbleMetadata() == null
                || (entry.getBubbleMetadata().getShortcutId() == null
                    && entry.getBubbleMetadata().getIntent() == null)) {
+1 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ constructor(
        addFilter(PulseLockscreenVisibilityPrivateSuppressor())
        addFilter(PulseLowImportanceSuppressor())
        addFilter(BubbleNotAllowedSuppressor())
        addFilter(BubbleAppSuspendedSuppressor())
        addFilter(BubbleNoMetadataSuppressor())
        addFilter(HunGroupAlertBehaviorSuppressor())
        addFilter(HunJustLaunchedFsiSuppressor())
+16 −1
Original line number Diff line number Diff line
@@ -999,11 +999,25 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
        assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(createBubble())).isFalse();
    }

    @Test
    public void shouldNotBubbleUp_suspended() {
        assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(createSuspendedBubble()))
                .isFalse();
    }

    private NotificationEntry createSuspendedBubble() {
        return createBubble(null, null, true);
    }

    private NotificationEntry createBubble() {
        return createBubble(null, null);
        return createBubble(null, null, false);
    }

    private NotificationEntry createBubble(String groupKey, Integer groupAlert) {
        return createBubble(groupKey, groupAlert, false);
    }

    private NotificationEntry createBubble(String groupKey, Integer groupAlert, Boolean suspended) {
        Notification.BubbleMetadata data = new Notification.BubbleMetadata.Builder(
                PendingIntent.getActivity(mContext, 0,
                        new Intent().setPackage(mContext.getPackageName()),
@@ -1031,6 +1045,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
                .setNotification(n)
                .setImportance(IMPORTANCE_HIGH)
                .setCanBubble(true)
                .setSuspended(suspended)
                .build();
    }

Loading