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

Commit c50899a4 authored by Jorge Gil's avatar Jorge Gil
Browse files

Clear [system/stable]InsetsConsumed when bounding rects are set

So that if any bounding rects have been set to the builder, they are
used in #build to create the WindowInsets.

Bug: 353751209
Test: atest WindowInsetsTest
Flag: EXEMPT bugfix
Change-Id: I252b85cb203629d3a306ec8897cd43b401fcd4e4
parent 36a3e6e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1708,6 +1708,7 @@ public final class WindowInsets {
                }
                mTypeBoundingRectsMap[indexOf(i)] = rects.toArray(new Rect[0]);
            }
            mSystemInsetsConsumed = false;
            return this;
        }

@@ -1736,6 +1737,7 @@ public final class WindowInsets {
                }
                mTypeMaxBoundingRectsMap[indexOf(i)] = rects.toArray(new Rect[0]);
            }
            mStableInsetsConsumed = false;
            return this;
        }

+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import static android.view.WindowInsets.Type.SIZE;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.systemBars;

import static org.junit.Assert.assertEquals;
@@ -32,6 +33,8 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

@RunWith(AndroidJUnit4.class)
@SmallTest
@Presubmit
@@ -68,4 +71,17 @@ public class WindowInsetsTest {
                true /* compatIgnoreVisibility */, null, null, 0, 0);
        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));
        final WindowInsets insets =
                new WindowInsets.Builder()
                        .setBoundingRects(captionBar(), rects)
                        .setBoundingRectsIgnoringVisibility(captionBar(), rects)
                        .build();

        assertEquals(rects, insets.getBoundingRects(captionBar()));
        assertEquals(rects, insets.getBoundingRectsIgnoringVisibility(captionBar()));
    }
}