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

Commit 6d1b7d1d authored by Tony Huang's avatar Tony Huang Committed by Automerger Merge Worker
Browse files

Merge "Fix divider disappear when rotation on shell transition" into tm-dev am: d5cdea48

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17055968

Change-Id: I09efc092b886e8f9c7eb2bb2e2f215a697086d61
parents 5fc366f4 d5cdea48
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -218,9 +218,13 @@ public class WindowlessWindowManager implements IWindowSession {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
                    "Invalid window token (never added or removed already)");
                    "Invalid window token (never added or removed already)");
        }
        }
        removeSurface(state.mSurfaceControl);
    }


    /** Separate from {@link #remove} so that subclasses can put removal on a sync transaction. */
    protected void removeSurface(SurfaceControl sc) {
        try (SurfaceControl.Transaction t = new SurfaceControl.Transaction()) {
        try (SurfaceControl.Transaction t = new SurfaceControl.Transaction()) {
            t.remove(state.mSurfaceControl).apply();
            t.remove(sc).apply();
        }
        }
    }
    }


+24 −7
Original line number Original line Diff line number Diff line
@@ -98,6 +98,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
    private WindowContainerToken mWinToken2;
    private WindowContainerToken mWinToken2;
    private int mDividePosition;
    private int mDividePosition;
    private boolean mInitialized = false;
    private boolean mInitialized = false;
    private boolean mFreezeDividerWindow = false;
    private int mOrientation;
    private int mOrientation;
    private int mRotation;
    private int mRotation;


@@ -225,11 +226,6 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
        mDividerSnapAlgorithm = getSnapAlgorithm(mContext, mRootBounds, null);
        mDividerSnapAlgorithm = getSnapAlgorithm(mContext, mRootBounds, null);
        initDividerPosition(mTempRect);
        initDividerPosition(mTempRect);


        if (mInitialized) {
            release();
            init();
        }

        return true;
        return true;
    }
    }


@@ -298,20 +294,37 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
    }
    }


    /** Releases the surface holding the current {@link DividerView}. */
    /** Releases the surface holding the current {@link DividerView}. */
    public void release() {
    public void release(SurfaceControl.Transaction t) {
        if (!mInitialized) return;
        if (!mInitialized) return;
        mInitialized = false;
        mInitialized = false;
        mSplitWindowManager.release();
        mSplitWindowManager.release(t);
        mDisplayImeController.removePositionProcessor(mImePositionProcessor);
        mDisplayImeController.removePositionProcessor(mImePositionProcessor);
        mImePositionProcessor.reset();
        mImePositionProcessor.reset();
    }
    }


    public void release() {
        release(null /* t */);
    }

    /** Releases and re-inflates {@link DividerView} on the root surface. */
    public void update(SurfaceControl.Transaction t) {
        if (!mInitialized) return;
        mSplitWindowManager.release(t);
        mImePositionProcessor.reset();
        mSplitWindowManager.init(this, mInsetsState);
    }

    @Override
    @Override
    public void insetsChanged(InsetsState insetsState) {
    public void insetsChanged(InsetsState insetsState) {
        mInsetsState.set(insetsState);
        mInsetsState.set(insetsState);
        if (!mInitialized) {
        if (!mInitialized) {
            return;
            return;
        }
        }
        if (mFreezeDividerWindow) {
            // DO NOT change its layout before transition actually run because it might cause
            // flicker.
            return;
        }
        mSplitWindowManager.onInsetsChanged(insetsState);
        mSplitWindowManager.onInsetsChanged(insetsState);
    }
    }


