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

Commit b58bbccd authored by Chong Zhang's avatar Chong Zhang
Browse files

Do not adjust bounds for IME until IME is actually displayed

When the IME window is just relayout to visibe but not drawn yet,
the given insets of the IME window may not be set. Adjusting the docked
stack at the time may cause wrong bounds to be used. So we wait until
the IME window is actually displayed before moving the bottom stack.

Also move the divider together with the bottom stack when adjusting
for the IME window. This makes it look less janky.

We still have issues with the top stack's bounds changed too early,
which has to be fixed separately.

bug: 27779495
Change-Id: Ic53dc261d430a40677154be5b312a992aab49c79
parent 005b2725
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ public class DockedStackDividerController implements DimLayerUser {
    private final Interpolator mMinimizedDockInterpolator;
    private float mMaximizeMeetFraction;
    private final Rect mTouchRegion = new Rect();
    private boolean mAdjustingForIme;

    DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) {
        mService = service;
@@ -173,6 +174,14 @@ public class DockedStackDividerController implements DimLayerUser {
        return mLastVisibility;
    }

    void setAdjustingForIme(boolean adjusting) {
        mAdjustingForIme = adjusting;
    }

    boolean isAdjustingForIme() {
        return mAdjustingForIme;
    }

    void positionDockedStackedDivider(Rect frame) {
        TaskStack stack = mDisplayContent.getDockedStackLocked();
        if (stack == null) {
+12 −6
Original line number Diff line number Diff line
@@ -200,10 +200,11 @@ public class TaskStack implements DimLayer.DimLayerUser,
     * @param bounds The adjusted bounds.
     * @param keepInsets Whether to keep the insets from the original bounds or to calculate new
     *                   ones depending on the adjusted bounds.
     * @return true if the adjusted bounds has changed.
     */
    private void setAdjustedBounds(Rect bounds, boolean keepInsets) {
    private boolean setAdjustedBounds(Rect bounds, boolean keepInsets) {
        if (mAdjustedBounds.equals(bounds)) {
            return;
            return false;
        }

        mAdjustedBounds.set(bounds);
@@ -211,6 +212,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
        alignTasksToAdjustedBounds(adjusted ? mAdjustedBounds : mBounds,
                adjusted && keepInsets ? mBounds : null);
        mDisplayContent.layoutNeeded = true;
        return true;
    }

    private void alignTasksToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds) {
@@ -794,7 +796,9 @@ public class TaskStack implements DimLayer.DimLayerUser,
    void setAdjustedForIme(WindowState imeWin) {
        mAdjustedForIme = true;
        mImeWin = imeWin;
        updateAdjustedBounds();
        if (updateAdjustedBounds()) {
            getDisplayContent().mDividerControllerLocked.setAdjustingForIme(true);
        }
    }

    /**
@@ -803,7 +807,9 @@ public class TaskStack implements DimLayer.DimLayerUser,
    void resetAdjustedForIme() {
        mAdjustedForIme = false;
        mImeWin = null;
        updateAdjustedBounds();
        if (updateAdjustedBounds()) {
            getDisplayContent().mDividerControllerLocked.setAdjustingForIme(true);
        }
    }

    /**
@@ -920,7 +926,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
    /**
     * Updates the adjustment depending on it's current state.
     */
    void updateAdjustedBounds() {
    boolean updateAdjustedBounds() {
        boolean adjust = false;
        if (mMinimizeAmount != 0f) {
            adjust = adjustForMinimizedDockedStack(mMinimizeAmount);
@@ -931,7 +937,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
            mTmpAdjustedBounds.setEmpty();
            mLastContentBounds.setEmpty();
        }
        setAdjustedBounds(mTmpAdjustedBounds, isAdjustedForMinimizedDockedStack());
        return setAdjustedBounds(mTmpAdjustedBounds, isAdjustedForMinimizedDockedStack());
    }

    boolean isAdjustedForMinimizedDockedStack() {
+25 −23
Original line number Diff line number Diff line
@@ -7352,6 +7352,30 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    private void adjustForImeIfNeeded(final DisplayContent displayContent) {
        final WindowState imeWin = mInputMethodWindow;
        final TaskStack focusedStack =
                mCurrentFocus != null ? mCurrentFocus.getStack() : null;
        if (imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
                && isStackVisibleLocked(DOCKED_STACK_ID)
                && focusedStack != null
                && focusedStack.getDockSide() == DOCKED_BOTTOM){
            final ArrayList<TaskStack> stacks = displayContent.getStacks();
            for (int i = stacks.size() - 1; i >= 0; --i) {
                final TaskStack stack = stacks.get(i);
                if (stack.isVisibleLocked()) {
                    stack.setAdjustedForIme(imeWin);
                }
            }
        } else {
            final ArrayList<TaskStack> stacks = displayContent.getStacks();
            for (int i = stacks.size() - 1; i >= 0; --i) {
                final TaskStack stack = stacks.get(i);
                stack.resetAdjustedForIme();
            }
        }
    }

    // -------------------------------------------------------------
    // Drag and drop
    // -------------------------------------------------------------
@@ -8209,30 +8233,8 @@ public class WindowManagerService extends IWindowManager.Stub
                case UPDATE_DOCKED_STACK_DIVIDER: {
                    synchronized (mWindowMap) {
                        final DisplayContent displayContent = getDefaultDisplayContentLocked();

                        displayContent.getDockedDividerController().reevaluateVisibility(false);

                        final WindowState imeWin = mInputMethodWindow;
                        final TaskStack focusedStack =
                                mCurrentFocus != null ? mCurrentFocus.getStack() : null;
                        if (imeWin != null && imeWin.isVisibleNow()
                                && isStackVisibleLocked(DOCKED_STACK_ID)
                                && focusedStack != null
                                && focusedStack.getDockSide() == DOCKED_BOTTOM){
                            final ArrayList<TaskStack> stacks = displayContent.getStacks();
                            for (int i = stacks.size() - 1; i >= 0; --i) {
                                final TaskStack stack = stacks.get(i);
                                if (stack.isVisibleLocked()) {
                                    stack.setAdjustedForIme(imeWin);
                                }
                            }
                        } else {
                            final ArrayList<TaskStack> stacks = displayContent.getStacks();
                            for (int i = stacks.size() - 1; i >= 0; --i) {
                                final TaskStack stack = stacks.get(i);
                                stack.resetAdjustedForIme();
                            }
                        }
                        adjustForImeIfNeeded(displayContent);
                    }
                }
                break;
+6 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
@@ -689,6 +690,9 @@ class WindowSurfacePlacer {
                            && !w.isDragResizing() && !adjustedForMinimizedDockedStack
                            && (task == null || !w.getTask().mStack.getFreezeMovementAnimations())) {
                        winAnimator.setMoveAnimation(left, top);
                    } else if (w.mAttrs.type  == TYPE_DOCK_DIVIDER &&
                            displayContent.getDockedDividerController().isAdjustingForIme()) {
                        winAnimator.setMoveAnimation(left, top);
                    }

                    //TODO (multidisplay): Accessibility supported only for the default display.
@@ -805,6 +809,8 @@ class WindowSurfacePlacer {
                mService.updateResizingWindows(w);
            }

            displayContent.getDockedDividerController().setAdjustingForIme(false);

            mService.mDisplayManagerInternal.setDisplayProperties(displayId,
                    mDisplayHasContent,
                    mPreferredRefreshRate,