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

Commit 73f3e8ad authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Introduce new window insets launch flag

Instead of turning off the new window insets system fully on or
off, we introduce three modes:

0: Old system
1: New system for IME only
2: New system for IME + system bars

This allows us to launch the feature in IME only mode, in order to
avoid a lot of compatibility fallout around system bars.

Test: adb shell setprop persist.wm.new_insets 0/1/2
Bug: 118118435
Change-Id: Iaa49e62930b2539770cd313567dde4b102216097
parent 66e01c2f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -161,7 +161,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    private Insets getInsetsFromState(InsetsState state, Rect frame,
            @Nullable @InsetSide SparseIntArray typeSideMap) {
        return state.calculateInsets(frame, false /* isScreenRound */,
                false /* alwaysConsumerNavBar */, null /* displayCutout */, typeSideMap)
                false /* alwaysConsumerNavBar */, null /* displayCutout */,
                null /* legacyContentInsets */, null /* legacyStableInsets */, typeSideMap)
               .getInsets(mTypes);
    }

+9 −1
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ public class InsetsController implements WindowInsetsController {

    private final Runnable mAnimCallback;

    private final Rect mLastLegacyContentInsets = new Rect();
    private final Rect mLastLegacyStableInsets = new Rect();

    public InsetsController(ViewRootImpl viewRoot) {
        mViewRoot = viewRoot;
        mAnimCallback = () -> {
@@ -70,6 +73,7 @@ public class InsetsController implements WindowInsetsController {
            }
            WindowInsets insets = state.calculateInsets(mFrame, mLastInsets.isRound(),
                    mLastInsets.shouldAlwaysConsumeNavBar(), mLastInsets.getDisplayCutout(),
                    mLastLegacyContentInsets, mLastLegacyStableInsets,
                    null /* typeSideMap */);
            mViewRoot.mView.dispatchWindowInsetsAnimationProgress(insets);
        };
@@ -102,8 +106,12 @@ public class InsetsController implements WindowInsetsController {
     */
    @VisibleForTesting
    public WindowInsets calculateInsets(boolean isScreenRound,
            boolean alwaysConsumeNavBar, DisplayCutout cutout) {
            boolean alwaysConsumeNavBar, DisplayCutout cutout, Rect legacyContentInsets,
            Rect legacyStableInsets) {
        mLastLegacyContentInsets.set(legacyContentInsets);
        mLastLegacyStableInsets.set(legacyStableInsets);
        mLastInsets = mState.calculateInsets(mFrame, isScreenRound, alwaysConsumeNavBar, cutout,
                legacyContentInsets, legacyStableInsets,
                null /* typeSideMap */);
        return mLastInsets;
    }
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.ViewRootImpl.NEW_INSETS_MODE_IME;
import static android.view.WindowInsets.Type.indexOf;

import android.annotation.IntDef;
@@ -119,11 +120,17 @@ public class InsetsState implements Parcelable {
     */
    public WindowInsets calculateInsets(Rect frame, boolean isScreenRound,
            boolean alwaysConsumeNavBar, DisplayCutout cutout,
            @Nullable Rect legacyContentInsets, @Nullable Rect legacyStableInsets,
            @Nullable @InsetSide SparseIntArray typeSideMap) {
        Insets[] typeInsetsMap = new Insets[Type.SIZE];
        Insets[] typeMaxInsetsMap = new Insets[Type.SIZE];
        final Rect relativeFrame = new Rect(frame);
        final Rect relativeFrameMax = new Rect(frame);
        if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_IME
                && legacyContentInsets != null && legacyStableInsets != null) {
            WindowInsets.assignCompatInsets(typeInsetsMap, legacyContentInsets);
            WindowInsets.assignCompatInsets(typeMaxInsetsMap, legacyStableInsets);
        }
        for (int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
            InsetsSource source = mSources.get(type);
            if (source == null) {
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.view;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED;
import static java.lang.Math.max;
@@ -5123,7 +5124,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            sAcceptZeroSizeDragShadow = targetSdkVersion < Build.VERSION_CODES.P;
            sBrokenInsetsDispatch = !ViewRootImpl.USE_NEW_INSETS
            sBrokenInsetsDispatch = ViewRootImpl.sNewInsetsMode != NEW_INSETS_MODE_FULL
                    || targetSdkVersion < Build.VERSION_CODES.Q;
            sCompatibilityDone = true;
+29 −7
Original line number Diff line number Diff line
@@ -163,13 +163,16 @@ public final class ViewRootImpl implements ViewParent,
    private static final boolean MT_RENDERER_AVAILABLE = true;

    /**
     * If set to true, the view system will switch from using rectangles retrieved from window to
     * If set to 2, the view system will switch from using rectangles retrieved from window to
     * dispatch to the view hierarchy to using {@link InsetsController}, that derives the insets
     * directly from the full configuration, enabling richer information about the insets state, as
     * well as new APIs to control it frame-by-frame, and synchronize animations with it.
     * <p>
     * Only switch this to true once the new insets system is productionized and the old APIs are
     * Only set this to 2 once the new insets system is productionized and the old APIs are
     * fully migrated over.
     * <p>
     * If set to 1, this will switch to a mode where we only use the new approach for IME, but not
     * for the status/navigation bar.
     */
    private static final String USE_NEW_INSETS_PROPERTY = "persist.wm.new_insets";

@@ -177,8 +180,26 @@ public final class ViewRootImpl implements ViewParent,
     * @see #USE_NEW_INSETS_PROPERTY
     * @hide
     */
    public static final boolean USE_NEW_INSETS =
            SystemProperties.getBoolean(USE_NEW_INSETS_PROPERTY, false);
    public static final int sNewInsetsMode =
            SystemProperties.getInt(USE_NEW_INSETS_PROPERTY, 0);

    /**
     * @see #USE_NEW_INSETS_PROPERTY
     * @hide
     */
    public static final int NEW_INSETS_MODE_NONE = 0;

    /**
     * @see #USE_NEW_INSETS_PROPERTY
     * @hide
     */
    public static final int NEW_INSETS_MODE_IME = 1;

    /**
     * @see #USE_NEW_INSETS_PROPERTY
     * @hide
     */
    public static final int NEW_INSETS_MODE_FULL = 2;

    /**
     * Set this system property to true to force the view hierarchy to render
@@ -1367,7 +1388,7 @@ public final class ViewRootImpl implements ViewParent,
    }

    void notifyInsetsChanged() {
        if (!USE_NEW_INSETS) {
        if (sNewInsetsMode == NEW_INSETS_MODE_NONE) {
            return;
        }
        mApplyInsetsRequested = true;
@@ -1855,10 +1876,11 @@ public final class ViewRootImpl implements ViewParent,
            }
            contentInsets = ensureInsetsNonNegative(contentInsets, "content");
            stableInsets = ensureInsetsNonNegative(stableInsets, "stable");
            if (USE_NEW_INSETS) {
            if (sNewInsetsMode != NEW_INSETS_MODE_NONE) {
                mLastWindowInsets = mInsetsController.calculateInsets(
                        mContext.getResources().getConfiguration().isScreenRound(),
                        mAttachInfo.mAlwaysConsumeNavBar, displayCutout);
                        mAttachInfo.mAlwaysConsumeNavBar, displayCutout,
                        contentInsets, stableInsets);
            } else {
                mLastWindowInsets = new WindowInsets(contentInsets, stableInsets,
                        mContext.getResources().getConfiguration().isScreenRound(),
Loading