Merge "[34/n] Migrating tests for AppCompatLetterboxPolicy/Overrides" into main
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
index 8d1ba5b..c788f3b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatActivityRobot.java
@@ -243,6 +243,18 @@
doReturn(embedded).when(mActivityStack.top()).isEmbedded();
}
+ void setTopActivityVisible(boolean isVisible) {
+ doReturn(isVisible).when(mActivityStack.top()).isVisible();
+ }
+
+ void setTopActivityVisibleRequested(boolean isVisibleRequested) {
+ doReturn(isVisibleRequested).when(mActivityStack.top()).isVisibleRequested();
+ }
+
+ void setTopActivityFillsParent(boolean fillsParent) {
+ doReturn(fillsParent).when(mActivityStack.top()).fillsParent();
+ }
+
void setTopActivityInMultiWindowMode(boolean multiWindowMode) {
doReturn(multiWindowMode).when(mActivityStack.top()).inMultiWindowMode();
if (multiWindowMode) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java
index 7760051..05f6ed6 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java
@@ -26,6 +26,8 @@
import androidx.annotation.NonNull;
+import com.android.server.wm.AppCompatConfiguration.LetterboxBackgroundType;
+
/**
* Robot implementation for {@link AppCompatConfiguration}.
*/
@@ -99,6 +101,32 @@
.getThinLetterboxHeightPx();
}
+ void setLetterboxActivityCornersRounded(boolean rounded) {
+ doReturn(rounded).when(mAppCompatConfiguration).isLetterboxActivityCornersRounded();
+ }
+
+ void setLetterboxEducationEnabled(boolean enabled) {
+ doReturn(enabled).when(mAppCompatConfiguration).getIsEducationEnabled();
+ }
+
+ void setLetterboxActivityCornersRadius(int cornerRadius) {
+ doReturn(cornerRadius).when(mAppCompatConfiguration).getLetterboxActivityCornersRadius();
+ }
+
+ void setLetterboxBackgroundType(@LetterboxBackgroundType int backgroundType) {
+ doReturn(backgroundType).when(mAppCompatConfiguration).getLetterboxBackgroundType();
+ }
+
+ void setLetterboxBackgroundWallpaperBlurRadiusPx(int blurRadiusPx) {
+ doReturn(blurRadiusPx).when(mAppCompatConfiguration)
+ .getLetterboxBackgroundWallpaperBlurRadiusPx();
+ }
+
+ void setLetterboxBackgroundWallpaperDarkScrimAlpha(float darkScrimAlpha) {
+ doReturn(darkScrimAlpha).when(mAppCompatConfiguration)
+ .getLetterboxBackgroundWallpaperDarkScrimAlpha();
+ }
+
void checkToNextLeftStop(boolean invoked) {
verify(mAppCompatConfiguration, times(invoked ? 1 : 0))
.movePositionForHorizontalReachabilityToNextLeftStop(anyBoolean());
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxOverrideTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxOverrideTest.java
new file mode 100644
index 0000000..af7f881
--- /dev/null
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxOverrideTest.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wm;
+
+import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND;
+import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING;
+import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_OVERRIDE_UNSET;
+import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR;
+import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_WALLPAPER;
+
+import static junit.framework.Assert.assertEquals;
+
+import android.platform.test.annotations.Presubmit;
+
+import androidx.annotation.NonNull;
+import androidx.test.filters.SmallTest;
+
+import com.android.server.wm.AppCompatConfiguration.LetterboxBackgroundType;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.function.Consumer;
+
+/**
+ * Test class for {@link AppCompatLetterboxOverrides}.
+ *
+ * Build/Install/Run:
+ * atest WmTests:AppCompatLetterboxOverrideTest
+ */
+@SmallTest
+@Presubmit
+@RunWith(WindowTestRunner.class)
+public class AppCompatLetterboxOverrideTest extends WindowTestsBase {
+
+ @Test
+ public void testIsLetterboxEducationEnabled() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxEducationEnabled(/* enabled */ true);
+ robot.checkLetterboxEducationEnabled(/* enabled */ true);
+
+ robot.conf().setLetterboxEducationEnabled(/* enabled */ false);
+ robot.checkLetterboxEducationEnabled(/* enabled */ false);
+ });
+ }
+
+ @Test
+ public void testShouldLetterboxHaveRoundedCorners() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.activity().setTopActivityFillsParent(/* fillsParent */ true);
+ robot.checkShouldLetterboxHaveRoundedCorners(/* expected */ true);
+
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ false);
+ robot.checkShouldLetterboxHaveRoundedCorners(/* expected */ false);
+
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.activity().setTopActivityFillsParent(/* fillsParent */ false);
+ robot.checkShouldLetterboxHaveRoundedCorners(/* expected */ false);
+ });
+ }
+
+ @Test
+ public void testHasWallpaperBackgroundForLetterbox() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+
+ robot.invokeCheckWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */ false);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+
+ robot.invokeCheckWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */ true);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ true);
+
+ robot.invokeCheckWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */ true);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ true);
+
+ robot.invokeCheckWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */ false);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+ });
+ }
+
+ @Test
+ public void testCheckWallpaperBackgroundForLetterbox() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+
+ robot.checkWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */
+ true, /* expected */ true);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ true);
+
+ robot.checkWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */
+ true, /* expected */ false);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ true);
+
+ robot.checkWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */
+ false, /* expected */ true);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+
+ robot.checkWallpaperBackgroundForLetterbox(/* wallpaperShouldBeShown */
+ false, /* expected */ false);
+ robot.checkHasWallpaperBackgroundForLetterbox(/* expected */ false);
+ });
+ }
+
+ @Test
+ public void testLetterboxActivityCornersRadius() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxActivityCornersRadius(/* cornerRadius */ 0);
+ robot.checkLetterboxActivityCornersRadius(/* cornerRadius */ 0);
+
+ robot.conf().setLetterboxActivityCornersRadius(/* cornerRadius */ 37);
+ robot.checkLetterboxActivityCornersRadius(/* cornerRadius */ 37);
+
+ robot.conf().setLetterboxActivityCornersRadius(/* cornerRadius */ 5);
+ robot.checkLetterboxActivityCornersRadius(/* cornerRadius */ 5);
+ });
+ }
+
+ @Test
+ public void testLetterboxActivityCornersRaunded() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.checkLetterboxActivityCornersRounded(/* expected */ true);
+
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ false);
+ robot.checkLetterboxActivityCornersRounded(/* expected */ false);
+ });
+ }
+
+ @Test
+ public void testLetterboxBackgroundType() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxBackgroundType(LETTERBOX_BACKGROUND_OVERRIDE_UNSET);
+ robot.checkLetterboxBackgroundType(LETTERBOX_BACKGROUND_OVERRIDE_UNSET);
+
+ robot.conf().setLetterboxBackgroundType(LETTERBOX_BACKGROUND_SOLID_COLOR);
+ robot.checkLetterboxBackgroundType(LETTERBOX_BACKGROUND_SOLID_COLOR);
+
+ robot.conf().setLetterboxBackgroundType(LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND);
+ robot.checkLetterboxBackgroundType(LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND);
+
+ robot.conf().setLetterboxBackgroundType(
+ LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING);
+ robot.checkLetterboxBackgroundType(LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING);
+
+ robot.conf().setLetterboxBackgroundType(LETTERBOX_BACKGROUND_WALLPAPER);
+ robot.checkLetterboxBackgroundType(LETTERBOX_BACKGROUND_WALLPAPER);
+ });
+ }
+
+ @Test
+ public void testLetterboxBackgroundWallpaperBlurRadiusPx() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxBackgroundWallpaperBlurRadiusPx(-1);
+ robot.checkLetterboxWallpaperBlurRadiusPx(0);
+
+ robot.conf().setLetterboxBackgroundWallpaperBlurRadiusPx(0);
+ robot.checkLetterboxWallpaperBlurRadiusPx(0);
+
+ robot.conf().setLetterboxBackgroundWallpaperBlurRadiusPx(10);
+ robot.checkLetterboxWallpaperBlurRadiusPx(10);
+ });
+ }
+
+ @Test
+ public void testLetterboxBackgroundWallpaperDarkScrimAlpha() {
+ runTestScenario((robot) -> {
+ robot.activity().createActivityWithComponent();
+
+ robot.conf().setLetterboxBackgroundWallpaperDarkScrimAlpha(-1f);
+ robot.checkLetterboxWallpaperDarkScrimAlpha(0);
+
+ robot.conf().setLetterboxBackgroundWallpaperDarkScrimAlpha(1.1f);
+ robot.checkLetterboxWallpaperDarkScrimAlpha(0);
+
+ robot.conf().setLetterboxBackgroundWallpaperDarkScrimAlpha(0.001f);
+ robot.checkLetterboxWallpaperDarkScrimAlpha(0.001f);
+
+ robot.conf().setLetterboxBackgroundWallpaperDarkScrimAlpha(0.999f);
+ robot.checkLetterboxWallpaperDarkScrimAlpha(0.999f);
+ });
+ }
+
+ /**
+ * Runs a test scenario providing a Robot.
+ */
+ void runTestScenario(@NonNull Consumer<LetterboxOverridesRobotTest> consumer) {
+ final LetterboxOverridesRobotTest robot =
+ new LetterboxOverridesRobotTest(mWm, mAtm, mSupervisor);
+ consumer.accept(robot);
+ }
+
+ private static class LetterboxOverridesRobotTest extends AppCompatRobotBase {
+ LetterboxOverridesRobotTest(@NonNull WindowManagerService wm,
+ @NonNull ActivityTaskManagerService atm,
+ @NonNull ActivityTaskSupervisor supervisor) {
+ super(wm, atm, supervisor);
+ }
+
+ void invokeCheckWallpaperBackgroundForLetterbox(boolean wallpaperShouldBeShown) {
+ getLetterboxOverrides().checkWallpaperBackgroundForLetterbox(wallpaperShouldBeShown);
+ }
+
+ void checkLetterboxEducationEnabled(boolean enabled) {
+ assertEquals(enabled, getLetterboxOverrides().isLetterboxEducationEnabled());
+ }
+
+ void checkShouldLetterboxHaveRoundedCorners(boolean expected) {
+ assertEquals(expected,
+ getLetterboxOverrides().shouldLetterboxHaveRoundedCorners());
+ }
+
+ void checkHasWallpaperBackgroundForLetterbox(boolean expected) {
+ assertEquals(expected,
+ getLetterboxOverrides().hasWallpaperBackgroundForLetterbox());
+ }
+
+ void checkWallpaperBackgroundForLetterbox(boolean wallpaperShouldBeShown,
+ boolean expected) {
+ assertEquals(expected,
+ getLetterboxOverrides().checkWallpaperBackgroundForLetterbox(
+ wallpaperShouldBeShown));
+ }
+
+ void checkLetterboxActivityCornersRadius(int expected) {
+ assertEquals(expected, getLetterboxOverrides().getLetterboxActivityCornersRadius());
+ }
+
+ void checkLetterboxActivityCornersRounded(boolean expected) {
+ assertEquals(expected, getLetterboxOverrides().isLetterboxActivityCornersRounded());
+ }
+
+ void checkLetterboxBackgroundType(@LetterboxBackgroundType int expected) {
+ assertEquals(expected, getLetterboxOverrides().getLetterboxBackgroundType());
+ }
+
+ void checkLetterboxWallpaperBlurRadiusPx(int expected) {
+ assertEquals(expected, getLetterboxOverrides().getLetterboxWallpaperBlurRadiusPx());
+ }
+
+ void checkLetterboxWallpaperDarkScrimAlpha(float expected) {
+ assertEquals(expected, getLetterboxOverrides().getLetterboxWallpaperDarkScrimAlpha(),
+ FLOAT_TOLLERANCE);
+ }
+
+ @NonNull
+ private AppCompatLetterboxOverrides getLetterboxOverrides() {
+ return activity().top().mAppCompatController.getAppCompatLetterboxOverrides();
+ }
+
+ }
+
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxPolicyTest.java
new file mode 100644
index 0000000..e046f7c
--- /dev/null
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatLetterboxPolicyTest.java
@@ -0,0 +1,382 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wm;
+
+import static android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+
+import android.graphics.Rect;
+import android.platform.test.annotations.Presubmit;
+import android.view.InsetsSource;
+import android.view.InsetsState;
+import android.view.RoundedCorner;
+import android.view.RoundedCorners;
+import android.view.WindowInsets;
+import android.view.WindowManager;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.test.filters.SmallTest;
+
+import com.android.internal.R;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.function.Consumer;
+
+/**
+ * Test class for {@link AppCompatLetterboxPolicy}.
+ *
+ * Build/Install/Run:
+ * atest WmTests:AppCompatLetterboxPolicyTest
+ */
+@SmallTest
+@Presubmit
+@RunWith(WindowTestRunner.class)
+public class AppCompatLetterboxPolicyTest extends WindowTestsBase {
+
+ @Test
+ public void testGetCropBoundsIfNeeded_handleCropForTransparentActivityBasedOnOpaqueBounds() {
+ runTestScenario((robot) -> {
+ robot.configureWindowStateWithTaskBar(/* hasTaskBarInsetsRoundedCorners */ true);
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+ robot.setTopActivityTransparentPolicyRunning(/* running */ true);
+ robot.activity().configureTopActivityBounds(new Rect(0, 0, 500, 300));
+
+ robot.resizeMainWindow(/* newWidth */ 499, /* newHeight */ 299);
+ robot.checkWindowStateHasCropBounds(/* expected */ false);
+
+ robot.resizeMainWindow(/* newWidth */ 500, /* newHeight */ 300);
+ robot.checkWindowStateHasCropBounds(/* expected */ true);
+ });
+ }
+
+ @Test
+ public void testGetCropBoundsIfNeeded_noCrop() {
+ runTestScenario((robot) -> {
+ robot.configureWindowStateWithTaskBar(/* hasTaskBarInsetsRoundedCorners */ false);
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+
+ // Do not apply crop if taskbar is collapsed
+ robot.collapseTaskBar();
+ robot.checkTaskBarIsExpanded(/* expected */ false);
+
+ robot.activity().configureTopActivityBounds(new Rect(50, 25, 150, 75));
+ robot.checkWindowStateHasCropBounds(/* expected */ true);
+ // Expected the same size of the activity.
+ robot.validateWindowStateCropBounds(0, 0, 100, 50);
+ });
+ }
+
+ @Test
+ public void testGetCropBoundsIfNeeded_appliesCrop() {
+ runTestScenario((robot) -> {
+ robot.configureWindowStateWithTaskBar(/* hasTaskBarInsetsRoundedCorners */ true);
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+
+ // Apply crop if taskbar is expanded.
+ robot.expandTaskBar();
+ robot.checkTaskBarIsExpanded(/* expected */ true);
+
+ robot.activity().configureTopActivityBounds(new Rect(50, 0, 150, 100));
+ robot.checkWindowStateHasCropBounds(/* expected */ true);
+ // The task bar expanded height is removed from the crop height.
+ robot.validateWindowStateCropBounds(0, 0, 100, 80);
+ });
+ }
+
+ @Test
+ public void testGetCropBoundsIfNeeded_appliesCropWithSizeCompatScaling() {
+ runTestScenario((robot) -> {
+ robot.configureWindowStateWithTaskBar(/* hasTaskBarInsetsRoundedCorners */ true);
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+
+ // Apply crop if taskbar is expanded.
+ robot.expandTaskBar();
+ robot.checkTaskBarIsExpanded(/* expected */ true);
+ robot.activity().setTopActivityInSizeCompatMode(/* isScm */ true);
+ robot.setInvCompatState(/* scale */ 2.0f);
+
+ robot.activity().configureTopActivityBounds(new Rect(50, 0, 150, 100));
+
+ robot.checkWindowStateHasCropBounds(/* expected */ true);
+ // The width and height, considering task bar, are scaled by 2.
+ robot.validateWindowStateCropBounds(0, 0, 200, 160);
+ });
+ }
+
+ @Test
+ public void testGetRoundedCornersRadius_withRoundedCornersFromInsets() {
+ runTestScenario((robot) -> {
+ robot.conf().setLetterboxActivityCornersRadius(-1);
+ robot.configureWindowState();
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+
+ robot.setInvCompatState(/* scale */ 0.5f);
+ robot.configureInsetsRoundedCorners(new RoundedCorners(
+ /*topLeft=*/ null,
+ /*topRight=*/ null,
+ /*bottomRight=*/ new RoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT,
+ /* configurationRadius */ 15, /*centerX=*/ 1, /*centerY=*/ 1),
+ /*bottomLeft=*/ new RoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT,
+ 30 /*2 is to test selection of the min radius*/,
+ /*centerX=*/ 1, /*centerY=*/ 1)
+ ));
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 7);
+ });
+ }
+
+
+ @Test
+ public void testGetRoundedCornersRadius_withLetterboxActivityCornersRadius() {
+ runTestScenario((robot) -> {
+ robot.conf().setLetterboxActivityCornersRadius(15);
+ robot.configureWindowState();
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+ robot.setInvCompatState(/* scale */ 0.5f);
+
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ true);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 7);
+
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 7);
+
+ robot.activity().setTopActivityVisibleRequested(/* isVisibleRequested */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ false);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 0);
+
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ true);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 7);
+ });
+ }
+
+ @Test
+ public void testGetRoundedCornersRadius_noScalingApplied() {
+ runTestScenario((robot) -> {
+ robot.conf().setLetterboxActivityCornersRadius(15);
+ robot.configureWindowState();
+ robot.activity().createActivityWithComponent();
+ robot.setTopActivityInLetterboxAnimation(/* inLetterboxAnimation */ false);
+ robot.activity().setTopActivityVisible(/* isVisible */ true);
+ robot.setIsLetterboxedForFixedOrientationAndAspectRatio(/* inLetterbox */ true);
+ robot.conf().setLetterboxActivityCornersRounded(/* rounded */ true);
+ robot.resources().configureGetDimensionPixelSize(R.dimen.taskbar_frame_height, 20);
+
+ robot.setInvCompatState(/* scale */ -1f);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 15);
+
+ robot.setInvCompatState(/* scale */ 0f);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 15);
+
+ robot.setInvCompatState(/* scale */ 1f);
+ robot.checkWindowStateRoundedCornersRadius(/* expected */ 15);
+ });
+ }
+
+ /**
+ * Runs a test scenario providing a Robot.
+ */
+ void runTestScenario(@NonNull Consumer<LetterboxPolicyRobotTest> consumer) {
+ final LetterboxPolicyRobotTest robot = new LetterboxPolicyRobotTest(mWm, mAtm, mSupervisor);
+ consumer.accept(robot);
+ }
+
+ private static class LetterboxPolicyRobotTest extends AppCompatRobotBase {
+
+ static final int TASKBAR_COLLAPSED_HEIGHT = 10;
+ static final int TASKBAR_EXPANDED_HEIGHT = 20;
+ private static final int SCREEN_WIDTH = 200;
+ private static final int SCREEN_HEIGHT = 100;
+ static final Rect TASKBAR_COLLAPSED_BOUNDS = new Rect(0,
+ SCREEN_HEIGHT - TASKBAR_COLLAPSED_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
+ static final Rect TASKBAR_EXPANDED_BOUNDS = new Rect(0,
+ SCREEN_HEIGHT - TASKBAR_EXPANDED_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
+
+ @NonNull
+ private final WindowState mWindowState;
+ @Nullable
+ private InsetsSource mTaskbar;
+ @Nullable
+ private InsetsState mInsetsState;
+
+ LetterboxPolicyRobotTest(@NonNull WindowManagerService wm,
+ @NonNull ActivityTaskManagerService atm,
+ @NonNull ActivityTaskSupervisor supervisor) {
+ super(wm, atm, supervisor);
+ mWindowState = mock(WindowState.class);
+ }
+
+ @Override
+ void onPostActivityCreation(@NonNull ActivityRecord activity) {
+ super.onPostActivityCreation(activity);
+ spyOn(getAspectRatioPolicy());
+ spyOn(getTransparentPolicy());
+ }
+
+ void configureWindowStateWithTaskBar(boolean hasInsetsRoundedCorners) {
+ configureWindowState(/* withTaskBar */ true, hasInsetsRoundedCorners);
+ }
+
+ void configureWindowState() {
+ configureWindowState(/* withTaskBar */ false, /* hasInsetsRoundedCorners */ false);
+ }
+
+ void configureInsetsRoundedCorners(@NonNull RoundedCorners roundedCorners) {
+ mInsetsState.setRoundedCorners(roundedCorners);
+ }
+
+ private void configureWindowState(boolean withTaskBar, boolean hasInsetsRoundedCorners) {
+ mInsetsState = new InsetsState();
+ if (withTaskBar) {
+ mTaskbar = new InsetsSource(/*id=*/ 0,
+ WindowInsets.Type.navigationBars());
+ if (hasInsetsRoundedCorners) {
+ mTaskbar.setFlags(FLAG_INSETS_ROUNDED_CORNER, FLAG_INSETS_ROUNDED_CORNER);
+ }
+ mTaskbar.setVisible(true);
+ mInsetsState.addSource(mTaskbar);
+ }
+ mWindowState.mInvGlobalScale = 1f;
+ final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams();
+ doReturn(mInsetsState).when(mWindowState).getInsetsState();
+ doReturn(attrs).when(mWindowState).getAttrs();
+ doReturn(true).when(mWindowState).isDrawn();
+ doReturn(true).when(mWindowState).isOnScreen();
+ doReturn(false).when(mWindowState).isLetterboxedForDisplayCutout();
+ doReturn(true).when(mWindowState).areAppWindowBoundsLetterboxed();
+ }
+
+ void setInvCompatState(float scale) {
+ mWindowState.mInvGlobalScale = scale;
+ }
+
+ void setTopActivityInLetterboxAnimation(boolean inLetterboxAnimation) {
+ doReturn(inLetterboxAnimation).when(activity().top()).isInLetterboxAnimation();
+ }
+
+ void setTopActivityTransparentPolicyRunning(boolean running) {
+ doReturn(running).when(getTransparentPolicy()).isRunning();
+ }
+
+ void setIsLetterboxedForFixedOrientationAndAspectRatio(boolean isLetterboxed) {
+ doReturn(isLetterboxed).when(getAspectRatioPolicy())
+ .isLetterboxedForFixedOrientationAndAspectRatio();
+ }
+
+ void resizeMainWindow(int newWidth, int newHeight) {
+ mWindowState.mRequestedWidth = newWidth;
+ mWindowState.mRequestedHeight = newHeight;
+ }
+
+ void collapseTaskBar() {
+ mTaskbar.setFrame(TASKBAR_COLLAPSED_BOUNDS);
+ }
+
+ void expandTaskBar() {
+ mTaskbar.setFrame(TASKBAR_EXPANDED_BOUNDS);
+ }
+
+ void checkWindowStateHasCropBounds(boolean expected) {
+ final Rect cropBounds = getAppCompatLetterboxPolicy().getCropBoundsIfNeeded(
+ mWindowState);
+ if (expected) {
+ assertNotNull(cropBounds);
+ } else {
+ assertNull(cropBounds);
+ }
+ }
+
+ void checkTaskBarIsExpanded(boolean expected) {
+ final InsetsSource expandedTaskBar = AppCompatUtils.getExpandedTaskbarOrNull(
+ mWindowState);
+ if (expected) {
+ assertNotNull(expandedTaskBar);
+ } else {
+ assertNull(expandedTaskBar);
+ }
+ }
+
+ void checkWindowStateRoundedCornersRadius(int expected) {
+ assertEquals(expected, getAppCompatLetterboxPolicy()
+ .getRoundedCornersRadius(mWindowState));
+ }
+
+ void validateWindowStateCropBounds(int left, int top, int right, int bottom) {
+ final Rect cropBounds = getAppCompatLetterboxPolicy().getCropBoundsIfNeeded(
+ mWindowState);
+ assertEquals(left, cropBounds.left);
+ assertEquals(top, cropBounds.top);
+ assertEquals(right, cropBounds.right);
+ assertEquals(bottom, cropBounds.bottom);
+ }
+
+ @NonNull
+ private AppCompatAspectRatioPolicy getAspectRatioPolicy() {
+ return activity().top().mAppCompatController.getAppCompatAspectRatioPolicy();
+ }
+
+ @NonNull
+ private TransparentPolicy getTransparentPolicy() {
+ return activity().top().mAppCompatController.getTransparentPolicy();
+ }
+
+ @NonNull
+ private AppCompatLetterboxPolicy getAppCompatLetterboxPolicy() {
+ return activity().top().mAppCompatController.getAppCompatLetterboxPolicy();
+ }
+
+ }
+
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatResourcesRobot.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatResourcesRobot.java
new file mode 100644
index 0000000..05e9a0f
--- /dev/null
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatResourcesRobot.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wm;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+
+import static org.mockito.Mockito.doReturn;
+
+import android.content.res.Resources;
+
+import androidx.annotation.DimenRes;
+import androidx.annotation.NonNull;
+
+/**
+ * Robot for managing {@link Resources} in unit tests.
+ */
+public class AppCompatResourcesRobot {
+
+ @NonNull
+ private final Resources mResources;
+
+ AppCompatResourcesRobot(@NonNull Resources resources) {
+ mResources = resources;
+ spyOn(mResources);
+ }
+
+ void configureGetDimensionPixelSize(@DimenRes int resId, int value) {
+ doReturn(value).when(mResources).getDimensionPixelSize(resId);
+ }
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/AppCompatRobotBase.java b/services/tests/wmtests/src/com/android/server/wm/AppCompatRobotBase.java
index 4e58e1d..5f2a63a 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AppCompatRobotBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AppCompatRobotBase.java
@@ -37,6 +37,8 @@
private final AppCompatConfigurationRobot mConfigurationRobot;
@NonNull
private final AppCompatComponentPropRobot mOptPropRobot;
+ @NonNull
+ private final AppCompatResourcesRobot mResourcesRobot;
AppCompatRobotBase(@NonNull WindowManagerService wm,
@NonNull ActivityTaskManagerService atm,
@@ -48,6 +50,7 @@
mConfigurationRobot =
new AppCompatConfigurationRobot(wm.mAppCompatConfiguration);
mOptPropRobot = new AppCompatComponentPropRobot(wm);
+ mResourcesRobot = new AppCompatResourcesRobot(wm.mContext.getResources());
}
AppCompatRobotBase(@NonNull WindowManagerService wm,
@@ -60,7 +63,7 @@
* Specific Robots can override this method to add operation to run on a newly created
* {@link ActivityRecord}. Common case is to invoke spyOn().
*
- * @param activity THe newly created {@link ActivityRecord}.
+ * @param activity The newly created {@link ActivityRecord}.
*/
@CallSuper
void onPostActivityCreation(@NonNull ActivityRecord activity) {
@@ -81,7 +84,6 @@
return mConfigurationRobot;
}
- @NonNull
void applyOnConf(@NonNull Consumer<AppCompatConfigurationRobot> consumer) {
consumer.accept(mConfigurationRobot);
}
@@ -91,7 +93,6 @@
return mActivityRobot;
}
- @NonNull
void applyOnActivity(@NonNull Consumer<AppCompatActivityRobot> consumer) {
consumer.accept(mActivityRobot);
}
@@ -101,8 +102,16 @@
return mOptPropRobot;
}
- @NonNull
void applyOnProp(@NonNull Consumer<AppCompatComponentPropRobot> consumer) {
consumer.accept(mOptPropRobot);
}
+
+ @NonNull
+ AppCompatResourcesRobot resources() {
+ return mResourcesRobot;
+ }
+
+ void applyOnResources(@NonNull Consumer<AppCompatResourcesRobot> consumer) {
+ consumer.accept(mResourcesRobot);
+ }
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
deleted file mode 100644
index 8947522..0000000
--- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import static android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER;
-
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.annotation.Nullable;
-import android.compat.testing.PlatformCompatChangeRule;
-import android.content.ComponentName;
-import android.content.res.Resources;
-import android.graphics.Rect;
-import android.platform.test.annotations.Presubmit;
-import android.view.InsetsSource;
-import android.view.InsetsState;
-import android.view.RoundedCorner;
-import android.view.RoundedCorners;
-import android.view.WindowInsets;
-import android.view.WindowManager;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.internal.R;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.runner.RunWith;
-
-/**
- * Test class for {@link LetterboxUiController}.
- *
- * Build/Install/Run:
- * atest WmTests:LetterboxUiControllerTest
- */
-@SmallTest
-@Presubmit
-@RunWith(WindowTestRunner.class)
-public class LetterboxUiControllerTest extends WindowTestsBase {
- private static final int TASKBAR_COLLAPSED_HEIGHT = 10;
- private static final int TASKBAR_EXPANDED_HEIGHT = 20;
- private static final int SCREEN_WIDTH = 200;
- private static final int SCREEN_HEIGHT = 100;
- private static final Rect TASKBAR_COLLAPSED_BOUNDS = new Rect(0,
- SCREEN_HEIGHT - TASKBAR_COLLAPSED_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
- private static final Rect TASKBAR_EXPANDED_BOUNDS = new Rect(0,
- SCREEN_HEIGHT - TASKBAR_EXPANDED_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
-
- @Rule
- public TestRule compatChangeRule = new PlatformCompatChangeRule();
-
- private ActivityRecord mActivity;
- private Task mTask;
- private DisplayContent mDisplayContent;
- private AppCompatConfiguration mAppCompatConfiguration;
- private final Rect mLetterboxedPortraitTaskBounds = new Rect();
-
- @Before
- public void setUp() throws Exception {
- mActivity = setUpActivityWithComponent();
-
- mAppCompatConfiguration = mWm.mAppCompatConfiguration;
- spyOn(mAppCompatConfiguration);
- }
-
- @Test
- public void testGetCropBoundsIfNeeded_handleCropForTransparentActivityBasedOnOpaqueBounds() {
- final InsetsSource taskbar = new InsetsSource(/*id=*/ 0,
- WindowInsets.Type.navigationBars());
- taskbar.setFlags(FLAG_INSETS_ROUNDED_CORNER, FLAG_INSETS_ROUNDED_CORNER);
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(taskbar);
- final Rect opaqueBounds = new Rect(0, 0, 500, 300);
- doReturn(opaqueBounds).when(mActivity).getBounds();
- // Activity is translucent
- spyOn(mActivity.mAppCompatController.getTransparentPolicy());
- when(mActivity.mAppCompatController.getTransparentPolicy()
- .isRunning()).thenReturn(true);
-
- // Makes requested sizes different
- mainWindow.mRequestedWidth = opaqueBounds.width() - 1;
- mainWindow.mRequestedHeight = opaqueBounds.height() - 1;
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
- assertNull(letterboxPolicy.getCropBoundsIfNeeded(mainWindow));
-
- // Makes requested sizes equals
- mainWindow.mRequestedWidth = opaqueBounds.width();
- mainWindow.mRequestedHeight = opaqueBounds.height();
- assertNotNull(letterboxPolicy.getCropBoundsIfNeeded(mainWindow));
- }
-
- @Test
- public void testGetCropBoundsIfNeeded_noCrop() {
- final InsetsSource taskbar = new InsetsSource(/*id=*/ 0,
- WindowInsets.Type.navigationBars());
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(taskbar);
-
- // Do not apply crop if taskbar is collapsed
- taskbar.setFrame(TASKBAR_COLLAPSED_BOUNDS);
- assertNull(AppCompatUtils.getExpandedTaskbarOrNull(mainWindow));
-
- mLetterboxedPortraitTaskBounds.set(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4,
- SCREEN_WIDTH - SCREEN_WIDTH / 4, SCREEN_HEIGHT - SCREEN_HEIGHT / 4);
-
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
-
- final Rect noCrop = letterboxPolicy.getCropBoundsIfNeeded(mainWindow);
- assertNotEquals(null, noCrop);
- assertEquals(0, noCrop.left);
- assertEquals(0, noCrop.top);
- assertEquals(mLetterboxedPortraitTaskBounds.width(), noCrop.right);
- assertEquals(mLetterboxedPortraitTaskBounds.height(), noCrop.bottom);
- }
-
- @Test
- public void testGetCropBoundsIfNeeded_appliesCrop() {
- final InsetsSource taskbar = new InsetsSource(/*id=*/ 0,
- WindowInsets.Type.navigationBars());
- taskbar.setFlags(FLAG_INSETS_ROUNDED_CORNER, FLAG_INSETS_ROUNDED_CORNER);
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(taskbar);
-
- // Apply crop if taskbar is expanded
- taskbar.setFrame(TASKBAR_EXPANDED_BOUNDS);
- assertNotNull(AppCompatUtils.getExpandedTaskbarOrNull(mainWindow));
-
- mLetterboxedPortraitTaskBounds.set(SCREEN_WIDTH / 4, 0, SCREEN_WIDTH - SCREEN_WIDTH / 4,
- SCREEN_HEIGHT);
-
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
- final Rect crop = letterboxPolicy.getCropBoundsIfNeeded(mainWindow);
- assertNotEquals(null, crop);
- assertEquals(0, crop.left);
- assertEquals(0, crop.top);
- assertEquals(mLetterboxedPortraitTaskBounds.width(), crop.right);
- assertEquals(mLetterboxedPortraitTaskBounds.height() - TASKBAR_EXPANDED_HEIGHT,
- crop.bottom);
- }
-
- @Test
- public void testGetCropBoundsIfNeeded_appliesCropWithSizeCompatScaling() {
- final InsetsSource taskbar = new InsetsSource(/*id=*/ 0,
- WindowInsets.Type.navigationBars());
- taskbar.setFlags(FLAG_INSETS_ROUNDED_CORNER, FLAG_INSETS_ROUNDED_CORNER);
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(taskbar);
- final float scaling = 2.0f;
-
- // Apply crop if taskbar is expanded
- taskbar.setFrame(TASKBAR_EXPANDED_BOUNDS);
- assertNotNull(AppCompatUtils.getExpandedTaskbarOrNull(mainWindow));
- // With SizeCompat scaling
- doReturn(true).when(mActivity).inSizeCompatMode();
- mainWindow.mInvGlobalScale = scaling;
-
- mLetterboxedPortraitTaskBounds.set(SCREEN_WIDTH / 4, 0, SCREEN_WIDTH - SCREEN_WIDTH / 4,
- SCREEN_HEIGHT);
-
- final int appWidth = mLetterboxedPortraitTaskBounds.width();
- final int appHeight = mLetterboxedPortraitTaskBounds.height();
-
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
- final Rect crop = letterboxPolicy.getCropBoundsIfNeeded(mainWindow);
- assertNotEquals(null, crop);
- assertEquals(0, crop.left);
- assertEquals(0, crop.top);
- assertEquals((int) (appWidth * scaling), crop.right);
- assertEquals((int) ((appHeight - TASKBAR_EXPANDED_HEIGHT) * scaling), crop.bottom);
- }
-
- @Test
- public void testGetRoundedCornersRadius_withRoundedCornersFromInsets() {
- final float invGlobalScale = 0.5f;
- final int expectedRadius = 7;
- final int configurationRadius = 15;
-
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(/*taskbar=*/ null);
- mainWindow.mInvGlobalScale = invGlobalScale;
- final InsetsState insets = mainWindow.getInsetsState();
-
- RoundedCorners roundedCorners = new RoundedCorners(
- /*topLeft=*/ null,
- /*topRight=*/ null,
- /*bottomRight=*/ new RoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT,
- configurationRadius, /*centerX=*/ 1, /*centerY=*/ 1),
- /*bottomLeft=*/ new RoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT,
- configurationRadius * 2 /*2 is to test selection of the min radius*/,
- /*centerX=*/ 1, /*centerY=*/ 1)
- );
- insets.setRoundedCorners(roundedCorners);
- mAppCompatConfiguration.setLetterboxActivityCornersRadius(-1);
-
- assertEquals(expectedRadius, mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
- .getRoundedCornersRadius(mainWindow));
- }
-
- @Test
- public void testGetRoundedCornersRadius_withLetterboxActivityCornersRadius() {
- final float invGlobalScale = 0.5f;
- final int expectedRadius = 7;
- final int configurationRadius = 15;
-
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(/*taskbar=*/ null);
- mainWindow.mInvGlobalScale = invGlobalScale;
- mAppCompatConfiguration.setLetterboxActivityCornersRadius(configurationRadius);
-
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
-
- doReturn(true).when(mActivity).isInLetterboxAnimation();
- assertEquals(expectedRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
-
- doReturn(false).when(mActivity).isInLetterboxAnimation();
- assertEquals(expectedRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
-
- doReturn(false).when(mActivity).isVisibleRequested();
- doReturn(false).when(mActivity).isVisible();
- assertEquals(0, letterboxPolicy.getRoundedCornersRadius(mainWindow));
-
- doReturn(true).when(mActivity).isInLetterboxAnimation();
- assertEquals(expectedRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
- }
-
- @Test
- public void testGetRoundedCornersRadius_noScalingApplied() {
- final int configurationRadius = 15;
-
- final WindowState mainWindow = mockForGetCropBoundsAndRoundedCorners(/*taskbar=*/ null);
- mAppCompatConfiguration.setLetterboxActivityCornersRadius(configurationRadius);
-
- final AppCompatLetterboxPolicy letterboxPolicy =
- mActivity.mAppCompatController.getAppCompatLetterboxPolicy();
-
- mainWindow.mInvGlobalScale = -1f;
- assertEquals(configurationRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
-
- mainWindow.mInvGlobalScale = 0f;
- assertEquals(configurationRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
-
- mainWindow.mInvGlobalScale = 1f;
- assertEquals(configurationRadius, letterboxPolicy.getRoundedCornersRadius(mainWindow));
- }
-
- private WindowState mockForGetCropBoundsAndRoundedCorners(@Nullable InsetsSource taskbar) {
- final WindowState mainWindow = mock(WindowState.class);
- final InsetsState insets = new InsetsState();
- final Resources resources = mWm.mContext.getResources();
- final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams();
-
- final AppCompatAspectRatioPolicy aspectRatioPolicy = mActivity.mAppCompatController
- .getAppCompatAspectRatioPolicy();
-
- mainWindow.mInvGlobalScale = 1f;
- spyOn(resources);
- spyOn(mActivity);
- spyOn(aspectRatioPolicy);
-
- if (taskbar != null) {
- taskbar.setVisible(true);
- insets.addSource(taskbar);
- }
- doReturn(mLetterboxedPortraitTaskBounds).when(mActivity).getBounds();
- doReturn(false).when(mActivity).isInLetterboxAnimation();
- doReturn(true).when(mActivity).isVisible();
- doReturn(true).when(aspectRatioPolicy)
- .isLetterboxedForFixedOrientationAndAspectRatio();
- doReturn(insets).when(mainWindow).getInsetsState();
- doReturn(attrs).when(mainWindow).getAttrs();
- doReturn(true).when(mainWindow).isDrawn();
- doReturn(true).when(mainWindow).isOnScreen();
- doReturn(false).when(mainWindow).isLetterboxedForDisplayCutout();
- doReturn(true).when(mainWindow).areAppWindowBoundsLetterboxed();
- doReturn(true).when(mAppCompatConfiguration).isLetterboxActivityCornersRounded();
- doReturn(TASKBAR_EXPANDED_HEIGHT).when(resources).getDimensionPixelSize(
- R.dimen.taskbar_frame_height);
-
- return mainWindow;
- }
-
- @Test
- public void testIsLetterboxEducationEnabled() {
- mActivity.mAppCompatController.getAppCompatLetterboxOverrides()
- .isLetterboxEducationEnabled();
- verify(mAppCompatConfiguration).getIsEducationEnabled();
- }
-
- private ActivityRecord setUpActivityWithComponent() {
- mDisplayContent = new TestDisplayContent
- .Builder(mAtm, /* dw */ 1000, /* dh */ 2000).build();
- mTask = new TaskBuilder(mSupervisor).setDisplay(mDisplayContent).build();
- final ActivityRecord activity = new ActivityBuilder(mAtm)
- .setOnTop(true)
- .setTask(mTask)
- // Set the component to be that of the test class in order to enable compat changes
- .setComponent(ComponentName.createRelative(mContext,
- com.android.server.wm.LetterboxUiControllerTest.class.getName()))
- .build();
- spyOn(activity.mAppCompatController.getAppCompatCameraOverrides());
- return activity;
- }
-}