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

Commit 68d2b2f4 authored by Tiger Huang's avatar Tiger Huang
Browse files

Copy mCompatInsetTypes and mCompatIgnoreVisibility

Before this CL, when creating a new WindowInsets based on an existing
one by using WindowInsets.Builder, some fields were not copyied
properly.

This CL passes mCompatInsetTypes and mCompatIgnoreVisibility from the
given WindowInsets to the newly created one.

This CL also refines the default value of mCompatInsetTypes of Builder,
which should be "systemBars() | displayCutout()" instead of
"systemBars()." See: compatInsetsTypes in InsetsState#calculateInsets.

Fix: 409469172
Flag: EXEMPT bugfix
Test: FrameworksCoreTests:WindowInsetsTest
      CtsWindowManagerDeviceInsets:WindowInsetsTest
Change-Id: Ief49e7981946689482e9301a467c59d0e3aaf3b7
parent f6a30104
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static android.internal.perfetto.protos.Insetsstate.InsetsStateProto.SOUR
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
import static android.view.WindowInsets.Type.SIZE;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.defaultCompatible;
import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.indexOf;
@@ -193,7 +194,7 @@ public class InsetsState implements Parcelable {
        final int softInputAdjustMode = legacySoftInputMode & SOFT_INPUT_MASK_ADJUST;

        @InsetsType
        int compatInsetsTypes = systemBars() | displayCutout();
        int compatInsetsTypes = defaultCompatible();
        if (softInputAdjustMode == SOFT_INPUT_ADJUST_RESIZE) {
            compatInsetsTypes |= ime();
        }
+35 −16
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ 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.defaultCompatible;
import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.indexOf;
@@ -139,7 +140,7 @@ public final class WindowInsets {
    static {
        CONSUMED = new WindowInsets(createCompatTypeMap(null), createCompatTypeMap(null),
                createCompatVisibilityMap(createCompatTypeMap(null)), false, 0, false, 0, null,
                null, null, null, systemBars(), false, null, null, 0, 0);
                null, null, null, defaultCompatible(), false, null, null, 0, 0);
    }

    /**
@@ -281,7 +282,7 @@ public final class WindowInsets {
    @UnsupportedAppUsage
    public WindowInsets(@Nullable Rect systemWindowInsets) {
        this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, 0, false, 0,
                null, null, null, null, systemBars(), false /* compatIgnoreVisibility */,
                null, null, null, null, defaultCompatible(), false /* compatIgnoreVisibility */,
                new Rect[SIZE][], null, 0, 0);
    }

