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

Commit 2e0b5486 authored by Tiger Huang's avatar Tiger Huang
Browse files

Refine getSystemWindowInsets when compatIgnoreVisibility is true

Before this CL, WindowInsets#getSystemWindowInsets would only return the
vales in mTypeMaxInsetsMap (except IME) if mCompatIgnoreVisibility is
true. However, the caller might add insets to mTypeInsetsMap via
WindowInsets#replaceSystemWindowInsets. So when mCompatIgnoreVisibility
is true, anyone (including the framework) cannot get the insets added
previously from getSystemWindowInsets.

Before commit 68d2b2f4,
mCompatIgnoreVisibility would be cleared unexpectedly by Builder. So
this issue was not discovered.

This CL returns the larger values between typeInsetsMap and
typeMaxInsetsMap from getSystemWindowInsets when mCompatIgnoreVisibility
is true.

Fix: 428536047
Bug: 429707181
Flag: EXEMPT bug fix
Test: atest WindowInsetsTest
Change-Id: Ie965457279b3e5dd78c73c6995e678654894094a
parent 34121fc5
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -363,15 +363,10 @@ public final class WindowInsets {
    @Deprecated
    @NonNull
    public Insets getSystemWindowInsets() {
        Insets result = mCompatIgnoreVisibility
                ? getInsetsIgnoringVisibility(mCompatInsetsTypes & ~ime())
                : getInsets(mCompatInsetsTypes);

        // We can't query max insets for IME, so we need to add it manually after.
        if ((mCompatInsetsTypes & ime()) != 0 && mCompatIgnoreVisibility) {
            result = Insets.max(result, getInsets(ime()));
        }
        return result;
        final Insets result = getInsets(mCompatInsetsTypes);
        return mCompatIgnoreVisibility
                ? Insets.max(result, getInsetsIgnoringVisibility(mCompatInsetsTypes & ~ime()))
                : result;
    }

    /**
+30 −0
Original line number Diff line number Diff line
@@ -145,6 +145,36 @@ public class WindowInsetsTest {
                .consumeSystemWindowInsets().isConsumed());
    }

    /**
     * Verifies that {@link WindowInsets#getSystemWindowInsets} returns the maximum value at each
     * side between typeInsetsMap and typeMaxInsetsMap regarding compatInsetsTypes when
     * compatIgnoreVisibility is true.
     */
    @Test
    public void systemWindowInsets_compatIgnoreVisibility() {
        Insets[] insets = new Insets[TYPES.length];
        Insets[] maxInsets = new Insets[TYPES.length];
        boolean[] visible = new boolean[TYPES.length];

        // Creates Windowinsets with larger values in typeInsetsMap than ones in typeMaxInsetsMap.
        WindowInsets.assignCompatInsets(insets, new Rect(5, 6, 7, 8));
        WindowInsets.assignCompatInsets(maxInsets, new Rect(1, 2, 3, 4));
        WindowInsets windowInsets1 = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, systemBars(),
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        // If compatIgnoreVisibility is true, getSystemWindowInsets should return the larger values.
        assertEquals(Insets.of(5, 6, 7, 8), windowInsets1.getSystemWindowInsets());

        // Creates Windowinsets with larger values in typeMaxInsetsMap than ones in typeInsetsMap
        WindowInsets.assignCompatInsets(insets, new Rect(1, 2, 3, 4));
        WindowInsets.assignCompatInsets(maxInsets, new Rect(5, 6, 7, 8));
        WindowInsets windowInsets2 = new WindowInsets(insets, maxInsets, visible, false, 0,
                false, 0, null, null, null, DisplayShape.NONE, systemBars(),
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        // If compatIgnoreVisibility is true, getSystemWindowInsets should return the larger values.
        assertEquals(Insets.of(5, 6, 7, 8), windowInsets2.getSystemWindowInsets());
    }

    @Test
    public void multiNullConstructor_isConsumed() {
        assertTrue(new WindowInsets(null, null, null, false, 0, false, 0, null, null, null, null,