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

Commit a08dfd34 authored by Ats Jenk's avatar Ats Jenk
Browse files

Ignore group alert setting when opening bubbles

When notifications are shown in a group, group alert setting can be set
to GROUP_ALERT_SUMMARY to notify the user only once per group.
Regardless of this alert setting, user is still allowed to bubble
individiual notifications in a group (button is shown).
Issue was that our check if a notification can be bubbled was applying
the check for alerting on a child notification in a group. Which is not
needed as bubbling should be allowed regardless.
Removing the check for bubbles.

Bug: 214130620
Test: atest NotificationInterruptStateProviderImplTest
Test: manually verified that when there are multiple notifications from
Telegram, they can be opened as bubbles
Test: manually verified with Messages that notifications in a group can
be opened as bubbles

Change-Id: I01258e0db041b8eb04160242f4fd9a875315ad3d
parent 57513305
Loading
Loading
Loading
Loading
+31 −10
Original line number Diff line number Diff line
@@ -194,6 +194,10 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            return false;
        }

        if (!canAlertHeadsUpCommon(entry)) {
            return false;
        }

        if (!canAlertAwakeCommon(entry)) {
            return false;
        }
@@ -267,6 +271,11 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            return false;
        }

        if (!canAlertHeadsUpCommon(entry)) {
            mLogger.logNoPulsingNoAlert(sbn);
            return false;
        }

        if (entry.shouldSuppressAmbient()) {
            mLogger.logNoPulsingNoAmbientEffect(sbn);
            return false;
@@ -294,12 +303,6 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            return false;
        }

        // Don't alert notifications that are suppressed due to group alert behavior
        if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) {
            mLogger.logNoAlertingGroupAlertBehavior(sbn);
            return false;
        }

        for (int i = 0; i < mSuppressors.size(); i++) {
            if (mSuppressors.get(i).suppressInterruptions(entry)) {
                mLogger.logNoAlertingSuppressedBy(sbn, mSuppressors.get(i), /* awake */ false);
@@ -307,13 +310,31 @@ public class NotificationInterruptStateProviderImpl implements NotificationInter
            }
        }

        if (entry.hasJustLaunchedFullScreenIntent()) {
            mLogger.logNoAlertingRecentFullscreen(sbn);
        if (mKeyguardNotificationVisibilityProvider.shouldHideNotification(entry)) {
            mLogger.keyguardHideNotification(entry.getKey());
            return false;
        }

        if (mKeyguardNotificationVisibilityProvider.shouldHideNotification(entry)) {
            mLogger.keyguardHideNotification(entry.getKey());
        return true;
    }

    /**
     * Common checks for heads up notifications on regular and AOD displays.
     *
     * @param entry the entry to check
     * @return true if these checks pass, false if the notification should not alert
     */
    private boolean canAlertHeadsUpCommon(NotificationEntry entry) {
        StatusBarNotification sbn = entry.getSbn();

        // Don't alert notifications that are suppressed due to group alert behavior
        if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) {
            mLogger.logNoAlertingGroupAlertBehavior(sbn);
            return false;
        }

        if (entry.hasJustLaunchedFullScreenIntent()) {
            mLogger.logNoAlertingRecentFullscreen(sbn);
            return false;
        }

+26 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.systemui.statusbar.notification.interruption;


import static android.app.Notification.FLAG_BUBBLE;
import static android.app.Notification.GROUP_ALERT_SUMMARY;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
@@ -430,6 +431,17 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
        assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(createBubble())).isTrue();
    }

    /**
     * Test that notification can bubble even if it is a child in a group and group settings are
     * set to alert only for summary notifications.
     */
    @Test
    public void testShouldBubbleUp_notifInGroupWithOnlySummaryAlerts() {
        ensureStateForBubbleUp();
        NotificationEntry bubble = createBubble("testgroup", GROUP_ALERT_SUMMARY);
        assertThat(mNotifInterruptionStateProvider.shouldBubbleUp(bubble)).isTrue();
    }

    /**
     * If the notification doesn't have permission to bubble, it shouldn't bubble.
     */
@@ -497,16 +509,27 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
    }

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

    private NotificationEntry createBubble(String groupKey, Integer groupAlert) {
        Notification.BubbleMetadata data = new Notification.BubbleMetadata.Builder(
                PendingIntent.getActivity(mContext, 0, new Intent(),
                    PendingIntent.FLAG_MUTABLE),
                        Icon.createWithResource(mContext.getResources(), R.drawable.android))
                .build();
        Notification n = new Notification.Builder(getContext(), "a")
        Notification.Builder nb = new Notification.Builder(getContext(), "a")
                .setContentTitle("title")
                .setContentText("content text")
                .setBubbleMetadata(data)
                .build();
                .setBubbleMetadata(data);
        if (groupKey != null) {
            nb.setGroup(groupKey);
            nb.setGroupSummary(false);
        }
        if (groupAlert != null) {
            nb.setGroupAlertBehavior(groupAlert);
        }
        Notification n = nb.build();
        n.flags |= FLAG_BUBBLE;

        return new NotificationEntryBuilder()