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

Commit 90d5b6d0 authored by Evan Rosky's avatar Evan Rosky
Browse files

Update home bounds when entering split on rotation

Sometimes the rotation call comes in before split
is fully entered. However, we already know that we
are going into split-mode, so use a partial split
check rather than the full check to determine
whether home should be updated.

Also fixes another race where the incorrect position
was used to find closest snap on rotate before that
snap was reset to middle when leaving split (due to
a previous change that sets mMinimized early).

Bug: 156491146
Test: make various attempts at entering split by
      opening apps in a different orientation.
Change-Id: I380653e47dc0d07488c3ac56d39c4571d2f25f0b
parent 3a6ec37a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
     * @return {@code true} if destinationBounds is altered for split screen
     */
    private boolean syncWithSplitScreenBounds(Rect destinationBoundsOut) {
        if (mSplitDivider == null || !mSplitDivider.inSplitMode()) {
        if (mSplitDivider == null || !mSplitDivider.isDividerVisible()) {
            // bail early if system is not in split screen mode
            return false;
        }
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class ShortcutKeyDispatcher extends SystemUI
    }

    private void handleDockKey(long shortcutCode) {
        if (mDivider == null || !mDivider.inSplitMode()) {
        if (mDivider == null || !mDivider.isDividerVisible()) {
            // Split the screen
            mRecents.splitPrimaryTask((shortcutCode == SC_DOCK_LEFT)
                    ? SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT
+29 −14
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.stackdivider;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.SCREEN_HEIGHT_DP_UNDEFINED;
import static android.content.res.Configuration.SCREEN_WIDTH_DP_UNDEFINED;
@@ -123,14 +124,17 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
                SplitDisplayLayout sdl = new SplitDisplayLayout(mContext, displayLayout, mSplits);
                sdl.rotateTo(toRotation);
                mRotateSplitLayout = sdl;
                int position = mMinimized ? mView.mSnapTargetBeforeMinimized.position
                        : mView.getCurrentPosition();
                final int position = isDividerVisible()
                        ? (mMinimized ? mView.mSnapTargetBeforeMinimized.position
                                : mView.getCurrentPosition())
                        // snap resets to middle target when not in split-mode
                        : sdl.getSnapAlgorithm().getMiddleTarget().position;
                DividerSnapAlgorithm snap = sdl.getSnapAlgorithm();
                final DividerSnapAlgorithm.SnapTarget target =
                        snap.calculateNonDismissingSnapTarget(position);
                sdl.resizeSplits(target.position, t);

                if (inSplitMode()) {
                if (isSplitActive()) {
                    WindowManagerProxy.applyHomeTasksMinimized(sdl, mSplits.mSecondary.token, t);
                }
            };
@@ -199,7 +203,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
        @Override
        public void onImeStartPositioning(int displayId, int hiddenTop, int shownTop,
                boolean imeShouldShow, SurfaceControl.Transaction t) {
            if (!inSplitMode()) {
            if (!isDividerVisible()) {
                return;
            }
            final boolean splitIsVisible = !mView.isHidden();
@@ -298,7 +302,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
        @Override
        public void onImePositionChanged(int displayId, int imeTop,
                SurfaceControl.Transaction t) {
            if (mAnimation != null || !inSplitMode() || mPaused) {
            if (mAnimation != null || !isDividerVisible() || mPaused) {
                // Not synchronized with IME anymore, so return.
                return;
            }
@@ -310,7 +314,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
        @Override
        public void onImeEndPositioning(int displayId, boolean cancelled,
                SurfaceControl.Transaction t) {
            if (mAnimation != null || !inSplitMode() || mPaused) {
            if (mAnimation != null || !isDividerVisible() || mPaused) {
                // Not synchronized with IME anymore, so return.
                return;
            }
@@ -479,7 +483,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,

            @Override
            public void onKeyguardShowingChanged() {
                if (!inSplitMode() || mView == null) {
                if (!isDividerVisible() || mView == null) {
                    return;
                }
                mView.setHidden(mKeyguardStateController.isShowing());
@@ -559,10 +563,20 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
    }

    /** {@code true} if this is visible */
    public boolean inSplitMode() {
    public boolean isDividerVisible() {
        return mView != null && mView.getVisibility() == View.VISIBLE;
    }

    /**
     * This indicates that at-least one of the splits has content. This differs from
     * isDividerVisible because the divider is only visible once *everything* is in split mode
     * while this only cares if some things are (eg. while entering/exiting as well).
     */
    private boolean isSplitActive() {
        return mSplits.mPrimary.topActivityType != ACTIVITY_TYPE_UNDEFINED
                || mSplits.mSecondary.topActivityType != ACTIVITY_TYPE_UNDEFINED;
    }

    private void addDivider(Configuration configuration) {
        Context dctx = mDisplayController.getDisplayContext(mContext.getDisplayId());
        mView = (DividerView)
@@ -635,8 +649,8 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
    }

    void onSplitDismissed() {
        mMinimized = false;
        updateVisibility(false /* visible */);
        mMinimized = false;
        removeDivider();
    }

@@ -655,7 +669,8 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
    private void setHomeMinimized(final boolean minimized, boolean homeStackResizable) {
        if (DEBUG) {
            Slog.d(TAG, "setHomeMinimized  min:" + mMinimized + "->" + minimized + " hrsz:"
                    + mHomeStackResizable + "->" + homeStackResizable + " split:" + inSplitMode());
                    + mHomeStackResizable + "->" + homeStackResizable
                    + " split:" + isDividerVisible());
        }
        WindowContainerTransaction wct = new WindowContainerTransaction();
        final boolean minimizedChanged = mMinimized != minimized;
@@ -670,7 +685,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,
        final boolean homeResizableChanged = mHomeStackResizable != homeStackResizable;
        if (homeResizableChanged) {
            mHomeStackResizable = homeStackResizable;
            if (inSplitMode()) {
            if (isDividerVisible()) {
                WindowManagerProxy.applyHomeTasksMinimized(
                        mSplitLayout, mSplits.mSecondary.token, wct);
            }
@@ -780,7 +795,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,

    /** Register a listener that gets called whenever the existence of the divider changes */
    public void registerInSplitScreenListener(Consumer<Boolean> listener) {
        listener.accept(inSplitMode());
        listener.accept(isDividerVisible());
        synchronized (mDockedStackExistsListeners) {
            mDockedStackExistsListeners.add(new WeakReference<>(listener));
        }
@@ -795,7 +810,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,

    void ensureMinimizedSplit() {
        setHomeMinimized(true /* minimized */, mSplits.mSecondary.isResizable());
        if (!inSplitMode()) {
        if (!isDividerVisible()) {
            // Wasn't in split-mode yet, so enter now.
            if (DEBUG) {
                Slog.d(TAG, " entering split mode with minimized=true");
@@ -806,7 +821,7 @@ public class Divider extends SystemUI implements DividerView.DividerCallbacks,

    void ensureNormalSplit() {
        setHomeMinimized(false /* minimized */, mHomeStackResizable);
        if (!inSplitMode()) {
        if (!isDividerVisible()) {
            // Wasn't in split-mode, so enter now.
            if (DEBUG) {
                Slog.d(TAG, " enter split mode unminimized ");
+1 −1
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ class SplitScreenTaskOrganizer extends TaskOrganizer {
                Log.d(TAG, " at-least one split empty " + mPrimary.topActivityType
                        + "  " + mSecondary.topActivityType);
            }
            if (mDivider.inSplitMode()) {
            if (mDivider.isDividerVisible()) {
                // Was in split-mode, which means we are leaving split, so continue that.
                // This happens when the stack in the primary-split is dismissed.
                if (DEBUG) {
+1 −1
Original line number Diff line number Diff line
@@ -1488,7 +1488,7 @@ public class StatusBar extends SystemUI implements DemoMode,
        if (mDividerOptional.isPresent()) {
            divider = mDividerOptional.get();
        }
        if (divider == null || !divider.inSplitMode()) {
        if (divider == null || !divider.isDividerVisible()) {
            final int navbarPos = WindowManagerWrapper.getInstance().getNavBarPosition(mDisplayId);
            if (navbarPos == NAV_BAR_POS_INVALID) {
                return false;