@@ -358,8 +359,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return The system window insets
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    @NonNull
@@ -442,8 +443,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return The left system window inset
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    public int getSystemWindowInsetLeft() {
@@ -458,8 +459,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return The top system window inset
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    public int getSystemWindowInsetTop() {
@@ -474,8 +475,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return The right system window inset
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    public int getSystemWindowInsetRight() {
@@ -490,8 +491,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return The bottom system window inset
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    public int getSystemWindowInsetBottom() {
@@ -506,8 +507,8 @@ public final class WindowInsets {
     * </p>
     *
     * @return true if any of the system window inset values are nonzero
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()}
     * instead.
     * @deprecated Use {@link #getInsets(int)} with {@link Type#systemBars()} OR
     *             {@link Type#displayCutout()} instead.
     */
    @Deprecated
    public boolean hasSystemWindowInsets() {
@@ -1411,6 +1412,8 @@ public final class WindowInsets {
        private final Rect[][] mTypeBoundingRectsMap;
        @NonNull
        private final Rect[][] mTypeMaxBoundingRectsMap;
        private final @InsetsType int mCompatInsetTypes;
        private final boolean mCompatIgnoreVisibility;
        private boolean mSystemInsetsConsumed = true;
        private boolean mStableInsetsConsumed = true;

@@ -1442,6 +1445,8 @@ public final class WindowInsets {
            mTypeVisibilityMap = new boolean[SIZE];
            mTypeBoundingRectsMap = new Rect[SIZE][];
            mTypeMaxBoundingRectsMap = new Rect[SIZE][];
            mCompatInsetTypes = defaultCompatible();
            mCompatIgnoreVisibility = false;
        }

        /**
@@ -1453,6 +1458,8 @@ public final class WindowInsets {
            mTypeInsetsMap = insets.mTypeInsetsMap.clone();
            mTypeMaxInsetsMap = insets.mTypeMaxInsetsMap.clone();
            mTypeVisibilityMap = insets.mTypeVisibilityMap.clone();
            mCompatInsetTypes = insets.mCompatInsetsTypes;
            mCompatIgnoreVisibility = insets.mCompatIgnoreVisibility;
            mSystemInsetsConsumed = insets.mSystemWindowInsetsConsumed;
            mStableInsetsConsumed = insets.mStableInsetsConsumed;
            mDisplayCutout = displayCutoutCopyConstructorArgument(insets);
@@ -1478,7 +1485,8 @@ public final class WindowInsets {
         *
         * @see #getSystemWindowInsets()
         * @return itself
         * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()}.
         * @deprecated Use {@link #setInsets(int, Insets)} with {@link Type#systemBars()} or
         *             {@link Type#displayCutout()}.
         */
        @Deprecated
        @NonNull
@@ -1827,7 +1835,7 @@ public final class WindowInsets {
                    mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap,
                    mIsRound, mForceConsumingTypes, mForceConsumingOpaqueCaptionBar,
                    mSuppressScrimTypes, mDisplayCutout, mRoundedCorners, mPrivacyIndicatorBounds,
                    mDisplayShape, systemBars(), false /* compatIgnoreVisibility */,
                    mDisplayShape, mCompatInsetTypes, mCompatIgnoreVisibility,
                    mSystemInsetsConsumed ? null : mTypeBoundingRectsMap,
                    mStableInsetsConsumed ? null : mTypeMaxBoundingRectsMap,
                    mFrameWidth, mFrameHeight);
@@ -2060,6 +2068,17 @@ public final class WindowInsets {
            return STATUS_BARS | NAVIGATION_BARS | CAPTION_BAR | SYSTEM_OVERLAYS;
        }

        /**
         * @return Default compatible types.
         *
         * @see #getSystemWindowInsets()
         * @hide
         */
        @InsetsType
        public static int defaultCompatible() {
            return systemBars() | displayCutout();
        }

        /**
         * @return Default visible types.
         *
+47 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ package android.view;

import static android.view.WindowInsets.Type.SIZE;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.navigationBars;
import static android.view.WindowInsets.Type.statusBars;
import static android.view.WindowInsets.Type.systemBars;

import static org.junit.Assert.assertEquals;
@@ -72,6 +76,49 @@ public class WindowInsetsTest {
        assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets());
    }

    @Test
    public void builder_copy_compatInsetTypes() {
        final Insets[] insets = new Insets[SIZE];
        final Insets[] maxInsets = new Insets[SIZE];
        final boolean[] visible = new boolean[SIZE];
        final int compatInsetTypes = systemBars() | displayCutout() | ime();
        final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes,
                false /* compatIgnoreVisibility */, null, null, 0, 0);
        final WindowInsets modified = new WindowInsets.Builder(windowInsets)
                .setInsets(statusBars(), Insets.of(0, 10, 0, 0))
                .setInsets(navigationBars(), Insets.of(0, 0, 20, 0))
                .setInsets(displayCutout(), Insets.of(30, 0, 0, 0))
                .setInsets(ime(), Insets.of(0, 0, 0, 40))
                .build();
        assertEquals(Insets.of(30, 10, 20, 40), modified.getSystemWindowInsets());
    }

    @Test
    public void builder_copy_compatIgnoreVisibility() {
        final Insets[] insets = new Insets[SIZE];
        final Insets[] maxInsets = new Insets[SIZE];
        final boolean[] visible = new boolean[SIZE];
        final int compatInsetTypes = systemBars() | displayCutout();
        final WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, compatInsetTypes,
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        final WindowInsets modified = new WindowInsets.Builder(windowInsets)
                .setInsetsIgnoringVisibility(statusBars(), Insets.of(0, 10, 0, 0))
                .setInsetsIgnoringVisibility(navigationBars(), Insets.of(0, 0, 20, 0))
                .setInsetsIgnoringVisibility(displayCutout(), Insets.of(30, 0, 0, 0))
                .build();
        assertEquals(Insets.of(30, 10, 20, 0), modified.getSystemWindowInsets());
    }

    @Test
    public void builder_displayCutout_getSystemWindowInsets() {
        final WindowInsets windowInsets = new WindowInsets.Builder()
                .setInsets(displayCutout(), Insets.of(0, 10, 0, 0))
                .build();
        assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets());
    }

    @Test
    public void testSetBoundingRectsInBuilder_noInsets_preservedInWindowInsets() {
        final List<Rect> rects = List.of(new Rect(0, 0, 50, 100));