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

Commit 761a5ab0 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Treat IME adjust flags correctly

- IME insets always get reported through WindowInsets.getInsets(ime())
- However, getSystemWindowInsets will not report it if ADJUST_RESIZE
isn't set.
- Fix bitmask check for ADJUST_RESIZE

Test: InsetsStateTest
Test: WindowInsetsTest
Fixes: 146465040
Bug: 111084606
Change-Id: Ib19c89050af4f669ddda14d2bf2415aa3b5092c1
parent 5ba7d903
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -19,10 +19,15 @@ package android.view;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_IME;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_NONE;
import static android.view.WindowInsets.Type.IME;
import static android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES;
import static android.view.WindowInsets.Type.SIZE;
import static android.view.WindowInsets.Type.SYSTEM_GESTURES;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.indexOf;
import static android.view.WindowInsets.Type.systemBars;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;

import android.annotation.IntDef;
import android.annotation.Nullable;
@@ -156,11 +161,10 @@ public class InsetsState implements Parcelable {
                    && source.getType() != ITYPE_IME;
            boolean skipSystemBars = ViewRootImpl.sNewInsetsMode != NEW_INSETS_MODE_FULL
                    && (type == ITYPE_STATUS_BAR || type == ITYPE_NAVIGATION_BAR);
            boolean skipIme = source.getType() == ITYPE_IME
                    && (legacySoftInputMode & LayoutParams.SOFT_INPUT_ADJUST_RESIZE) == 0;
            boolean skipLegacyTypes = ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_NONE
                    && (toPublicType(type) & Type.compatSystemInsets()) != 0;
            if (skipSystemBars || skipIme || skipLegacyTypes || skipNonImeInImeMode) {
                    && (type == ITYPE_STATUS_BAR || type == ITYPE_NAVIGATION_BAR
                            || type == ITYPE_IME);
            if (skipSystemBars || skipLegacyTypes || skipNonImeInImeMode) {
                typeVisibilityMap[indexOf(toPublicType(type))] = source.isVisible();
                continue;
            }
@@ -175,8 +179,11 @@ public class InsetsState implements Parcelable {
                        typeMaxInsetsMap, null /* typeSideMap */, null /* typeVisibilityMap */);
            }
        }
        final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST;
        return new WindowInsets(typeInsetsMap, typeMaxInsetsMap, typeVisibilityMap, isScreenRound,
                alwaysConsumeSystemBars, cutout);
                alwaysConsumeSystemBars, cutout, softInputAdjustMode == SOFT_INPUT_ADJUST_RESIZE
                        ? systemBars() | ime()
                        : systemBars());
    }

    private void processSource(InsetsSource source, Rect relativeFrame, boolean ignoreVisibility,
+22 −21
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ import static android.view.WindowInsets.Type.STATUS_BARS;
import static android.view.WindowInsets.Type.SYSTEM_GESTURES;
import static android.view.WindowInsets.Type.TAPPABLE_ELEMENT;
import static android.view.WindowInsets.Type.all;
import static android.view.WindowInsets.Type.compatSystemInsets;
import static android.view.WindowInsets.Type.indexOf;
import static android.view.WindowInsets.Type.systemBars;

import android.annotation.IntDef;
import android.annotation.IntRange;
@@ -87,6 +87,8 @@ public final class WindowInsets {
    private final boolean mStableInsetsConsumed;
    private final boolean mDisplayCutoutConsumed;

    private final int mCompatInsetTypes;

    /**
     * Since new insets may be added in the future that existing apps couldn't
     * know about, this fully empty constant shouldn't be made available to apps
@@ -112,7 +114,7 @@ public final class WindowInsets {
            boolean isRound, boolean alwaysConsumeSystemBars, DisplayCutout displayCutout) {
        this(createCompatTypeMap(systemWindowInsetsRect), createCompatTypeMap(stableInsetsRect),
                createCompatVisibilityMap(createCompatTypeMap(systemWindowInsetsRect)),
                isRound, alwaysConsumeSystemBars, displayCutout);
                isRound, alwaysConsumeSystemBars, displayCutout, systemBars());
    }

    /**
@@ -131,7 +133,7 @@ public final class WindowInsets {
            @Nullable Insets[] typeMaxInsetsMap,
            boolean[] typeVisibilityMap,
            boolean isRound,
            boolean alwaysConsumeSystemBars, DisplayCutout displayCutout) {
            boolean alwaysConsumeSystemBars, DisplayCutout displayCutout, int compatInsetTypes) {
        mSystemWindowInsetsConsumed = typeInsetsMap == null;
        mTypeInsetsMap = mSystemWindowInsetsConsumed
                ? new Insets[SIZE]
@@ -145,6 +147,7 @@ public final class WindowInsets {
        mTypeVisibilityMap = typeVisibilityMap;
        mIsRound = isRound;
        mAlwaysConsumeSystemBars = alwaysConsumeSystemBars;
        mCompatInsetTypes = compatInsetTypes;

        mDisplayCutoutConsumed = displayCutout == null;
        mDisplayCutout = (mDisplayCutoutConsumed || displayCutout.isEmpty())
@@ -160,7 +163,8 @@ public final class WindowInsets {
        this(src.mSystemWindowInsetsConsumed ? null : src.mTypeInsetsMap,
                src.mStableInsetsConsumed ? null : src.mTypeMaxInsetsMap,
                src.mTypeVisibilityMap, src.mIsRound,
                src.mAlwaysConsumeSystemBars, displayCutoutCopyConstructorArgument(src));
                src.mAlwaysConsumeSystemBars, displayCutoutCopyConstructorArgument(src),
                src.mCompatInsetTypes);
    }

    private static DisplayCutout displayCutoutCopyConstructorArgument(WindowInsets w) {
@@ -211,7 +215,8 @@ public final class WindowInsets {
    /** @hide */
    @UnsupportedAppUsage
    public WindowInsets(Rect systemWindowInsets) {
        this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, false, null);
        this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, false, null,
                systemBars());
    }

    /**
@@ -280,7 +285,7 @@ public final class WindowInsets {
     */
    @NonNull
    public Insets getSystemWindowInsets() {
        return getInsets(mTypeInsetsMap, compatSystemInsets());
        return getInsets(mTypeInsetsMap, mCompatInsetTypes);
    }

    /**
@@ -439,7 +444,8 @@ public final class WindowInsets {
                mStableInsetsConsumed ? null : mTypeMaxInsetsMap,
                mTypeVisibilityMap,
                mIsRound, mAlwaysConsumeSystemBars,
                null /* displayCutout */);
                null /* displayCutout */,
                mCompatInsetTypes);
    }


