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

Commit 8c198a83 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show flyout if dismissed from shade. Add tests"

parents 8b3c10ac 72f50903
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -184,8 +184,9 @@ public class BubbleData {
        if (DEBUG_BUBBLE_DATA) {
            Log.d(TAG, "notificationEntryUpdated: " + entry);
        }

        Bubble bubble = getBubbleWithKey(entry.getKey());
        suppressFlyout = !entry.getRanking().visuallyInterruptive() || suppressFlyout;
        suppressFlyout |= !shouldShowFlyout(entry);

        if (bubble == null) {
            // Create a new bubble
@@ -298,6 +299,15 @@ public class BubbleData {
        return bubbleChildren;
    }

    private boolean shouldShowFlyout(NotificationEntry notif) {
        if (notif.getRanking().visuallyInterruptive()) {
            return true;
        }
        final boolean suppressedFromShade = hasBubbleWithKey(notif.getKey())
                && !getBubbleWithKey(notif.getKey()).showInShadeWhenBubble();
        return suppressedFromShade;
    }

    private void doAdd(Bubble bubble) {
        if (DEBUG_BUBBLE_DATA) {
            Log.d(TAG, "doAdd: " + bubble);
@@ -683,15 +693,19 @@ public class BubbleData {
     * Description of current bubble data state.
     */
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.print("selected: "); pw.println(mSelectedBubble != null
        pw.print("selected: ");
        pw.println(mSelectedBubble != null
                ? mSelectedBubble.getKey()
                : "null");
        pw.print("expanded: "); pw.println(mExpanded);
        pw.print("count:    "); pw.println(mBubbles.size());
        pw.print("expanded: ");
        pw.println(mExpanded);
        pw.print("count:    ");
        pw.println(mBubbles.size());
        for (Bubble bubble : mBubbles) {
            bubble.dump(fd, pw, args);
        }
        pw.print("summaryKeys: "); pw.println(mSuppressedGroupKeys.size());
        pw.print("summaryKeys: ");
        pw.println(mSuppressedGroupKeys.size());
        for (String key : mSuppressedGroupKeys.keySet()) {
            pw.println("   suppressing: " + key);
        }
+99 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.bubbles;

import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.mock;
@@ -72,6 +74,8 @@ public class BubbleDataTest extends SysuiTestCase {
    private NotificationEntry mEntryB2;
    private NotificationEntry mEntryB3;
    private NotificationEntry mEntryC1;
    private NotificationEntry mEntryInterruptive;
    private NotificationEntry mEntryDismissed;

    private Bubble mBubbleA1;
    private Bubble mBubbleA2;
@@ -110,6 +114,13 @@ public class BubbleDataTest extends SysuiTestCase {
        mEntryB3 = createBubbleEntry(1, "b3", "package.b");
        mEntryC1 = createBubbleEntry(1, "c1", "package.c");

        mEntryInterruptive = createBubbleEntry(1, "interruptive", "package.d");
        modifyRanking(mEntryInterruptive)
                .setVisuallyInterruptive(true)
                .build();

        mEntryDismissed = createBubbleEntry(1, "dismissed", "package.d");

        mBubbleA1 = new Bubble(mContext, mEntryA1);
        mBubbleA2 = new Bubble(mContext, mEntryA2);
        mBubbleA3 = new Bubble(mContext, mEntryA3);
@@ -160,6 +171,77 @@ public class BubbleDataTest extends SysuiTestCase {
        assertBubbleRemoved(mBubbleA1, BubbleController.DISMISS_USER_GESTURE);
    }

    @Test
    public void ifSuppress_hideFlyout() {
        // Setup
        mBubbleData.setListener(mListener);

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

        // Verify
        verifyUpdateReceived();
        BubbleData.Update update = mUpdateCaptor.getValue();
        assertThat(update.addedBubble.showFlyoutForBubble()).isFalse();
    }

    @Test
    public void ifInterruptiveAndNotSuppressed_thenShowFlyout() {
        // Setup
        mBubbleData.setListener(mListener);

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

        // Verify
        verifyUpdateReceived();
        BubbleData.Update update = mUpdateCaptor.getValue();
        assertThat(update.addedBubble.showFlyoutForBubble()).isTrue();
    }

    @Test
    public void sameUpdate_InShade_thenHideFlyout() {
        // Setup
        mBubbleData.setListener(mListener);

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

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

        // Verify
        BubbleData.Update update = mUpdateCaptor.getValue();
        assertThat(update.updatedBubble.showFlyoutForBubble()).isFalse();
    }

    @Test
    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);
        verifyUpdateReceived();

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

        // Verify
        BubbleData.Update update = mUpdateCaptor.getValue();
        assertThat(update.updatedBubble.showFlyoutForBubble()).isTrue();
    }

    // COLLAPSED / ADD

    /**
@@ -853,6 +935,23 @@ 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
+5 −0
Original line number Diff line number Diff line
@@ -175,6 +175,11 @@ public class RankingBuilder {
        return this;
    }

    public RankingBuilder setVisuallyInterruptive(boolean interruptive) {
        mIsVisuallyInterruptive = interruptive;
        return this;
    }

    public RankingBuilder setImportance(@Importance int importance) {
        mImportance = importance;
        return this;