Loading core/java/android/view/DisplayCutout.java +18 −16 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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 */); } Loading Loading @@ -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) { Loading @@ -327,6 +327,7 @@ public final class DisplayCutout { sortedBounds[BOUNDS_POSITION_BOTTOM] = bound; } } } return sortedBounds; } Loading Loading @@ -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()) { Loading core/tests/coretests/src/android/view/DisplayCutoutTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading
core/java/android/view/DisplayCutout.java +18 −16 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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 */); } Loading Loading @@ -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) { Loading @@ -327,6 +327,7 @@ public final class DisplayCutout { sortedBounds[BOUNDS_POSITION_BOTTOM] = bound; } } } return sortedBounds; } Loading Loading @@ -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()) { Loading
core/tests/coretests/src/android/view/DisplayCutoutTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading