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

Commit 2795a48e authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Create a root view for bubbles

We now use a single window in window manager for both floating
and bar mode. The root view is added to window manager and the
stack and layer view are added under the root view.

See details in go/bubbles-stack-bar-conversion

Bug: 392893178
Flag: EXEMPT refactor
Test: manual - check stuff still works
       - create first floating bubble
       - dismiss bubble
       - create it again
       - unfold
       - dismiss
       - create first bubble bar bubble
Change-Id: I6f907dc3aafc180e430f01287d4a33c4be5384ea
parent e835c3b4
Loading
Loading
Loading
Loading
+25 −19
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.window.IMultitaskingController;
import android.window.ScreenCapture;
import android.window.ScreenCapture.SynchronousScreenCaptureListener;
@@ -227,6 +228,7 @@ public class BubbleController implements ConfigurationChangeListener,

    private final BubbleLogger mLogger;
    private final BubbleData mBubbleData;
    private final FrameLayout mBubblesRootView;
    @Nullable private BubbleStackView mStackView;
    @Nullable private BubbleBarLayerView mLayerView;
    private BubbleIconFactory mBubbleIconFactory;
@@ -401,6 +403,7 @@ public class BubbleController implements ConfigurationChangeListener,
        mResizabilityChecker = resizabilityChecker;
        mHomeIntentProvider = homeIntentProvider;
        shellInit.addInitCallback(this::onInit, this);
        mBubblesRootView = new FrameLayout(mContext);
    }

    private void registerOneHandedState(OneHandedController oneHanded) {
@@ -1009,6 +1012,9 @@ public class BubbleController implements ConfigurationChangeListener,
                mLayerView = new BubbleBarLayerView(mContext, this, mBubbleData, mLogger);
                mLayerView.setUnBubbleConversationCallback(mSysuiProxy::onUnbubbleConversation);
            }
            if (mLayerView.getParent() == null) {
                mBubblesRootView.addView(mLayerView);
            }
        } else {
            if (mStackView == null) {
                BubbleStackViewManager bubbleStackViewManager =
@@ -1022,11 +1028,14 @@ public class BubbleController implements ConfigurationChangeListener,
                }
                mStackView.setUnbubbleConversationCallback(mSysuiProxy::onUnbubbleConversation);
            }
            if (mStackView.getParent() == null) {
                mBubblesRootView.addView(mStackView);
            }
        }
        addToWindowManagerMaybe();
    }

    /** Adds the appropriate view to WindowManager if it's not already there. */
    /** Adds the root view to WindowManager if it's not already there. */
    private void addToWindowManagerMaybe() {
        // If already added, don't add it.
        if (mAddedToWindowManager) {
@@ -1070,9 +1079,9 @@ public class BubbleController implements ConfigurationChangeListener,
                mBubbleData.getOverflow().initialize(
                        mExpandedViewManager, mStackView, mBubblePositioner);
            }
            mWindowManager.addView(mBubblesRootView, mWmLayoutParams);
            // (TODO: b/273314541) some duplication in the inset listener
            if (isShowingAsBubbleBar()) {
                mWindowManager.addView(mLayerView, mWmLayoutParams);
                mLayerView.setOnApplyWindowInsetsListener((view, windowInsets) -> {
                    if (!windowInsets.equals(mWindowInsets) && mLayerView != null) {
                        mWindowInsets = windowInsets;
@@ -1082,7 +1091,6 @@ public class BubbleController implements ConfigurationChangeListener,
                    return windowInsets;
                });
            } else {
                mWindowManager.addView(mStackView, mWmLayoutParams);
                mStackView.setOnApplyWindowInsetsListener((view, windowInsets) -> {
                    if (!windowInsets.equals(mWindowInsets) && mStackView != null) {
                        mWindowInsets = windowInsets;
@@ -1113,11 +1121,16 @@ public class BubbleController implements ConfigurationChangeListener,
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
            mWmLayoutParams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            mWindowManager.updateViewLayout(mBubblesRootView, mWmLayoutParams);
        }
    }

    private void removeViewsFromRootView() {
        if (mStackView != null) {
                mWindowManager.updateViewLayout(mStackView, mWmLayoutParams);
            } else if (mLayerView != null) {
                mWindowManager.updateViewLayout(mLayerView, mWmLayoutParams);
            mBubblesRootView.removeView(mStackView);
        }
        if (mLayerView != null) {
            mBubblesRootView.removeView(mLayerView);
        }
    }

@@ -1139,14 +1152,8 @@ public class BubbleController implements ConfigurationChangeListener,
            }
        });
        try {
            if (mStackView != null) {
                mWindowManager.removeView(mStackView);
                mBubbleData.getOverflow().cleanUpExpandedState();
            }
            if (mLayerView != null) {
                mWindowManager.removeView(mLayerView);
            mWindowManager.removeView(mBubblesRootView);
            mBubbleData.getOverflow().cleanUpExpandedState();
            }
        } catch (IllegalArgumentException e) {
            // This means the stack has already been removed - it shouldn't happen, but ignore if it
            // does, since we wanted it removed anyway.
@@ -1856,9 +1863,8 @@ public class BubbleController implements ConfigurationChangeListener,
        // TaskView.
        mBubbleData.getBubbles().forEach(b -> b.cleanupViews(/* cleanupTaskView= */ false));

        // remove the current bubble container from window manager, null it out, and create a new
        // container based on the current mode.
        removeFromWindowManagerMaybe();
        // replace the current views in the root view based on the mode we're switching to
        removeViewsFromRootView();
        mLayerView = null;
        mStackView = null;