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

Commit de363d08 authored by Adrian Roos's avatar Adrian Roos
Browse files

DisplayCutout: Fix NPE in deprecated constructor and add nullability annotations

Change-Id: Ib791a41e399afbd8586f6b471165185e63b93ea4
Fixes: 117590687
Test: atest DisplayCutoutTest
parent c83ed073
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -245,9 +245,8 @@ public final class DisplayCutout {
     *                   passed, it's treated as an empty rectangle (0,0)-(0,0).
     */
    // TODO(b/73953958): @VisibleForTesting(visibility = PRIVATE)
    public DisplayCutout(
            Insets safeInsets, @Nullable Rect boundLeft, @Nullable Rect boundTop,
            @Nullable Rect boundRight, @Nullable Rect boundBottom) {
    public DisplayCutout(@NonNull Insets safeInsets, @Nullable Rect boundLeft,
            @Nullable Rect boundTop, @Nullable Rect boundRight, @Nullable Rect boundBottom) {
        this(safeInsets.toRect(), boundLeft, boundTop, boundRight, boundBottom, true);
    }

@@ -262,7 +261,7 @@ public final class DisplayCutout {
     */
    // TODO(b/73953958): @VisibleForTesting(visibility = PRIVATE)
    @Deprecated
    public DisplayCutout(Rect safeInsets, List<Rect> boundingRects) {
    public DisplayCutout(@Nullable Rect safeInsets, @Nullable List<Rect> boundingRects) {
        this(safeInsets, extractBoundsFromList(safeInsets, boundingRects),
                true /* copyArguments */);
    }
@@ -313,8 +312,9 @@ public final class DisplayCutout {
        for (int i = 0; i < sortedBounds.length; ++i) {
            sortedBounds[i] = ZERO_RECT;
        }
        if (safeInsets != null && boundingRects != null) {
            for (Rect bound : boundingRects) {
            // There will be at most one non-functional area per short edge of the device, and none
                // There is at most one non-functional area per short edge of the device, but none
                // on the long edges, so either safeInsets.right or safeInsets.bottom must be 0.
                // TODO(b/117199965): Refine the logic to handle edge cases.
                if (bound.left == 0) {
@@ -327,6 +327,7 @@ public final class DisplayCutout {
                    sortedBounds[BOUNDS_POSITION_BOTTOM] = bound;
                }
            }
        }
        return sortedBounds;
    }

@@ -389,6 +390,7 @@ public final class DisplayCutout {
     * @return a list of bounding {@code Rect}s, one for each display cutout area. No empty Rect is
     * returned.
     */
    @NonNull
    public List<Rect> getBoundingRects() {
        List<Rect> result = new ArrayList<>();
        for (Rect bound : getBoundingRectsAll()) {
+12 −0
Original line number Diff line number Diff line
@@ -103,6 +103,18 @@ public class DisplayCutoutTest {
                equalTo(new Rect[]{ZERO_RECT, boundTop, ZERO_RECT, boundBottom}));
    }

    @Test
    public void testExtractBoundsFromList_nullBoundingRects() {
        Rect safeInsets = new Rect(0, 0, 0, 0);
        assertThat(extractBoundsFromList(safeInsets, null /* boundingRects */),
                equalTo(new Rect[]{ZERO_RECT, ZERO_RECT, ZERO_RECT, ZERO_RECT}));
    }

    @Test
    public void testExtractBoundsFromList_nullSafeInsets() {
        assertThat(extractBoundsFromList(null /* safeInsets */, Collections.emptyList()),
                equalTo(new Rect[]{ZERO_RECT, ZERO_RECT, ZERO_RECT, ZERO_RECT}));
    }

    @Test
    public void hasCutout() throws Exception {