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

Commit 017b6b94 authored by Felix Stern's avatar Felix Stern
Browse files

Update the server visibility before layout

With the change in [1], we only set server visibility for the IME, when
it is actually drawn and store the last drawn state of the IME. If it is
currently not drawn (rotation), server visibility will be reset.

However, the insets should be dispatched after the IME became (server)
visible. To avoid a redundant window layout, this CL introduces
`onPreLayout`, which sets the serverVisibility. As we need the previous
visibility state in the ImeInsetsSourceProvider to reset the statsToken
if needed, we store it as well.

[1]: Ifc0d345633b1aede56cf9ca8b2517c051e7359c6

Fix: 420218955
Fix: 425538294
Test: atest ImeInsetsSourceProviderTest#testOnPreLayout_resetServerVisibilityWhenImeIsNotDrawn
Test: atest com.android.server.wm.DisplayPolicyLayoutTests
Test: atest KeyboardVisibilityControlTest#testDialogPositionChangedAfterImeIsShown
Flag: EXEMPT Bugfix
Change-Id: I857a52e4cc01b59133f5be437305e8fb68a8e54a
parent a410f754
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ public class ImePerfTest extends ImePerfTestBase
            "IMMS.applyImeVisibility",
            "applyPostLayoutPolicy",
            "applyWindowSurfaceChanges",
            "ISC.onPreLayout",
            "ISC.onPostLayout"
    };

+2 −0
Original line number Diff line number Diff line
@@ -5082,6 +5082,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            setLayoutNeeded();
        }

        mInsetsStateController.onPreLayout();

        // Perform a layout, if needed.
        performLayout(true /* initial */, false /* updateInputWindows */);
        pendingLayoutChanges = 0;
+21 −6
Original line number Diff line number Diff line
@@ -70,6 +70,12 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
     */
    private boolean mServerVisible;

    /**
     * The server visibility of the source provider's window before the latest
     * {@link #onPreLayout} call.
     */
    private boolean mServerVisiblePreLayout;

    /**
     * When the IME is not ready, it has givenInsetsPending. However, this could happen again,
     * after it became serverVisible. This flag indicates is used to determine if it is
@@ -91,12 +97,17 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    @Override
    void onPostLayout() {
        boolean wasServerVisible = mServerVisible;
        super.onPostLayout();
    void onPreLayout() {
        mServerVisiblePreLayout = mServerVisible;
        super.onPreLayout();

        final boolean givenInsetsPending = mWin != null && mWin.mGivenInsetsPending;
        mLastDrawn = mWin != null && mWin.isDrawn();
    }

    @Override
    boolean onPostLayout() {
        final boolean controlDispatched = super.onPostLayout();
        final boolean givenInsetsPending = mWin != null && mWin.mGivenInsetsPending;

        // isLeashReadyForDispatching (used to dispatch the leash of the control) is
        // depending on mGivenInsetsReady. Therefore, triggering notifyControlChanged here
@@ -109,9 +120,12 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            mGivenInsetsReady = true;
            ImeTracker.forLogging().onProgress(mStatsToken,
                    ImeTracker.PHASE_WM_POST_LAYOUT_NOTIFY_CONTROLS_CHANGED);
            if (!controlDispatched) {
                mStateController.notifyControlChanged(mControlTarget, this);
            }
            setImeShowing(true);
        } else if (wasServerVisible && isServerVisible() && mGivenInsetsReady
            return true;
        } else if (mServerVisiblePreLayout && isServerVisible() && mGivenInsetsReady
                && givenInsetsPending) {
            // If the server visibility didn't change (still visible), and mGivenInsetsReady
            // is set, we won't call into notifyControlChanged. Therefore, we can reset the
@@ -127,6 +141,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
                    mControlTarget);
            setImeShowing(false);
        }
        return controlDispatched;
    }

    @Nullable
+22 −9
Original line number Diff line number Diff line
@@ -366,28 +366,41 @@ class InsetsSourceProvider {
    }

    /**
     * Called when a layout pass has occurred.
     * Called before a layout pass will occur.
     */
    void onPostLayout() {
    void onPreLayout() {
        if (mWin == null) {
            return;
        }
        final boolean isServerVisible = isSurfaceVisible();
        setServerVisible(isSurfaceVisible());
    }

        final boolean serverVisibleChanged = mServerVisible != isServerVisible;
        setServerVisible(isServerVisible);
    /**
     * Called after a layout pass has occurred.
     *
     * @return {@code true} if {@link InsetsStateController#notifyControlChanged} was called or
     * was scheduled to be called within this method, else {@code false}.
     */
    boolean onPostLayout() {
        if (mWin == null) {
            return false;
        }
        if (mControl != null && mControlTarget != null) {
            final boolean positionChanged = updateInsetsControlPosition(mWin);
            if (!(positionChanged || mHasPendingPosition)
            if (positionChanged || mHasPendingPosition) {
                return true;
            }
            // The insets hint would be updated while changing the position. Here updates it
                    // for the possible change of the bounds or the server visibility.
                    && (updateInsetsHint(mControl) || serverVisibleChanged)) {
            // for the possible change of the bounds.
            if (updateInsetsHint(mControl)) {
                // Only call notifyControlChanged here when the position hasn't been or won't be
                // changed. Otherwise, it has been called or scheduled to be called during
                // updateInsetsControlPosition.
                mStateController.notifyControlChanged(mControlTarget, this);
                return true;
            }
        }
        return false;
    }

    /**
+12 −1
Original line number Diff line number Diff line
@@ -188,7 +188,18 @@ class InsetsStateController {
    }

    /**
     * Called when a layout pass has occurred.
     * Called before a layout pass will occur.
     */
    void onPreLayout() {
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "ISC.onPreLayout");
        for (int i = mProviders.size() - 1; i >= 0; i--) {
            mProviders.valueAt(i).onPreLayout();
        }
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
    }

    /**
     * Called after a layout pass has occurred.
     */
    void onPostLayout() {
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "ISC.onPostLayout");
Loading