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

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

Getters for private methods on Bubble & move dismissed from NotifEntry to Bubble

Test: atest BubbleControllerTest (existing pass) BubbleDataTest
Bug: 135214687
Change-Id: I648548cb55b46e64ca237bc1ed32026058179563
parent 81ad3950
Loading
Loading
Loading
Loading
+49 −29
Original line number Diff line number Diff line
@@ -39,14 +39,14 @@ class Bubble {
    private final String mKey;
    private final String mGroupId;
    private String mAppName;
    private NotificationEntry mEntry;

    private boolean mInflated;
    public NotificationEntry entry;
    BubbleView iconView;
    BubbleExpandedView expandedView;
    private BubbleView mIconView;
    private BubbleExpandedView mExpandedView;
    private long mLastUpdated;
    private long mLastAccessed;
    private PackageManager mPm;
    private boolean mIsRemoved;

    public static String groupId(NotificationEntry entry) {
        UserHandle user = entry.notification.getUser();
@@ -56,25 +56,25 @@ class Bubble {
    /** Used in tests when no UI is required. */
    @VisibleForTesting(visibility = PRIVATE)
    Bubble(Context context, NotificationEntry e) {
        entry = e;
        mEntry = e;
        mKey = e.key;
        mLastUpdated = e.notification.getPostTime();
        mGroupId = groupId(e);

        mPm = context.getPackageManager();
        PackageManager pm = context.getPackageManager();
        ApplicationInfo info;
        try {
            info = mPm.getApplicationInfo(
                entry.notification.getPackageName(),
            info = pm.getApplicationInfo(
                mEntry.notification.getPackageName(),
                PackageManager.MATCH_UNINSTALLED_PACKAGES
                    | PackageManager.MATCH_DISABLED_COMPONENTS
                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                    | PackageManager.MATCH_DIRECT_BOOT_AWARE);
            if (info != null) {
                mAppName = String.valueOf(mPm.getApplicationLabel(info));
                mAppName = String.valueOf(pm.getApplicationLabel(info));
            }
        } catch (PackageManager.NameNotFoundException unused) {
            mAppName = entry.notification.getPackageName();
            mAppName = mEntry.notification.getPackageName();
        }
    }

@@ -82,12 +82,16 @@ class Bubble {
        return mKey;
    }

    public NotificationEntry getEntry() {
        return mEntry;
    }

    public String getGroupId() {
        return mGroupId;
    }

    public String getPackageName() {
        return entry.notification.getPackageName();
        return mEntry.notification.getPackageName();
    }

    public String getAppName() {
@@ -99,22 +103,30 @@ class Bubble {
    }

    public void updateDotVisibility() {
        if (iconView != null) {
            iconView.updateDotVisibility(true /* animate */);
        if (mIconView != null) {
            mIconView.updateDotVisibility(true /* animate */);
        }
    }

    public BubbleView getIconView() {
        return mIconView;
    }

    public BubbleExpandedView getExpandedView() {
        return mExpandedView;
    }

    void inflate(LayoutInflater inflater, BubbleStackView stackView) {
        if (mInflated) {
            return;
        }
        iconView = (BubbleView) inflater.inflate(
        mIconView = (BubbleView) inflater.inflate(
                R.layout.bubble_view, stackView, false /* attachToRoot */);
        iconView.setNotif(entry);
        mIconView.setNotif(mEntry);

        expandedView = (BubbleExpandedView) inflater.inflate(
        mExpandedView = (BubbleExpandedView) inflater.inflate(
                R.layout.bubble_expanded_view, stackView, false /* attachToRoot */);
        expandedView.setEntry(entry, stackView, mAppName);
        mExpandedView.setEntry(mEntry, stackView, mAppName);

        mInflated = true;
    }
@@ -128,25 +140,33 @@ class Bubble {
     * and setting {@code false} actually means rendering the expanded view in transparent.
     */
    void setContentVisibility(boolean visibility) {
        if (expandedView != null) {
            expandedView.setContentVisibility(visibility);
        if (mExpandedView != null) {
            mExpandedView.setContentVisibility(visibility);
        }
    }

    void setDismissed() {
        entry.setBubbleDismissed(true);
    void setRemoved() {
        mIsRemoved = true;
        // TODO: move this somewhere where it can be guaranteed not to run until safe from flicker
        if (expandedView != null) {
            expandedView.cleanUpExpandedState();
        if (mExpandedView != null) {
            mExpandedView.cleanUpExpandedState();
        }
    }

    void setRemoved(boolean removed) {
        mIsRemoved = removed;
    }

    public boolean isRemoved() {
        return mIsRemoved;
    }

    void setEntry(NotificationEntry entry) {
        this.entry = entry;
        this.mEntry = entry;
        mLastUpdated = entry.notification.getPostTime();
        if (mInflated) {
            iconView.update(entry);
            expandedView.update(entry);
            mIconView.update(entry);
            mExpandedView.update(entry);
        }
    }

@@ -175,7 +195,7 @@ class Bubble {
     * @return the display id of the virtual display on which bubble contents is drawn.
     */
    int getDisplayId() {
        return expandedView != null ? expandedView.getVirtualDisplayId() : INVALID_DISPLAY;
        return mExpandedView != null ? mExpandedView.getVirtualDisplayId() : INVALID_DISPLAY;
    }

    /**
@@ -183,14 +203,14 @@ class Bubble {
     */
    void markAsAccessedAt(long lastAccessedMillis) {
        mLastAccessed = lastAccessedMillis;
        entry.setShowInShadeWhenBubble(false);
        mEntry.setShowInShadeWhenBubble(false);
    }

    /**
     * @return whether bubble is from a notification associated with a foreground service.
     */
    public boolean isOngoing() {
        return entry.isForegroundService();
        return mEntry.isForegroundService();
    }

    @Override
+13 −11
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
        // TEMP: refactor to change this to pass entry
        Bubble bubble = mBubbleData.getBubbleWithKey(key);
        if (bubble != null) {
            mBubbleData.notificationEntryRemoved(bubble.entry, reason);
            mBubbleData.notificationEntryRemoved(bubble.getEntry(), reason);
        }
    }

@@ -420,7 +420,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                if (!mBubbleData.hasBubbleWithKey(key)) {
                    return false;
                }
                NotificationEntry entry = mBubbleData.getBubbleWithKey(key).entry;
                Bubble bubble = mBubbleData.getBubbleWithKey(key);
                NotificationEntry entry = bubble.getEntry();

                final boolean isClearAll = reason == REASON_CANCEL_ALL;
                final boolean isUserDimiss = reason == REASON_CANCEL;
@@ -434,7 +435,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi

                // The bubble notification sticks around in the data as long as the bubble is
                // not dismissed and the app hasn't cancelled the notification.
                boolean bubbleExtended = entry.isBubble() && !entry.isBubbleDismissed()
                boolean bubbleExtended = entry.isBubble() && !bubble.isRemoved()
                        && userRemovedNotif;
                if (bubbleExtended) {
                    entry.setShowInShadeWhenBubble(false);
@@ -443,7 +444,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                    }
                    mNotificationEntryManager.updateNotifications();
                    return true;
                } else if (!userRemovedNotif && !entry.isBubbleDismissed()) {
                } else if (!userRemovedNotif && !bubble.isRemoved()) {
                    // This wasn't a user removal so we should remove the bubble as well
                    mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL);
                    return false;
@@ -488,7 +489,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE);
            } else if (shouldBubble) {
                updateShowInShadeForSuppressNotification(entry);
                entry.setBubbleDismissed(false); // updates come back as bubbles even if dismissed
                Bubble b = mBubbleData.getBubbleWithKey(entry.key);
                b.setRemoved(false); // updates come back as bubbles even if dismissed
                updateBubble(entry);
            }
        }
@@ -531,13 +533,13 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                mStackView.removeBubble(bubble);

                if (!mBubbleData.hasBubbleWithKey(bubble.getKey())
                        && !bubble.entry.showInShadeWhenBubble()) {
                        && !bubble.getEntry().showInShadeWhenBubble()) {
                    // The bubble is gone & the notification is gone, time to actually remove it
                    mNotificationEntryManager.performRemoveNotification(bubble.entry.notification,
                            UNDEFINED_DISMISS_REASON);
                    mNotificationEntryManager.performRemoveNotification(
                            bubble.getEntry().notification, UNDEFINED_DISMISS_REASON);
                } else {
                    // Update the flag for SysUI
                    bubble.entry.notification.getNotification().flags &= ~FLAG_BUBBLE;
                    bubble.getEntry().notification.getNotification().flags &= ~FLAG_BUBBLE;

                    // Make sure NoMan knows it's not a bubble anymore so anyone querying it will
                    // get right result back
@@ -758,8 +760,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
            if (expandedBubble.getDisplayId() == displayId) {
                mBubbleData.setExpanded(false);
            }
            if (expandedBubble.expandedView != null) {
                expandedBubble.expandedView.notifyDisplayEmpty();
            if (expandedBubble.getExpandedView() != null) {
                expandedBubble.getExpandedView().notifyDisplayEmpty();
            }
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -302,8 +302,8 @@ public class BubbleData {
            Bubble newSelected = mBubbles.get(newIndex);
            setSelectedBubbleInternal(newSelected);
        }
        bubbleToRemove.setDismissed();
        maybeSendDeleteIntent(reason, bubbleToRemove.entry);
        bubbleToRemove.setRemoved();
        maybeSendDeleteIntent(reason, bubbleToRemove.getEntry());
    }

    public void dismissAll(@DismissReason int reason) {
@@ -317,8 +317,8 @@ public class BubbleData {
        setSelectedBubbleInternal(null);
        while (!mBubbles.isEmpty()) {
            Bubble bubble = mBubbles.remove(0);
            bubble.setDismissed();
            maybeSendDeleteIntent(reason, bubble.entry);
            bubble.setRemoved();
            maybeSendDeleteIntent(reason, bubble.getEntry());
            mStateChange.bubbleRemoved(bubble, reason);
        }
        dispatchPendingChanges();
+38 −38
Original line number Diff line number Diff line
@@ -387,7 +387,7 @@ public class BubbleStackView extends FrameLayout {
                        .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY));
        mExpandedViewYAnim.addEndListener((anim, cancelled, value, velocity) -> {
            if (mIsExpanded && mExpandedBubble != null) {
                mExpandedBubble.expandedView.updateView();
                mExpandedBubble.getExpandedView().updateView();
            }
        });

@@ -411,7 +411,7 @@ public class BubbleStackView extends FrameLayout {
            mExpandedAnimationController.updateYPosition(
                    // Update the insets after we're done translating otherwise position
                    // calculation for them won't be correct.
                    () -> mExpandedBubble.expandedView.updateInsets(insets));
                    () -> mExpandedBubble.getExpandedView().updateInsets(insets));
            return view.onApplyWindowInsets(insets);
        });

@@ -463,8 +463,8 @@ public class BubbleStackView extends FrameLayout {
     */
    public void onThemeChanged() {
        for (Bubble b: mBubbleData.getBubbles()) {
            b.iconView.updateViews();
            b.expandedView.applyThemeAttrs();
            b.getIconView().updateViews();
            b.getExpandedView().applyThemeAttrs();
        }
    }

@@ -580,7 +580,7 @@ public class BubbleStackView extends FrameLayout {
        }
        Bubble topBubble = mBubbleData.getBubbles().get(0);
        String appName = topBubble.getAppName();
        Notification notification = topBubble.entry.notification.getNotification();
        Notification notification = topBubble.getEntry().notification.getNotification();
        CharSequence titleCharSeq = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
        String titleStr = getResources().getString(R.string.stream_notification);
        if (titleCharSeq != null) {
@@ -654,7 +654,7 @@ public class BubbleStackView extends FrameLayout {
     * The {@link BubbleView} that is expanded, null if one does not exist.
     */
    BubbleView getExpandedBubbleView() {
        return mExpandedBubble != null ? mExpandedBubble.iconView : null;
        return mExpandedBubble != null ? mExpandedBubble.getIconView() : null;
    }

    /**
@@ -675,7 +675,7 @@ public class BubbleStackView extends FrameLayout {
        Bubble bubbleToExpand = mBubbleData.getBubbleWithKey(key);
        if (bubbleToExpand != null) {
            setSelectedBubble(bubbleToExpand);
            bubbleToExpand.entry.setShowInShadeWhenBubble(false);
            bubbleToExpand.getEntry().setShowInShadeWhenBubble(false);
            setExpanded(true);
        }
    }
@@ -699,14 +699,14 @@ public class BubbleStackView extends FrameLayout {
            Log.d(TAG, "addBubble: " + bubble);
        }
        bubble.inflate(mInflater, this);
        bubble.iconView.setBubbleIconFactory(mBubbleIconFactory);
        bubble.iconView.updateViews();
        bubble.getIconView().setBubbleIconFactory(mBubbleIconFactory);
        bubble.getIconView().updateViews();

        mBubbleContainer.addView(bubble.iconView, 0,
        mBubbleContainer.addView(bubble.getIconView(), 0,
                new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
        ViewClippingUtil.setClippingDeactivated(bubble.iconView, true, mClippingParameters);
        if (bubble.iconView != null) {
            bubble.iconView.setSuppressDot(mSuppressNewDot, false /* animate */);
        ViewClippingUtil.setClippingDeactivated(bubble.getIconView(), true, mClippingParameters);
        if (bubble.getIconView() != null) {
            bubble.getIconView().setSuppressDot(mSuppressNewDot, false /* animate */);
        }
        animateInFlyoutForBubble(bubble);
        requestUpdate();
@@ -720,7 +720,7 @@ public class BubbleStackView extends FrameLayout {
            Log.d(TAG, "removeBubble: " + bubble);
        }
        // Remove it from the views
        int removedIndex = mBubbleContainer.indexOfChild(bubble.iconView);
        int removedIndex = mBubbleContainer.indexOfChild(bubble.getIconView());
        if (removedIndex >= 0) {
            mBubbleContainer.removeViewAt(removedIndex);
            logBubbleEvent(bubble, StatsLog.BUBBLE_UICHANGED__ACTION__DISMISSED);
@@ -740,7 +740,7 @@ public class BubbleStackView extends FrameLayout {
    public void updateBubbleOrder(List<Bubble> bubbles) {
        for (int i = 0; i < bubbles.size(); i++) {
            Bubble bubble = bubbles.get(i);
            mBubbleContainer.reorderView(bubble.iconView, i);
            mBubbleContainer.reorderView(bubble.getIconView(), i);
        }
    }

@@ -774,8 +774,8 @@ public class BubbleStackView extends FrameLayout {
                requestUpdate();
                logBubbleEvent(previouslySelected, StatsLog.BUBBLE_UICHANGED__ACTION__COLLAPSED);
                logBubbleEvent(bubbleToSelect, StatsLog.BUBBLE_UICHANGED__ACTION__EXPANDED);
                notifyExpansionChanged(previouslySelected.entry, false /* expanded */);
                notifyExpansionChanged(bubbleToSelect == null ? null : bubbleToSelect.entry,
                notifyExpansionChanged(previouslySelected.getEntry(), false /* expanded */);
                notifyExpansionChanged(bubbleToSelect == null ? null : bubbleToSelect.getEntry(),
                        true /* expanded */);
            });
        }
@@ -803,7 +803,7 @@ public class BubbleStackView extends FrameLayout {
            logBubbleEvent(mExpandedBubble, StatsLog.BUBBLE_UICHANGED__ACTION__EXPANDED);
            logBubbleEvent(mExpandedBubble, StatsLog.BUBBLE_UICHANGED__ACTION__STACK_EXPANDED);
        }
        notifyExpansionChanged(mExpandedBubble.entry, mIsExpanded);
        notifyExpansionChanged(mExpandedBubble.getEntry(), mIsExpanded);
    }

    /**
@@ -1353,7 +1353,7 @@ public class BubbleStackView extends FrameLayout {
     */
    @VisibleForTesting
    void animateInFlyoutForBubble(Bubble bubble) {
        final CharSequence updateMessage = bubble.entry.getUpdateMessage(getContext());
        final CharSequence updateMessage = bubble.getEntry().getUpdateMessage(getContext());

        // Show the message if one exists, and we're not expanded or animating expansion.
        if (updateMessage != null
@@ -1361,9 +1361,9 @@ public class BubbleStackView extends FrameLayout {
                && !mIsExpansionAnimating
                && !mIsGestureInProgress
                && !mSuppressFlyout) {
            if (bubble.iconView != null) {
            if (bubble.getIconView() != null) {
                // Temporarily suppress the dot while the flyout is visible.
                bubble.iconView.setSuppressDot(
                bubble.getIconView().setSuppressDot(
                        true /* suppressDot */, false /* animate */);

                mFlyoutDragDeltaX = 0f;
@@ -1374,14 +1374,14 @@ public class BubbleStackView extends FrameLayout {
                }

                mAfterFlyoutHides = () -> {
                    if (bubble.iconView == null) {
                    if (bubble.getIconView() == null) {
                        return;
                    }

                    // If we're going to suppress the dot, make it visible first so it'll
                    // visibly animate away.
                    if (mSuppressNewDot) {
                        bubble.iconView.setSuppressDot(
                        bubble.getIconView().setSuppressDot(
                                false /* suppressDot */, false /* animate */);
                    }

@@ -1389,7 +1389,7 @@ public class BubbleStackView extends FrameLayout {
                    // stop suppressing it with no animation (since the flyout has
                    // transformed into the dot). If we are suppressing due to DND, animate
                    // it away.
                    bubble.iconView.setSuppressDot(
                    bubble.getIconView().setSuppressDot(
                            mSuppressNewDot /* suppressDot */,
                            mSuppressNewDot /* animate */);
                };
@@ -1405,7 +1405,7 @@ public class BubbleStackView extends FrameLayout {
                    mFlyout.showFlyout(
                            updateMessage, mStackAnimationController.getStackPosition(), getWidth(),
                            mStackAnimationController.isStackOnLeftSide(),
                            bubble.iconView.getBadgeColor(), mAfterFlyoutHides);
                            bubble.getIconView().getBadgeColor(), mAfterFlyoutHides);
                });
            }

@@ -1485,8 +1485,8 @@ public class BubbleStackView extends FrameLayout {
        }
        mExpandedViewContainer.removeAllViews();
        if (mExpandedBubble != null && mIsExpanded) {
            mExpandedViewContainer.addView(mExpandedBubble.expandedView);
            mExpandedBubble.expandedView.populateExpandedView();
            mExpandedViewContainer.addView(mExpandedBubble.getExpandedView());
            mExpandedBubble.getExpandedView().populateExpandedView();
            mExpandedViewContainer.setVisibility(mIsExpanded ? VISIBLE : GONE);
            mExpandedViewContainer.setAlpha(1.0f);
        }
@@ -1501,12 +1501,12 @@ public class BubbleStackView extends FrameLayout {
        if (mIsExpanded) {
            // First update the view so that it calculates a new height (ensuring the y position
            // calculation is correct)
            mExpandedBubble.expandedView.updateView();
            mExpandedBubble.getExpandedView().updateView();
            final float y = getExpandedViewY();
            if (!mExpandedViewYAnim.isRunning()) {
                // We're not animating so set the value
                mExpandedViewContainer.setTranslationY(y);
                mExpandedBubble.expandedView.updateView();
                mExpandedBubble.getExpandedView().updateView();
            } else {
                // We are animating so update the value; there is an end listener on the animator
                // that will ensure expandedeView.updateView gets called.
@@ -1552,7 +1552,7 @@ public class BubbleStackView extends FrameLayout {
        // Remove padding when deriving pointer location from bubbles.
        float bubbleCenter = bubbleLeftFromScreenLeft + halfBubble - mExpandedViewPadding;

        expandedBubble.expandedView.setPointerPosition(bubbleCenter);
        expandedBubble.getExpandedView().setPointerPosition(bubbleCenter);
    }

    /**
@@ -1573,7 +1573,7 @@ public class BubbleStackView extends FrameLayout {
        if (bubble == null) {
            return 0;
        }
        return mBubbleContainer.indexOfChild(bubble.iconView);
        return mBubbleContainer.indexOfChild(bubble.getIconView());
    }

    /**
@@ -1606,8 +1606,8 @@ public class BubbleStackView extends FrameLayout {
     * @param action the user interaction enum.
     */
    private void logBubbleEvent(@Nullable Bubble bubble, int action) {
        if (bubble == null || bubble.entry == null
                || bubble.entry.notification == null) {
        if (bubble == null || bubble.getEntry() == null
                || bubble.getEntry().notification == null) {
            StatsLog.write(StatsLog.BUBBLE_UI_CHANGED,
                    null /* package name */,
                    null /* notification channel */,
@@ -1621,7 +1621,7 @@ public class BubbleStackView extends FrameLayout {
                    false /* on-going bubble */,
                    false /* isAppForeground (unused) */);
        } else {
            StatusBarNotification notification = bubble.entry.notification;
            StatusBarNotification notification = bubble.getEntry().notification;
            StatsLog.write(StatsLog.BUBBLE_UI_CHANGED,
                    notification.getPackageName(),
                    notification.getNotification().getChannelId(),
@@ -1631,8 +1631,8 @@ public class BubbleStackView extends FrameLayout {
                    action,
                    getNormalizedXPosition(),
                    getNormalizedYPosition(),
                    bubble.entry.showInShadeWhenBubble(),
                    bubble.entry.isForegroundService(),
                    bubble.getEntry().showInShadeWhenBubble(),
                    bubble.getEntry().isForegroundService(),
                    false /* isAppForeground (unused) */);
        }
    }
@@ -1645,7 +1645,7 @@ public class BubbleStackView extends FrameLayout {
        if (!isExpanded()) {
            return false;
        }
        return mExpandedBubble.expandedView.performBackPressIfNeeded();
        return mExpandedBubble.getExpandedView().performBackPressIfNeeded();
    }

    /** For debugging only */
+0 −13
Original line number Diff line number Diff line
@@ -163,11 +163,6 @@ public final class NotificationEntry {
     */
    private boolean mShowInShadeWhenBubble = true;

    /**
     * Whether the user has dismissed this notification when it was in bubble form.
     */
    private boolean mUserDismissedBubble;

    /**
     * Whether this notification is shown to the user as a high priority notification: visible on
     * the lock screen/status bar and in the top section in the shade.
@@ -225,14 +220,6 @@ public final class NotificationEntry {
        return (notification.getNotification().flags & FLAG_BUBBLE) != 0;
    }

    public void setBubbleDismissed(boolean userDismissed) {
        mUserDismissedBubble = userDismissed;
    }

    public boolean isBubbleDismissed() {
        return mUserDismissedBubble;
    }

    /**
     * Sets whether this notification should be shown in the shade when it is also displayed as a
     * bubble.
Loading