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
This commit is contained in:
Massimo Carli
2023-02-22 14:47:17 +00:00
parent 45b4cad82c
commit 96c0011984
2 changed files with 158 additions and 8 deletions

View File

@@ -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;
}

View File

@@ -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<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);