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

Commit cb1b8e46 authored by Matthew Ng's avatar Matthew Ng
Browse files

Fixes rotating tablet changing original dock side in landscape

Tablets can dock to the right side in landscape/seascape and when
rotating between portrait to either landscape or seascape it would
produce the primary split to be on the left for landscape and right for
seascape. Also rotating from landscape to portrait and back would change
the original dock side to the otherside if docked from the right. This
is fixed by keeping track of the original dock side and checking to see
if the new side is valid respect to the original dock side.

Change-Id: Ia430518d901f4c009e05e637a636b8262cff18fa
Fixes: 68218244
Test: runtest --path cts/tests/framework/base/activitymanager/src/
android/server/am/ActivityManagerDockedStackTests.java
parent c9666de1
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.WindowManager.DOCKED_BOTTOM;
import static android.view.WindowManager.DOCKED_INVALID;
import static android.view.WindowManager.DOCKED_LEFT;
import static android.view.WindowManager.DOCKED_RIGHT;
import static android.view.WindowManager.DOCKED_TOP;
@@ -116,6 +117,7 @@ public class DockedStackDividerController implements DimLayerUser {
    private final DimLayer mDimLayer;

    private boolean mMinimizedDock;
    private int mOriginalDockedSide = DOCKED_INVALID;
    private boolean mAnimatingForMinimizedDockedStack;
    private boolean mAnimationStarted;
    private long mAnimationStartTime;
@@ -408,6 +410,31 @@ public class DockedStackDividerController implements DimLayerUser {
        mDockedStackListeners.finishBroadcast();
    }

    /**
     * Checks if the primary stack is allowed to dock to a specific side based on its original dock
     * side.
     *
     * @param dockSide the side to see if it is valid
     * @return true if the side provided is valid
     */
    boolean canPrimaryStackDockTo(int dockSide) {
        if (mService.mPolicy.isDockSideAllowed(dockSide)) {
            // Side is the same as original side
            if (dockSide == mOriginalDockedSide) {
                return true;
            }
            // Special rule that the top in portrait is always valid
            if (dockSide == DOCKED_TOP) {
                return true;
            }
            // Only if original docked side was top in portrait will allow left side for landscape
            if (dockSide == DOCKED_LEFT && mOriginalDockedSide == DOCKED_TOP) {
                return true;
            }
        }
        return false;
    }

    void notifyDockedStackExistsChanged(boolean exists) {
        // TODO(multi-display): Perform all actions only for current display.
        final int size = mDockedStackListeners.beginBroadcast();
@@ -430,8 +457,11 @@ public class DockedStackDividerController implements DimLayerUser {
                inputMethodManagerInternal.hideCurrentInputMethod();
                mImeHideRequested = true;
            }
            final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility();
            mOriginalDockedSide = stack.getDockSide();
            return;
        }
        mOriginalDockedSide = DOCKED_INVALID;
        setMinimizedDockedStack(false /* minimizedDock */, false /* animate */);
    }

+6 −6
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        mTmpRect2.set(mBounds);
        mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
        if (inSplitScreenPrimaryWindowingMode()) {
            repositionDockedStackAfterRotation(mTmpRect2);
            repositionPrimarySplitScreenStackAfterRotation(mTmpRect2);
            snapDockedStackAfterRotation(mTmpRect2);
            final int newDockSide = getDockSide(mTmpRect2);

@@ -466,14 +466,14 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
    }

    /**
     * Some dock sides are not allowed by the policy. This method queries the policy and moves
     * the docked stack around if needed.
     * Some primary split screen sides are not allowed by the policy. This method queries the policy
     * and moves the primary stack around if needed.
     *
     * @param inOutBounds the bounds of the docked stack to adjust
     * @param inOutBounds the bounds of the primary stack to adjust
     */
    private void repositionDockedStackAfterRotation(Rect inOutBounds) {
    private void repositionPrimarySplitScreenStackAfterRotation(Rect inOutBounds) {
        int dockSide = getDockSide(inOutBounds);
        if (mService.mPolicy.isDockSideAllowed(dockSide)) {
        if (mDisplayContent.getDockedDividerController().canPrimaryStackDockTo(dockSide)) {
            return;
        }
        mDisplayContent.getLogicalDisplayRect(mTmpRect);