@@ -323,6 +336,10 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange
        }
        }
    }
    }


    public void setFreezeDividerWindow(boolean freezeDividerWindow) {
        mFreezeDividerWindow = freezeDividerWindow;
    }

    /**
    /**
     * Updates bounds with the passing position. Usually used to update recording bounds while
     * Updates bounds with the passing position. Usually used to update recording bounds while
     * performing animation or dragging divider bar to resize the splits.
     * performing animation or dragging divider bar to resize the splits.
+21 −2
Original line number Original line Diff line number Diff line
@@ -58,6 +58,9 @@ public final class SplitWindowManager extends WindowlessWindowManager {
    private SurfaceControl mLeash;
    private SurfaceControl mLeash;
    private DividerView mDividerView;
    private DividerView mDividerView;


    // Used to "pass" a transaction to WWM.remove so that view removal can be synchronized.
    private SurfaceControl.Transaction mSyncTransaction = null;

    public interface ParentContainerCallbacks {
    public interface ParentContainerCallbacks {
        void attachToParentSurface(SurfaceControl.Builder b);
        void attachToParentSurface(SurfaceControl.Builder b);
        void onLeashReady(SurfaceControl leash);
        void onLeashReady(SurfaceControl leash);
@@ -130,22 +133,38 @@ public final class SplitWindowManager extends WindowlessWindowManager {
     * Releases the surface control of the current {@link DividerView} and tear down the view
     * Releases the surface control of the current {@link DividerView} and tear down the view
     * hierarchy.
     * hierarchy.
     */
     */
    void release() {
    void release(@Nullable SurfaceControl.Transaction t) {
        if (mDividerView != null) {
        if (mDividerView != null) {
            mDividerView = null;
            mDividerView = null;
        }
        }


        if (mViewHost != null){
        if (mViewHost != null){
            mSyncTransaction = t;
            mViewHost.release();
            mViewHost.release();
            mSyncTransaction = null;
            mViewHost = null;
            mViewHost = null;
        }
        }


        if (mLeash != null) {
        if (mLeash != null) {
            if (t == null) {
                new SurfaceControl.Transaction().remove(mLeash).apply();
                new SurfaceControl.Transaction().remove(mLeash).apply();
            } else {
                t.remove(mLeash);
            }
            mLeash = null;
            mLeash = null;
        }
        }
    }
    }


    @Override
    protected void removeSurface(SurfaceControl sc) {
        // This gets called via SurfaceControlViewHost.release()
        if (mSyncTransaction != null) {
            mSyncTransaction.remove(sc);
        } else {
            super.removeSurface(sc);
        }
    }

    void setInteractive(boolean interactive) {
    void setInteractive(boolean interactive) {
        if (mDividerView == null) return;
        if (mDividerView == null) return;
        mDividerView.setInteractive(interactive);
        mDividerView.setInteractive(interactive);
+18 −7
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.view.WindowManager.transitTypeToString;
import static android.view.WindowManager.transitTypeToString;
import static android.view.WindowManagerPolicyConstants.SPLIT_DIVIDER_LAYER;
import static android.view.WindowManagerPolicyConstants.SPLIT_DIVIDER_LAYER;
import static android.window.TransitionInfo.FLAG_IS_DISPLAY;


import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
@@ -1171,6 +1172,8 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                updateUnfoldBounds();
                updateUnfoldBounds();
                return;
                return;
            }
            }

            mSplitLayout.update(null /* t */);
            onLayoutSizeChanged(mSplitLayout);
            onLayoutSizeChanged(mSplitLayout);
        }
        }
    }
    }
@@ -1198,7 +1201,6 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        if (!ENABLE_SHELL_TRANSITIONS) return;
        if (!ENABLE_SHELL_TRANSITIONS) return;


        final SurfaceControl.Transaction t = mTransactionPool.acquire();
        final SurfaceControl.Transaction t = mTransactionPool.acquire();
        setDividerVisibility(false, t);
        mDisplayLayout.rotateTo(mContext.getResources(), toRotation);
        mDisplayLayout.rotateTo(mContext.getResources(), toRotation);
        mSplitLayout.rotateTo(toRotation, mDisplayLayout.stableInsets());
        mSplitLayout.rotateTo(toRotation, mDisplayLayout.stableInsets());
        updateWindowBounds(mSplitLayout, wct);
        updateWindowBounds(mSplitLayout, wct);
