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

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

Move showInShade off of NotificationEntry and into Bubble

There are minimal usages of showInShade outside of the bubbles package and
things that want to know stuff about bubbles should probs go through
bubbleController.

This CL:
* moves showInShade off of NotificationEntry and onto Bubble, updates
  usages & tests
* adds method on BubbleController to check if a notif should be suppressed
  from the shade
* removes the NotificationFilter code to filter out bubbles -- this turned
  out to be unneeded -- NotificationViewHiearchyManager can query
  BubbleController and do the right thing based on that (this also
  works around the issue from b/135280077)

Test: atest SystemUITests
Bug: 135280077
Bug: 135214687
Change-Id: Id9261eae892f39059cbb3116fe05488fcf8ff0dc
parent bdc61f7b
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -61,6 +61,14 @@ class Bubble {
    private long mLastAccessed;
    private boolean mIsRemoved;

    /**
     * Whether this notification should be shown in the shade when it is also displayed as a bubble.
     *
     * <p>When a notification is a bubble we don't show it in the shade once the bubble has been
     * expanded</p>
     */
    private boolean mShowInShadeWhenBubble = true;

    public static String groupId(NotificationEntry entry) {
        UserHandle user = entry.notification.getUser();
        return user.getIdentifier() + "|" + entry.notification.getPackageName();
@@ -99,14 +107,6 @@ class Bubble {
        return mEntry;
    }

    public boolean showInShadeWhenBubble() {
        return mEntry.showInShadeWhenBubble();
    }

    public void setShowInShadeWhenBubble(boolean showInShade) {
        mEntry.setShowInShadeWhenBubble(showInShade);
    }

    public String getGroupId() {
        return mGroupId;
    }
@@ -129,11 +129,11 @@ class Bubble {
        }
    }

    public BubbleView getIconView() {
    BubbleView getIconView() {
        return mIconView;
    }

    public BubbleExpandedView getExpandedView() {
    BubbleExpandedView getExpandedView() {
        return mExpandedView;
    }

@@ -182,7 +182,7 @@ class Bubble {
        return mIsRemoved;
    }

    void setEntry(NotificationEntry entry) {
    void updateEntry(NotificationEntry entry) {
        mEntry = entry;
        mLastUpdated = entry.notification.getPostTime();
        if (mInflated) {
@@ -227,6 +227,23 @@ class Bubble {
        setShowInShadeWhenBubble(false);
    }

    /**
     * Whether this notification should be shown in the shade when it is also displayed as a
     * bubble.
     */
    boolean showInShadeWhenBubble() {
        return !mEntry.isRowDismissed() && !shouldSuppressNotification()
                && (!mEntry.isClearable() || mShowInShadeWhenBubble);
    }

    /**
     * Sets whether this notification should be shown in the shade when it is also displayed as a
     * bubble.
     */
    void setShowInShadeWhenBubble(boolean showInShade) {
        mShowInShadeWhenBubble = showInShade;
    }

    /**
     * Returns whether the notification for this bubble is a foreground service. It shows that this
     * is an ongoing bubble.
@@ -355,6 +372,11 @@ class Bubble {
        return 0;
    }

    private boolean shouldSuppressNotification() {
        return mEntry.getBubbleMetadata() != null
                && mEntry.getBubbleMetadata().isNotificationSuppressed();
    }

    @Override
    public String toString() {
        return "Bubble{" + mKey + '}';
+12 −25
Original line number Diff line number Diff line
@@ -80,7 +80,6 @@ import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater.InflationFlag;
import com.android.systemui.statusbar.phone.StatusBarWindowController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ZenModeController;
@@ -345,6 +344,17 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
        mBubbleData.setExpanded(false /* expanded */);
    }

    /**
     * Whether (1) there is a bubble associated with the provided key and
     *         (2) if the notification for that bubble is hidden from the shade.
     *
     * False if there isn't a bubble or if the notification for that bubble appears in the shade.
     */
    public boolean isBubbleNotificationSuppressedFromShade(String key) {
        return mBubbleData.hasBubbleWithKey(key)
                && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble();
    }

    void selectBubble(Bubble bubble) {
        mBubbleData.setSelectedBubble(bubble);
    }
@@ -438,7 +448,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                boolean bubbleExtended = entry.isBubble() && !bubble.isRemoved()
                        && userRemovedNotif;
                if (bubbleExtended) {
                    entry.setShowInShadeWhenBubble(false);
                    bubble.setShowInShadeWhenBubble(false);
                    if (mStackView != null) {
                        mStackView.updateDotVisibility(entry.key);
                    }
@@ -457,17 +467,6 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
    private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
        @Override
        public void onPendingEntryAdded(NotificationEntry entry) {
            if (!areBubblesEnabled(mContext)) {
                return;
            }
            if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
                    && canLaunchInActivityView(mContext, entry)) {
                updateShowInShadeForSuppressNotification(entry);
            }
        }

        @Override
        public void onEntryInflated(NotificationEntry entry, @InflationFlag int inflatedFlags) {
            if (!areBubblesEnabled(mContext)) {
                return;
            }
@@ -488,7 +487,6 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                // It was previously a bubble but no longer a bubble -- lets remove it
                removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE);
            } else if (shouldBubble) {
                updateShowInShadeForSuppressNotification(entry);
                Bubble b = mBubbleData.getBubbleWithKey(entry.key);
                b.setRemoved(false); // updates come back as bubbles even if dismissed
                updateBubble(entry);
@@ -683,17 +681,6 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
        return mStackView;
    }

    private void updateShowInShadeForSuppressNotification(NotificationEntry entry) {
        boolean suppressNotification = entry.getBubbleMetadata() != null
                && entry.getBubbleMetadata().isNotificationSuppressed();
        Bubble b = mBubbleData.getBubbleWithKey(entry.key);
        if (b != null && mBubbleData.getSelectedBubble() == b && mBubbleData.isExpanded()) {
            // If we're expanded & selected don't show in shade
            suppressNotification = true;
        }
        entry.setShowInShadeWhenBubble(!suppressNotification);
    }

    static String formatBubblesString(List<Bubble> bubbles, Bubble selected) {
        StringBuilder sb = new StringBuilder();
        for (Bubble bubble : bubbles) {
+2 −1
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ public class BubbleData {
            trim();
        } else {
            // Updates an existing bubble
            bubble.setEntry(entry);
            bubble.updateEntry(entry);
            doUpdate(bubble);
        }
        if (shouldAutoExpand(entry)) {
@@ -187,6 +187,7 @@ public class BubbleData {
        } else if (mSelectedBubble == null) {
            setSelectedBubbleInternal(bubble);
        }
        bubble.setShowInShadeWhenBubble(!mExpanded || mSelectedBubble != bubble);
        dispatchPendingChanges();
    }

+5 −5
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.view.View;
import android.view.ViewGroup;

import com.android.systemui.R;
import com.android.systemui.bubbles.BubbleData;
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.DynamicPrivacyController;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
@@ -79,7 +79,7 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
     * possible.
     */
    private final boolean mAlwaysExpandNonGroupedNotification;
    private final BubbleData mBubbleData;
    private final BubbleController mBubbleController;
    private final DynamicPrivacyController mDynamicPrivacyController;
    private final KeyguardBypassController mBypassController;

@@ -97,8 +97,8 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
            StatusBarStateController statusBarStateController,
            NotificationEntryManager notificationEntryManager,
            Lazy<ShadeController> shadeController,
            BubbleData bubbleData,
            KeyguardBypassController bypassController,
            BubbleController bubbleController,
            DynamicPrivacyController privacyController) {
        mLockscreenUserManager = notificationLockscreenUserManager;
        mBypassController = bypassController;
@@ -110,7 +110,7 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
        Resources res = context.getResources();
        mAlwaysExpandNonGroupedNotification =
                res.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications);
        mBubbleData = bubbleData;
        mBubbleController = bubbleController;
        mDynamicPrivacyController = privacyController;
        privacyController.addListener(this);
    }
@@ -136,7 +136,7 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
        for (int i = 0; i < N; i++) {
            NotificationEntry ent = activeNotifications.get(i);
            if (ent.isRowDismissed() || ent.isRowRemoved()
                    || (mBubbleData.hasBubbleWithKey(ent.key) && !ent.showInShadeWhenBubble())) {
                    || mBubbleController.isBubbleNotificationSuppressedFromShade(ent.key)) {
                // we don't want to update removed notifications because they could
                // temporarily become children if they were isolated before.
                continue;
+0 −5
Original line number Diff line number Diff line
@@ -133,11 +133,6 @@ public class NotificationFilter {
                }
            }
        }

        if (entry.isBubble() && !entry.showInShadeWhenBubble()) {
            return true;
        }

        return false;
    }

Loading