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

Commit f9f2b593 authored by lucychang's avatar lucychang Committed by Lucy Chang
Browse files

Account for letterbox space when computing touchable region

Account for letterbox space when computing touchable region to prevent
revealing background window which is covered by the letterbox.

Bug: 177982505
Test: atest AccessibilityWindowQueryTest on all display cutout types

Change-Id: Ica4f5e6964fb945cbe71a55cadd07367341936b6
parent d9b11089
Loading
Loading
Loading
Loading
+21 −20
Original line number Diff line number Diff line
@@ -974,7 +974,7 @@ final class AccessibilityController {
                    }

                    // Count letterbox into nonMagnifiedBounds
                    if (windowState.isLetterboxedForDisplayCutout()) {
                    if (windowState.isLetterboxedAppWindow()) {
                        Region letterboxBounds = getLetterboxBounds(windowState);
                        nonMagnifiedBounds.op(letterboxBounds, Region.Op.UNION);
                        availableBounds.op(letterboxBounds, Region.Op.DIFFERENCE);
@@ -1030,25 +1030,6 @@ final class AccessibilityController {
                }
            }

            private Region getLetterboxBounds(WindowState windowState) {
                final ActivityRecord appToken = windowState.mActivityRecord;
                if (appToken == null) {
                    return new Region();
                }

                mDisplay.getRealSize(mTempPoint);
                final Rect letterboxInsets = appToken.getLetterboxInsets();
                final int screenWidth = mTempPoint.x;
                final int screenHeight = mTempPoint.y;
                final Rect nonLetterboxRect = mTempRect1;
                final Region letterboxBounds = mTempRegion3;
                nonLetterboxRect.set(0, 0, screenWidth, screenHeight);
                nonLetterboxRect.inset(letterboxInsets);
                letterboxBounds.set(0, 0, screenWidth, screenHeight);
                letterboxBounds.op(nonLetterboxRect, Region.Op.DIFFERENCE);
                return letterboxBounds;
            }

            void onRotationChanged(SurfaceControl.Transaction t) {
                // If we are showing the magnification border, hide it immediately so
                // the user does not see strange artifacts during rotation. The screenshot
@@ -1430,6 +1411,20 @@ final class AccessibilityController {
        return source != null ? source.getFrame() : EMPTY_RECT;
    }

    static Region getLetterboxBounds(WindowState windowState) {
        final ActivityRecord appToken = windowState.mActivityRecord;
        if (appToken == null) {
            return new Region();
        }
        final Rect letterboxInsets = appToken.getLetterboxInsets();
        final Rect nonLetterboxRect = windowState.getBounds();
        nonLetterboxRect.inset(letterboxInsets);
        final Region letterboxBounds = new Region();
        letterboxBounds.set(windowState.getBounds());
        letterboxBounds.op(nonLetterboxRect, Region.Op.DIFFERENCE);
        return letterboxBounds;
    }

    /**
     * This class encapsulates the functionality related to computing the windows
     * reported for accessibility purposes. These windows are all windows a sighted
@@ -1734,6 +1729,12 @@ final class AccessibilityController {
                        unaccountedSpace.setEmpty();
                    }
                }

                // Account for the space of letterbox.
                if (windowState.isLetterboxedAppWindow()) {
                    unaccountedSpace.op(getLetterboxBounds(windowState), unaccountedSpace,
                            Region.Op.REVERSE_DIFFERENCE);
                }
            }
        }