@@ -1255,8 +1257,15 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            @Nullable TransitionRequestInfo request) {
            @Nullable TransitionRequestInfo request) {
        final ActivityManager.RunningTaskInfo triggerTask = request.getTriggerTask();
        final ActivityManager.RunningTaskInfo triggerTask = request.getTriggerTask();
        if (triggerTask == null) {
        if (triggerTask == null) {
            if (mMainStage.isActive()) {
                if (request.getType() == TRANSIT_CHANGE && request.getDisplayChange() != null) {
                    mSplitLayout.setFreezeDividerWindow(true);
                }
                // Still want to monitor everything while in split-screen, so return non-null.
                // Still want to monitor everything while in split-screen, so return non-null.
            return mMainStage.isActive() ? new WindowContainerTransaction() : null;
                return new WindowContainerTransaction();
            } else {
                return null;
            }
        } else if (triggerTask.displayId != mDisplayId) {
        } else if (triggerTask.displayId != mDisplayId) {
            // Skip handling task on the other display.
            // Skip handling task on the other display.
            return null;
            return null;
@@ -1352,8 +1361,14 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
            // If we're not in split-mode, just abort so something else can handle it.
            // If we're not in split-mode, just abort so something else can handle it.
            if (!mMainStage.isActive()) return false;
            if (!mMainStage.isActive()) return false;


            mSplitLayout.setFreezeDividerWindow(false);
            for (int iC = 0; iC < info.getChanges().size(); ++iC) {
            for (int iC = 0; iC < info.getChanges().size(); ++iC) {
                final TransitionInfo.Change change = info.getChanges().get(iC);
                final TransitionInfo.Change change = info.getChanges().get(iC);
                if (change.getMode() == TRANSIT_CHANGE
                        && (change.getFlags() & FLAG_IS_DISPLAY) != 0) {
                    mSplitLayout.update(startTransaction);
                }

                final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
                final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
                if (taskInfo == null || !taskInfo.hasParentTask()) continue;
                if (taskInfo == null || !taskInfo.hasParentTask()) continue;
                final StageTaskListener stage = getStageOfTask(taskInfo);
                final StageTaskListener stage = getStageOfTask(taskInfo);
@@ -1368,10 +1383,6 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                        Log.w(TAG, "Expected onTaskVanished on " + stage + " to have been called"
                        Log.w(TAG, "Expected onTaskVanished on " + stage + " to have been called"
                                + " with " + taskInfo.taskId + " before startAnimation().");
                                + " with " + taskInfo.taskId + " before startAnimation().");
                    }
                    }
                } else if (info.getType() == TRANSIT_CHANGE
                        && change.getStartRotation() != change.getEndRotation()) {
                    // Show the divider after transition finished.
                    setDividerVisibility(true, finishTransaction);
                }
                }
            }
            }
            if (mMainStage.getChildCount() == 0 || mSideStage.getChildCount() == 0) {
            if (mMainStage.getChildCount() == 0 || mSideStage.getChildCount() == 0) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -61,7 +61,7 @@ public class SplitWindowManagerTests extends ShellTestCase {
    public void testInitRelease() {
    public void testInitRelease() {
        mSplitWindowManager.init(mSplitLayout, new InsetsState());
        mSplitWindowManager.init(mSplitLayout, new InsetsState());
        assertThat(mSplitWindowManager.getSurfaceControl()).isNotNull();
        assertThat(mSplitWindowManager.getSurfaceControl()).isNotNull();
        mSplitWindowManager.release();
        mSplitWindowManager.release(null /* t */);
        assertThat(mSplitWindowManager.getSurfaceControl()).isNull();
        assertThat(mSplitWindowManager.getSurfaceControl()).isNull();
    }
    }
}
}