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

Commit 31e2848c authored by Robert Carr's avatar Robert Carr
Browse files

Fix repositionChild positioning.

Two seperate issues corrected. First top and left
were swapped as parameters to repositionChild. Second
the recent change to update attributes was incomplete.
Updating the attributes fixes the size and scaling
but its also necessary to update the frame in order
to trigger an update to mShownPosition. Extract and
use a method applyGravityAndUpdateFrame to do so.

Bug: 25791641
Change-Id: Id0b98d587e8acf163121b28eb377c4cf83ebc58b
parent 353ad63f
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -2495,7 +2495,7 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    void repositionChild(Session session, IWindow client,
            int top, int left, int right, int bottom,
            int left, int top, int right, int bottom,
            long deferTransactionUntilFrame, Rect outFrame) {
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "repositionChild");
        long origId = Binder.clearCallingIdentity();
@@ -2516,23 +2516,24 @@ public class WindowManagerService extends IWindowManager.Stub
                win.mAttrs.y = top;
                win.mAttrs.width = right - left;
                win.mAttrs.height = bottom - top;

                win.setWindowScale(win.mRequestedWidth, win.mRequestedHeight);

                win.mWinAnimator.computeShownFrameLocked();

                if (SHOW_TRANSACTIONS) {
                    Slog.i(TAG, ">>> OPEN TRANSACTION repositionChild");
                }

                SurfaceControl.openTransaction();

                win.applyGravityAndUpdateFrame();
                win.mWinAnimator.computeShownFrameLocked();

                win.mWinAnimator.setSurfaceBoundariesLocked(false);

                if (deferTransactionUntilFrame > 0) {
                    win.mWinAnimator.mSurfaceController.deferTransactionUntil(
                            win.mAttachedWindow.mWinAnimator.mSurfaceController.getHandle(),
                            deferTransactionUntilFrame);
                }
                win.mWinAnimator.setSurfaceBoundariesLocked(false);

                SurfaceControl.closeTransaction();
                if (SHOW_TRANSACTIONS) {
@@ -2566,6 +2567,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (win == null) {
                return 0;
            }

            WindowStateAnimator winAnimator = win.mWinAnimator;
            if (viewVisibility != View.GONE) {
                win.setRequestedSize(requestedWidth, requestedHeight);
+67 −55
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
@@ -623,39 +624,6 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        final int pw = mContainingFrame.width();
        final int ph = mContainingFrame.height();

        int w,h;
        if ((mAttrs.flags & FLAG_SCALED) != 0) {
            if (mAttrs.width < 0) {
                w = pw;
            } else if (mEnforceSizeCompat) {
                w = (int)(mAttrs.width * mGlobalScale + .5f);
            } else {
                w = mAttrs.width;
            }
            if (mAttrs.height < 0) {
                h = ph;
            } else if (mEnforceSizeCompat) {
                h = (int)(mAttrs.height * mGlobalScale + .5f);
            } else {
                h = mAttrs.height;
            }
        } else {
            if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
                w = pw;
            } else if (mEnforceSizeCompat) {
                w = (int)(mRequestedWidth * mGlobalScale + .5f);
            } else {
                w = mRequestedWidth;
            }
            if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
                h = ph;
            } else if (mEnforceSizeCompat) {
                h = (int)(mRequestedHeight * mGlobalScale + .5f);
            } else {
                h = mRequestedHeight;
            }
        }

        if (!mParentFrame.equals(pf)) {
            //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
            //        + " to " + pf);
@@ -681,28 +649,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        final int fw = mFrame.width();
        final int fh = mFrame.height();

        float x, y;
        if (mEnforceSizeCompat) {
            x = mAttrs.x * mGlobalScale;
            y = mAttrs.y * mGlobalScale;
        } else {
            x = mAttrs.x;
            y = mAttrs.y;
        }

        if (nonFullscreenTask) {
            // Make sure window fits in containing frame since it is in a non-fullscreen stack as
            // required by {@link Gravity#apply} call.
            w = Math.min(w, pw);
            h = Math.min(h, ph);
        }

        Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
                (int) (x + mAttrs.horizontalMargin * pw),
                (int) (y + mAttrs.verticalMargin * ph), mFrame);

        // Now make sure the window fits in the overall display frame.
        Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
        applyGravityAndUpdateFrame();

        // Calculate the outsets before the content frame gets shrinked to the window frame.
        if (hasOutsets) {
@@ -2236,4 +2183,69 @@ final class WindowState implements WindowManagerPolicy.WindowState {
            rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
        }
    }

    void applyGravityAndUpdateFrame() {
        final int pw = mContainingFrame.width();
        final int ph = mContainingFrame.height();
        final Task task = getTask();
        final boolean nonFullscreenTask = task != null && !task.isFullscreen();

        float x, y;
        int w,h;

        if ((mAttrs.flags & FLAG_SCALED) != 0) {
            if (mAttrs.width < 0) {
                w = pw;
            } else if (mEnforceSizeCompat) {
                w = (int)(mAttrs.width * mGlobalScale + .5f);
            } else {
                w = mAttrs.width;
            }
            if (mAttrs.height < 0) {
                h = ph;
            } else if (mEnforceSizeCompat) {
                h = (int)(mAttrs.height * mGlobalScale + .5f);
            } else {
                h = mAttrs.height;
            }
        } else {
            if (mAttrs.width == MATCH_PARENT) {
                w = pw;
            } else if (mEnforceSizeCompat) {
                w = (int)(mRequestedWidth * mGlobalScale + .5f);
            } else {
                w = mRequestedWidth;
            }
            if (mAttrs.height == MATCH_PARENT) {
                h = ph;
            } else if (mEnforceSizeCompat) {
                h = (int)(mRequestedHeight * mGlobalScale + .5f);
            } else {
                h = mRequestedHeight;
            }
        }

        if (mEnforceSizeCompat) {
            x = mAttrs.x * mGlobalScale;
            y = mAttrs.y * mGlobalScale;
        } else {
            x = mAttrs.x;
            y = mAttrs.y;
        }

        if (nonFullscreenTask) {
            // Make sure window fits in containing frame since it is in a non-fullscreen stack as
            // required by {@link Gravity#apply} call.
            w = Math.min(w, pw);
            h = Math.min(h, ph);
        }

        // Set mFrame
        Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
                (int) (x + mAttrs.horizontalMargin * pw),
                (int) (y + mAttrs.verticalMargin * ph), mFrame);

        // Now make sure the window fits in the overall display frame.
        Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
    }
}