From f9f2b5937de9faf7c81950c628803808e1f1adfb Mon Sep 17 00:00:00 2001 From: lucychang Date: Mon, 19 Apr 2021 10:59:13 +0800 Subject: [PATCH] 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 --- .../server/wm/AccessibilityController.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/services/core/java/com/android/server/wm/AccessibilityController.java b/services/core/java/com/android/server/wm/AccessibilityController.java index d23579a1da89f..eb79518da9624 100644 --- a/services/core/java/com/android/server/wm/AccessibilityController.java +++ b/services/core/java/com/android/server/wm/AccessibilityController.java @@ -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); + } } }