From 96c00119846a5e3064db2c370b9753e6afa809bf Mon Sep 17 00:00:00 2001 From: Massimo Carli Date: Wed, 22 Feb 2023 14:47:17 +0000 Subject: [PATCH] Allow reachability for translucent activities Fixes: 260857308 Test: Check if double tap works when a traslucent activities (e.g. permission dialogs) are letterboxed Run `atest WmTests:SizeCompatTests` Change-Id: I6408c6fd831c21f0a66617fb46f6ca40d1ba67bf --- .../server/wm/LetterboxUiController.java | 14 +- .../android/server/wm/SizeCompatTests.java | 152 ++++++++++++++++++ 2 files changed, 158 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index e1dbe01aca619..c20a51338739f 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -870,10 +870,9 @@ final class LetterboxUiController { return mActivityRecord.mWmService.mContext.getResources(); } - private void handleHorizontalDoubleTap(int x) { - // TODO(b/260857308): Investigate if enabling reachability for translucent activity - if (hasInheritedLetterboxBehavior() || !isHorizontalReachabilityEnabled() - || mActivityRecord.isInTransition()) { + @VisibleForTesting + void handleHorizontalDoubleTap(int x) { + if (!isHorizontalReachabilityEnabled() || mActivityRecord.isInTransition()) { return; } @@ -911,10 +910,9 @@ final class LetterboxUiController { mActivityRecord.recomputeConfiguration(); } - private void handleVerticalDoubleTap(int y) { - // TODO(b/260857308): Investigate if enabling reachability for translucent activity - if (hasInheritedLetterboxBehavior() || !isVerticalReachabilityEnabled() - || mActivityRecord.isInTransition()) { + @VisibleForTesting + void handleVerticalDoubleTap(int y) { + if (!isVerticalReachabilityEnabled() || mActivityRecord.isInTransition()) { return; } diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 318fff275f1f9..8b506739ba77d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -113,6 +113,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; /** * Tests for Size Compatibility mode. @@ -167,6 +169,156 @@ public class SizeCompatTests extends WindowTestsBase { setUpApp(builder.build()); } + @Test + public void testHorizontalReachabilityEnabledForTranslucentActivities() { + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + final LetterboxConfiguration config = mWm.mLetterboxConfiguration; + config.setTranslucentLetterboxingOverrideEnabled(true); + config.setLetterboxHorizontalPositionMultiplier(0.5f); + config.setIsHorizontalReachabilityEnabled(true); + + // Opaque activity + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + addWindowToActivity(mActivity); + mActivity.mRootWindowContainer.performSurfacePlacement(); + + // Translucent Activity + final ActivityRecord translucentActivity = new ActivityBuilder(mAtm) + .setLaunchedFromUid(mActivity.getUid()) + .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT) + .build(); + doReturn(false).when(translucentActivity).fillsParent(); + mTask.addChild(translucentActivity); + + spyOn(translucentActivity.mLetterboxUiController); + doReturn(true).when(translucentActivity.mLetterboxUiController) + .shouldShowLetterboxUi(any()); + + addWindowToActivity(translucentActivity); + translucentActivity.mRootWindowContainer.performSurfacePlacement(); + + final Function innerBoundsOf = + (ActivityRecord a) -> { + final Rect bounds = new Rect(); + a.mLetterboxUiController.getLetterboxInnerBounds(bounds); + return bounds; + }; + final Runnable checkLetterboxPositions = () -> assertEquals(innerBoundsOf.apply(mActivity), + innerBoundsOf.apply(translucentActivity)); + final Runnable checkIsLeft = () -> assertThat( + innerBoundsOf.apply(translucentActivity).left).isEqualTo(0); + final Runnable checkIsRight = () -> assertThat( + innerBoundsOf.apply(translucentActivity).right).isEqualTo(2500); + final Runnable checkIsCentered = () -> assertThat( + innerBoundsOf.apply(translucentActivity).left > 0 + && innerBoundsOf.apply(translucentActivity).right < 2500).isTrue(); + + final Consumer doubleClick = + (Integer x) -> { + mActivity.mLetterboxUiController.handleHorizontalDoubleTap(x); + mActivity.mRootWindowContainer.performSurfacePlacement(); + }; + + // Initial state + checkIsCentered.run(); + + // Double-click left + doubleClick.accept(/* x */ 10); + checkLetterboxPositions.run(); + checkIsLeft.run(); + + // Double-click right + doubleClick.accept(/* x */ 1990); + checkLetterboxPositions.run(); + checkIsCentered.run(); + + // Double-click right + doubleClick.accept(/* x */ 1990); + checkLetterboxPositions.run(); + checkIsRight.run(); + + // Double-click left + doubleClick.accept(/* x */ 10); + checkLetterboxPositions.run(); + checkIsCentered.run(); + } + + @Test + public void testVerticalReachabilityEnabledForTranslucentActivities() { + setUpDisplaySizeWithApp(1000, 2500); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + final LetterboxConfiguration config = mWm.mLetterboxConfiguration; + config.setTranslucentLetterboxingOverrideEnabled(true); + config.setLetterboxVerticalPositionMultiplier(0.5f); + config.setIsVerticalReachabilityEnabled(true); + + // Opaque activity + prepareUnresizable(mActivity, SCREEN_ORIENTATION_LANDSCAPE); + addWindowToActivity(mActivity); + mActivity.mRootWindowContainer.performSurfacePlacement(); + + // Translucent Activity + final ActivityRecord translucentActivity = new ActivityBuilder(mAtm) + .setLaunchedFromUid(mActivity.getUid()) + .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE) + .build(); + doReturn(false).when(translucentActivity).fillsParent(); + mTask.addChild(translucentActivity); + + spyOn(translucentActivity.mLetterboxUiController); + doReturn(true).when(translucentActivity.mLetterboxUiController) + .shouldShowLetterboxUi(any()); + + addWindowToActivity(translucentActivity); + translucentActivity.mRootWindowContainer.performSurfacePlacement(); + + final Function innerBoundsOf = + (ActivityRecord a) -> { + final Rect bounds = new Rect(); + a.mLetterboxUiController.getLetterboxInnerBounds(bounds); + return bounds; + }; + final Runnable checkLetterboxPositions = () -> assertEquals(innerBoundsOf.apply(mActivity), + innerBoundsOf.apply(translucentActivity)); + final Runnable checkIsTop = () -> assertThat( + innerBoundsOf.apply(translucentActivity).top).isEqualTo(0); + final Runnable checkIsBottom = () -> assertThat( + innerBoundsOf.apply(translucentActivity).bottom).isEqualTo(2500); + final Runnable checkIsCentered = () -> assertThat( + innerBoundsOf.apply(translucentActivity).top > 0 + && innerBoundsOf.apply(translucentActivity).bottom < 2500).isTrue(); + + final Consumer doubleClick = + (Integer y) -> { + mActivity.mLetterboxUiController.handleVerticalDoubleTap(y); + mActivity.mRootWindowContainer.performSurfacePlacement(); + }; + + // Initial state + checkIsCentered.run(); + + // Double-click top + doubleClick.accept(/* y */ 10); + checkLetterboxPositions.run(); + checkIsTop.run(); + + // Double-click bottom + doubleClick.accept(/* y */ 1990); + checkLetterboxPositions.run(); + checkIsCentered.run(); + + // Double-click bottom + doubleClick.accept(/* y */ 1990); + checkLetterboxPositions.run(); + checkIsBottom.run(); + + // Double-click top + doubleClick.accept(/* y */ 10); + checkLetterboxPositions.run(); + checkIsCentered.run(); + } + @Test public void testApplyStrategyToTranslucentActivities() { mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);