@@ -485,7 +491,8 @@ public final class WindowInsets {
        return new WindowInsets(null, mStableInsetsConsumed ? null : mTypeMaxInsetsMap,
                mTypeVisibilityMap,
                mIsRound, mAlwaysConsumeSystemBars,
                displayCutoutCopyConstructorArgument(this));
                displayCutoutCopyConstructorArgument(this),
                mCompatInsetTypes);
    }

    // TODO(b/119190588): replace @code with @link below
@@ -555,7 +562,7 @@ public final class WindowInsets {
     */
    @NonNull
    public Insets getStableInsets() {
        return getInsets(mTypeMaxInsetsMap, compatSystemInsets());
        return getInsets(mTypeMaxInsetsMap, mCompatInsetTypes);
    }

    /**
@@ -733,7 +740,8 @@ public final class WindowInsets {
    public WindowInsets consumeStableInsets() {
        return new WindowInsets(mSystemWindowInsetsConsumed ? null : mTypeInsetsMap, null,
                mTypeVisibilityMap, mIsRound, mAlwaysConsumeSystemBars,
                displayCutoutCopyConstructorArgument(this));
                displayCutoutCopyConstructorArgument(this),
                mCompatInsetTypes);
    }

    /**
@@ -817,7 +825,8 @@ public final class WindowInsets {
                        ? null
                        : mDisplayCutout == null
                                ? DisplayCutout.NO_CUTOUT
                                : mDisplayCutout.inset(left, top, right, bottom));
                                : mDisplayCutout.inset(left, top, right, bottom),
                mCompatInsetTypes);
    }

    @Override
@@ -1134,7 +1143,8 @@ public final class WindowInsets {
        public WindowInsets build() {
            return new WindowInsets(mSystemInsetsConsumed ? null : mTypeInsetsMap,
                    mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap,
                    mIsRound, mAlwaysConsumeSystemBars, mDisplayCutout);
                    mIsRound, mAlwaysConsumeSystemBars, mDisplayCutout,
                    systemBars());
        }
    }

@@ -1270,15 +1280,6 @@ public final class WindowInsets {
            return STATUS_BARS | NAVIGATION_BARS;
        }

        /**
         * @return Inset types representing the list of bars that traditionally were denoted as
         *         system insets.
         * @hide
         */
        static @InsetsType int compatSystemInsets() {
            return STATUS_BARS | NAVIGATION_BARS | IME;
        }

        /**
         * @return All inset types combined.
         *
+13 −8
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.InsetsState.ITYPE_STATUS_BAR;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

import static org.junit.Assert.assertEquals;
@@ -116,15 +117,19 @@ public class InsetsStateTest {

    @Test
    public void testCalculateInsets_imeIgnoredWithoutAdjustResize() {
        try (final InsetsModeSession session =
                     new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_FULL)) {
            mState.getSource(ITYPE_STATUS_BAR).setFrame(new Rect(0, 0, 100, 100));
            mState.getSource(ITYPE_STATUS_BAR).setVisible(true);
            mState.getSource(ITYPE_IME).setFrame(new Rect(0, 200, 100, 300));
            mState.getSource(ITYPE_IME).setVisible(true);
            WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), false, false,
                DisplayCutout.NO_CUTOUT, null, null, 0, null);
                    DisplayCutout.NO_CUTOUT, null, null, SOFT_INPUT_ADJUST_NOTHING, null);
            assertEquals(0, insets.getSystemWindowInsetBottom());
            assertEquals(100, insets.getInsets(ime()).bottom);
            assertTrue(insets.isVisible(ime()));
        }
    }

    @Test
    public void testStripForDispatch() {
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ public class WindowInsetsTest {
        b.setInsets(navigationBars(), Insets.of(0, 0, 0, 100));
        b.setInsets(ime(), Insets.of(0, 0, 0, 300));
        WindowInsets insets = b.build();
        assertEquals(300, insets.getSystemWindowInsets().bottom);
        assertEquals(100, insets.getSystemWindowInsets().bottom);
        assertEquals(300, insets.getInsets(ime()).bottom);
    }

    // TODO: Move this to CTS once API made public