diff options
| author | 2023-03-01 18:53:15 +0000 | |
|---|---|---|
| committer | 2023-03-01 18:53:15 +0000 | |
| commit | e4d662a0d1102f7c86eb2e2e34d094464bbd4eb7 (patch) | |
| tree | 28f803591eea38ccaf097dcc73e743eb8c1e5340 | |
| parent | 98cc6ca03e4c6582d65fc4c6eceb8bdd4c5b8d8c (diff) | |
| parent | 3194b5a054e9fe86c74f8685091632ddffc5562c (diff) | |
Merge "Allow reachability for translucent activities" into tm-qpr-dev am: 3194b5a054
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21538127
Change-Id: I5f972774ffcb2d21e413fdba901ac049a6917254
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | services/core/java/com/android/server/wm/LetterboxUiController.java | 14 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/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 e1dbe01aca61..c20a51338739 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 318fff275f1f..8b506739ba77 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. @@ -168,6 +170,156 @@ public class SizeCompatTests extends WindowTestsBase { } @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<ActivityRecord, Rect> 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<Integer> 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<ActivityRecord, Rect> 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<Integer> 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); setUpDisplaySizeWithApp(2000, 1000); |