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

Commit 6b5f5e97 authored by Issei Suzuki's avatar Issei Suzuki
Browse files

Refined the logic to detect the location of DisplayCutout.

Bug: 117199965
Test: atest DisplayCutoutTest
Change-Id: I943922ff6e2866c783b88ce3b2c9bca494d688d7
parent e372602e
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -319,18 +319,23 @@ public final class DisplayCutout {
            sortedBounds[i] = ZERO_RECT;
        }
        if (safeInsets != null && boundingRects != null) {
            for (Rect bound : boundingRects) {
            // 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.
            // on the long edges, so either a) safeInsets.top and safeInsets.bottom is 0, or
            // b) safeInsets.left and safeInset.right is 0.
            final boolean topBottomInset = safeInsets.top > 0 || safeInsets.bottom > 0;
            for (Rect bound : boundingRects) {
                if (topBottomInset) {
                    if (bound.top == 0) {
                        sortedBounds[BOUNDS_POSITION_TOP] = bound;
                    } else {
                        sortedBounds[BOUNDS_POSITION_BOTTOM] = bound;
                    }
                } else {
                    if (bound.left == 0) {
                        sortedBounds[BOUNDS_POSITION_LEFT] = bound;
                } else if (bound.top == 0) {
                    sortedBounds[BOUNDS_POSITION_TOP] = bound;
                } else if (safeInsets.right > 0) {
                    } else {
                        sortedBounds[BOUNDS_POSITION_RIGHT] = bound;
                } else if (safeInsets.bottom > 0) {
                    sortedBounds[BOUNDS_POSITION_BOTTOM] = bound;
                    }
                }
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ public class DisplayCutoutTest {

    @Test
    public void testExtractBoundsFromList_top_and_bottom() {
        Rect safeInsets = new Rect(0, 1, 0, 10);
        Rect boundTop = new Rect(80, 0, 120, 10);
        Rect safeInsets = new Rect(0, 10, 0, 10);
        Rect boundTop = new Rect(0, 0, 120, 10);
        Rect boundBottom = new Rect(80, 190, 120, 200);
        assertThat(extractBoundsFromList(safeInsets,
                Arrays.asList(new Rect[]{boundTop, boundBottom})),