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

Commit b25f9065 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix suppressing dot from BubbleMetadata suppress dot

If the app has set #suppressNotification on the bubble, then we shouldn't
show the flyout and we shouldn't show the dot on the bubble.

Right now this wasn't working. This CL adds that check to showDot and
showFlyout and adds a test for it.

There was a test in BubbleDataTest that had to be reworked -- it was using
suppressNotification to act like a shade dismissal which isn't quite right
so this CL fixes that as well.

Test: atest BubbleControllerTest BubbleDataTest
Fixes: 145918462
Change-Id: I3d2c40cf0f4d3eb71b5ed10a480c7b4490649a15
parent 95781fe5
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -297,7 +297,9 @@ class Bubble {
     * Whether the bubble for this notification should show a dot indicating updated content.
     */
    boolean showDot() {
        return mShowBubbleUpdateDot && !mEntry.shouldSuppressNotificationDot();
        return mShowBubbleUpdateDot
                && !mEntry.shouldSuppressNotificationDot()
                && !shouldSuppressNotification();
    }

    /**
@@ -305,6 +307,7 @@ class Bubble {
     */
    boolean showFlyout() {
        return !mSuppressFlyout && !mEntry.shouldSuppressPeek()
                && !shouldSuppressNotification()
                && !mEntry.shouldSuppressNotificationList();
    }

+25 −11
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ public class BubbleControllerTest extends SysuiTestCase {
    }

    @Test
    public void testAutoExpand_FailsNotForeground() {
    public void testAutoExpand_fails_noFlag() {
        assertFalse(mBubbleController.isStackExpanded());
        setMetadataFlags(mRow.getEntry(),
                Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */);
@@ -498,7 +498,7 @@ public class BubbleControllerTest extends SysuiTestCase {
    }

    @Test
    public void testAutoExpand_SucceedsForeground() {
    public void testAutoExpand_succeeds_withFlag() {
        setMetadataFlags(mRow.getEntry(),
                Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */);

@@ -516,38 +516,52 @@ public class BubbleControllerTest extends SysuiTestCase {
    }

    @Test
    public void testSuppressNotif_FailsNotForeground() {
    public void testSuppressNotif_onInitialNotif() {
        setMetadataFlags(mRow.getEntry(),
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, false /* enableFlag */);
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */);

        // Add the suppress notif bubble
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Should not be suppressed because we weren't forground
        assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
        // Notif should be suppressed because we were foreground
        assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
                mRow.getEntry().getKey()));
        // Dot + flyout is hidden because notif is suppressed
        assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
        assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout());

        // # of bubbles should change
        verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
    }

    @Test
    public void testSuppressNotif_SucceedsForeground() {
    public void testSuppressNotif_onUpdateNotif() {
        mBubbleController.updateBubble(mRow.getEntry());

        // Should not be suppressed
        assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
                mRow.getEntry().getKey()));
        // Should show dot
        assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());

        // Update to suppress notif
        setMetadataFlags(mRow.getEntry(),
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */);

        // Add the suppress notif bubble
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Notif should be suppressed because we were foreground
        // Notif should be suppressed
        assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
                mRow.getEntry().getKey()));
        // Dot + flyout is hidden because notif is suppressed
        assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
        assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout());

        // # of bubbles should change
        verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
    }


    @Test
    public void testExpandStackAndSelectBubble_removedFirst() {
        final String key = mRow.getEntry().getKey();
+17 −30
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.systemui.bubbles.BubbleData.TimeSource;
import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.NotificationTestHelper;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;

import com.google.common.collect.ImmutableList;

@@ -119,7 +120,9 @@ public class BubbleDataTest extends SysuiTestCase {
                .setVisuallyInterruptive(true)
                .build();

        ExpandableNotificationRow row = mNotificationTestHelper.createBubble();
        mEntryDismissed = createBubbleEntry(1, "dismissed", "package.d");
        mEntryDismissed.setRow(row);

        mBubbleA1 = new Bubble(mContext, mEntryA1);
        mBubbleA2 = new Bubble(mContext, mEntryA2);
@@ -192,9 +195,8 @@ public class BubbleDataTest extends SysuiTestCase {
        mBubbleData.setListener(mListener);

        // Test
        mBubbleData.notificationEntryUpdated(mEntryInterruptive, /* suppressFlyout */
                false, /* showInShade */
                true);
        mBubbleData.notificationEntryUpdated(mEntryInterruptive,
                false /* suppressFlyout */, true  /* showInShade */);

        // Verify
        verifyUpdateReceived();
@@ -208,12 +210,12 @@ public class BubbleDataTest extends SysuiTestCase {
        mBubbleData.setListener(mListener);

        // Test
        mBubbleData.notificationEntryUpdated(mEntryC1, /* suppressFlyout */ false, /* showInShade */
                true);
        mBubbleData.notificationEntryUpdated(mEntryC1, false /* suppressFlyout */,
                true /* showInShade */);
        verifyUpdateReceived();

        mBubbleData.notificationEntryUpdated(mEntryC1, /* suppressFlyout */ false, /* showInShade */
                true);
        mBubbleData.notificationEntryUpdated(mEntryC1, false /* suppressFlyout */,
                true /* showInShade */);
        verifyUpdateReceived();

        // Verify
@@ -225,16 +227,18 @@ public class BubbleDataTest extends SysuiTestCase {
    public void sameUpdate_NotInShade_showFlyout() {
        // Setup
        mBubbleData.setListener(mListener);
        setMetadataFlags(mEntryDismissed,
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, /* enableFlag */ true);

        // Test
        mBubbleData.notificationEntryUpdated(mEntryDismissed, /* suppressFlyout */ false,
                /* showInShade */ false);
        mBubbleData.notificationEntryUpdated(mEntryDismissed, false /* suppressFlyout */,
                false /* showInShade */);
        verifyUpdateReceived();

        mBubbleData.notificationEntryUpdated(mEntryDismissed, /* suppressFlyout */
                false, /* showInShade */ false);
        // Make it look like user swiped away row
        mEntryDismissed.getRow().dismiss(false /* refocusOnDismiss */);
        assertThat(mBubbleData.getBubbleWithKey(mEntryDismissed.getKey()).showInShade()).isFalse();

        mBubbleData.notificationEntryUpdated(mEntryDismissed, false /* suppressFlyout */,
                false /* showInShade */);
        verifyUpdateReceived();

        // Verify
@@ -935,23 +939,6 @@ public class BubbleDataTest extends SysuiTestCase {
        }
    }

    /**
     * Sets the bubble metadata flags for this entry. These flags are normally set by
     * NotificationManagerService when the notification is sent, however, these tests do not
     * go through that path so we set them explicitly when testing.
     */
    private void setMetadataFlags(NotificationEntry entry, int flag, boolean enableFlag) {
        Notification.BubbleMetadata bubbleMetadata =
                entry.getSbn().getNotification().getBubbleMetadata();
        int flags = bubbleMetadata.getFlags();
        if (enableFlag) {
            flags |= flag;
        } else {
            flags &= ~flag;
        }
        bubbleMetadata.setFlags(flags);
    }

    /**
     * No ExpandableNotificationRow is required to test BubbleData. This setup is all that is
     * required for BubbleData functionality and verification. NotificationTestHelper is used only