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

Commit 168bfd8e authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Revert "Keep runtime insets types during layout"

This reverts commit b863e6e4.

Reason for revert: Made G3Compat layout related tests flaky. See b/177911751

Bug: b/177911751
Test: Treehugger

Change-Id: I7e295beedc6581c01328a82b426a6d13feac2249
parent 66cbc53d
Loading
Loading
Loading
Loading
+9 −24
Original line number Diff line number Diff line
@@ -106,9 +106,7 @@ public class InsetsState implements Parcelable {
    public static final int ITYPE_NAVIGATION_BAR = 1;
    public static final int ITYPE_CAPTION_BAR = 2;

    // The always visible types are visible to all windows regardless of the z-order.
    public static final int FIRST_ALWAYS_VISIBLE_TYPE = 3;
    public static final int ITYPE_TOP_GESTURES = FIRST_ALWAYS_VISIBLE_TYPE;
    public static final int ITYPE_TOP_GESTURES = 3;
    public static final int ITYPE_BOTTOM_GESTURES = 4;
    public static final int ITYPE_LEFT_GESTURES = 5;
    public static final int ITYPE_RIGHT_GESTURES = 6;
@@ -119,16 +117,15 @@ public class InsetsState implements Parcelable {
    public static final int ITYPE_LEFT_MANDATORY_GESTURES = 9;
    public static final int ITYPE_RIGHT_MANDATORY_GESTURES = 10;

    public static final int ITYPE_LEFT_DISPLAY_CUTOUT = 11;
    public static final int ITYPE_TOP_DISPLAY_CUTOUT = 12;
    public static final int ITYPE_RIGHT_DISPLAY_CUTOUT = 13;
    public static final int ITYPE_BOTTOM_DISPLAY_CUTOUT = 14;
    public static final int LAST_ALWAYS_VISIBLE_TYPE = ITYPE_BOTTOM_DISPLAY_CUTOUT;
    public static final int ITYPE_LEFT_TAPPABLE_ELEMENT = 11;
    public static final int ITYPE_TOP_TAPPABLE_ELEMENT = 12;
    public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = 13;
    public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT = 14;

    public static final int ITYPE_LEFT_TAPPABLE_ELEMENT = 15;
    public static final int ITYPE_TOP_TAPPABLE_ELEMENT = 16;
    public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = 17;
    public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT = 18;
    public static final int ITYPE_LEFT_DISPLAY_CUTOUT = 15;
    public static final int ITYPE_TOP_DISPLAY_CUTOUT = 16;
    public static final int ITYPE_RIGHT_DISPLAY_CUTOUT = 17;
    public static final int ITYPE_BOTTOM_DISPLAY_CUTOUT = 18;

    /** Input method window. */
    public static final int ITYPE_IME = 19;
@@ -184,18 +181,6 @@ public class InsetsState implements Parcelable {
        set(copy, copySources);
    }

    /**
     * Mirror the always visible sources from the other state. They will share the same object for
     * the always visible types.
     *
     * @param other the state to mirror the mirrored sources from.
     */
    public void mirrorAlwaysVisibleInsetsSources(InsetsState other) {
        for (int type = FIRST_ALWAYS_VISIBLE_TYPE; type <= LAST_ALWAYS_VISIBLE_TYPE; type++) {
            mSources[type] = other.mSources[type];
        }
    }

    /**
     * Calculates {@link WindowInsets} based on the current source configuration.
     *
+15 −24
Original line number Diff line number Diff line
@@ -669,9 +669,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    // Used in updating override configurations
    private final Configuration mTempConfig = new Configuration();

    // Used in performing layout, to record the insets provided by other windows above the current
    // window.
    private InsetsState mTmpAboveInsetsState = new InsetsState();
    // Used in performing layout
    private boolean mTmpWindowsBehindIme;

    /**
     * Used to prevent recursions when calling
@@ -770,12 +769,18 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    + " parentHidden=" + w.isParentWindowHidden());
        }

        // Sets mAboveInsets for each window. Windows behind the window providing the insets can
        // receive the insets.
        if (!w.mAboveInsetsState.equals(mTmpAboveInsetsState)) {
            w.mAboveInsetsState.set(mTmpAboveInsetsState);
        // Sets mBehindIme for each window. Windows behind IME can get IME insets.
        if (w.mBehindIme != mTmpWindowsBehindIme) {
            w.mBehindIme = mTmpWindowsBehindIme;
            if (getInsetsStateController().getRawInsetsState().getSourceOrDefaultVisibility(
                    ITYPE_IME)) {
                // If IME is invisible, behind IME or not doesn't make the insets different.
                mWinInsetsChanged.add(w);
            }
        }
        if (w == mInputMethodWindow) {
            mTmpWindowsBehindIme = true;
        }

        // If this view is GONE, then skip it -- keep the current frame, and let the caller know
        // so they can ignore it if they want.  (We do the normal layout for INVISIBLE windows,
@@ -810,16 +815,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    + " mContainingFrame=" + w.getContainingFrame()
                    + " mDisplayFrame=" + w.getDisplayFrame());
        }
        provideInsetsByWindow(w);
    };

    private void provideInsetsByWindow(WindowState w) {
        for (int i = 0; i < w.mProvidedInsetsSources.size(); i++) {
            final InsetsSource providedSource = w.mProvidedInsetsSources.valueAt(i);
            mTmpAboveInsetsState.addSource(providedSource);
        }
    }

    private final Consumer<WindowState> mPerformLayoutAttached = w -> {
        if (w.mLayoutAttached) {
            if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
@@ -4272,20 +4269,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    + " dh=" + mDisplayInfo.logicalHeight);
        }

        // Used to indicate that we have processed the insets windows. This needs to be after
        // beginLayoutLw to ensure the raw insets state display related info is initialized.
        final InsetsState rawInsetsState = getInsetsStateController().getRawInsetsState();
        mTmpAboveInsetsState = new InsetsState();
        mTmpAboveInsetsState.setDisplayFrame(rawInsetsState.getDisplayFrame());
        mTmpAboveInsetsState.setDisplayCutout(rawInsetsState.getDisplayCutout());
        mTmpAboveInsetsState.mirrorAlwaysVisibleInsetsSources(rawInsetsState);

        int seq = mLayoutSeq + 1;
        if (seq < 0) seq = 0;
        mLayoutSeq = seq;

        mTmpInitial = initial;

        // Used to indicate that we have processed the IME window.
        mTmpWindowsBehindIme = false;

        // First perform layout of any root windows (not attached to another window).
        forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
+5 −9
Original line number Diff line number Diff line
@@ -152,7 +152,6 @@ class InsetsSourceProvider {
            // animate-out as new one animates-in.
            mWin.cancelAnimation();
            mWin.mPendingPositionChanged = null;
            mWin.mProvidedInsetsSources.remove(mSource.getType());
        }
        ProtoLog.d(WM_DEBUG_IME, "InsetsSource setWin %s", win);
        mWin = win;
@@ -162,9 +161,7 @@ class InsetsSourceProvider {
            setServerVisible(false);
            mSource.setFrame(new Rect());
            mSource.setVisibleFrame(null);
        } else {
            mWin.mProvidedInsetsSources.put(mSource.getType(), mSource);
            if (mControllable) {
        } else if (mControllable) {
            mWin.setControllableInsetProvider(this);
            if (mPendingControlTarget != null) {
                updateControlForTarget(mPendingControlTarget, true /* force */);
@@ -172,7 +169,6 @@ class InsetsSourceProvider {
            }
        }
    }
    }

    /**
     * @return Whether there is a window which backs this source.
+28 −11
Original line number Diff line number Diff line
@@ -104,8 +104,6 @@ class InsetsStateController {
     * visible to the target. e.g., the source which represents the target window itself, and the
     * IME source when the target is above IME. We also need to exclude certain types of insets
     * source for client within specific windowing modes.
     * This is to get the insets for a window layout on the screen. If the window is not there, use
     * the {@link #getInsetsForWindowMetrics} to get insets instead.
     *
     * @param target The window associate with the perspective.
     * @return The state stripped of the necessary information.
@@ -119,7 +117,7 @@ class InsetsStateController {
        final @InternalInsetsType int type = provider != null
                ? provider.getSource().getType() : ITYPE_INVALID;
        return getInsetsForTarget(type, target.getWindowingMode(), target.isAlwaysOnTop(),
                target.mAboveInsetsState);
                isAboveIme(target));
    }

    InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) {
@@ -134,7 +132,19 @@ class InsetsStateController {
        final @WindowingMode int windowingMode = token != null
                ? token.getWindowingMode() : WINDOWING_MODE_UNDEFINED;
        final boolean alwaysOnTop = token != null && token.isAlwaysOnTop();
        return getInsetsForTarget(type, windowingMode, alwaysOnTop, mState);
        return getInsetsForTarget(type, windowingMode, alwaysOnTop, isAboveIme(token));
    }

    private boolean isAboveIme(WindowContainer target) {
        final WindowState imeWindow = mDisplayContent.mInputMethodWindow;
        if (target == null || imeWindow == null) {
            return false;
        }
        if (target instanceof WindowState) {
            final WindowState win = (WindowState) target;
            return win.needsRelativeLayeringToIme() || !win.mBehindIme;
        }
        return false;
    }

    private static @InternalInsetsType
@@ -170,12 +180,11 @@ class InsetsStateController {
     * @see #getInsetsForWindowMetrics
     */
    private InsetsState getInsetsForTarget(@InternalInsetsType int type,
            @WindowingMode int windowingMode, boolean isAlwaysOnTop, InsetsState state) {
        boolean stateCopied = false;
            @WindowingMode int windowingMode, boolean isAlwaysOnTop, boolean aboveIme) {
        InsetsState state = mState;

        if (type != ITYPE_INVALID) {
            state = new InsetsState(state);
            stateCopied = true;
            state.removeSource(type);

            // Navigation bar doesn't get influenced by anything else
@@ -210,15 +219,23 @@ class InsetsStateController {

        if (WindowConfiguration.isFloating(windowingMode)
                || (windowingMode == WINDOWING_MODE_MULTI_WINDOW && isAlwaysOnTop)) {
            if (!stateCopied) {
            state = new InsetsState(state);
                stateCopied = true;
            }
            state.removeSource(ITYPE_STATUS_BAR);
            state.removeSource(ITYPE_NAVIGATION_BAR);
            state.removeSource(ITYPE_EXTRA_NAVIGATION_BAR);
        }

        if (aboveIme) {
            InsetsSource imeSource = state.peekSource(ITYPE_IME);
            if (imeSource != null && imeSource.isVisible()) {
                imeSource = new InsetsSource(imeSource);
                imeSource.setVisible(false);
                imeSource.setFrame(0, 0, 0, 0);
                state = new InsetsState(state);
                state.addSource(imeSource);
            }
        }

        return state;
    }

+2 −8
Original line number Diff line number Diff line
@@ -212,7 +212,6 @@ import android.os.Trace;
import android.os.WorkSource;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.MergedConfiguration;
@@ -647,14 +646,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    boolean mSeamlesslyRotated = false;

    /**
     * The insets state of sources provided by windows above the current window.
     * Indicates if this window is behind IME. Only windows behind IME can get insets from IME.
     */
    InsetsState mAboveInsetsState = new InsetsState();

    /**
     * The insets sources provided by this window.
     */
    ArrayMap<Integer, InsetsSource> mProvidedInsetsSources = new ArrayMap<>();
    boolean mBehindIme = false;

    /**
     * Surface insets from the previous call to relayout(), used to track
Loading