Loading services/tests/wmtests/src/com/android/server/wm/AppCompatAspectRatioOverridesTest.java 0 → 100644 +316 −0 Original line number Diff line number Diff line /* * 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.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.junit.Assert.assertEquals; import android.compat.testing.PlatformCompatChangeRule; import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import java.util.function.Consumer; /** * Test class for {@link AppCompatAspectRatioOverrides}. * <p> * Build/Install/Run: * atest WmTests:AppCompatAspectRatioOverridesTest */ @Presubmit @RunWith(WindowTestRunner.class) public class AppCompatAspectRatioOverridesTest extends WindowTestsBase { @Rule public TestRule compatChangeRule = new PlatformCompatChangeRule(); @Test public void testShouldApplyUserFullscreenOverride_trueProperty_returnsFalse() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE); robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ false); robot.activity().createActivityWithComponent(); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_falseFullscreenProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_falseSettingsProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ true); }); } @Test public void testShouldEnableUserAspectRatioSettings_falseProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldEnableUserAspectRatioSettings_trueProperty_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ true); }); } @Test public void testShouldEnableUserAspectRatioSettings_ignoreOrientation_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_falseProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_trueProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldEnableUserAspectRatioSettings(/* enabled */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_disabledIgnoreOrientationRequest() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ false); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ true); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_ignoreOrientation_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_overrideEnabled_returnsTrue() { runTestScenario((robot)-> { robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_propertyTrue_overrideEnabled_returnsTrue() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ true); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_propertyTrue_overrideDisabled_returnsFalse() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_overrideDisabled_returnsFalse() { runTestScenario((robot)-> { robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testshouldOverrideMinAspectRatio_propertyFalse_overrideEnabled_returnsFalse() { runTestScenario((robot)-> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testshouldOverrideMinAspectRatio_propertyFalse_noOverride_returnsFalse() { runTestScenario((robot)-> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ void runTestScenario(@NonNull Consumer<AspectRatioOverridesRobotTest> consumer) { spyOn(mWm.mAppCompatConfiguration); final AspectRatioOverridesRobotTest robot = new AspectRatioOverridesRobotTest(mWm, mAtm, mSupervisor); consumer.accept(robot); } private static class AspectRatioOverridesRobotTest extends AppCompatRobotBase { AspectRatioOverridesRobotTest(@NonNull WindowManagerService wm, @NonNull ActivityTaskManagerService atm, @NonNull ActivityTaskSupervisor supervisor) { super(wm, atm, supervisor); } void checkShouldApplyUserFullscreenOverride(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldApplyUserFullscreenOverride()); } void checkShouldEnableUserAspectRatioSettings(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldEnableUserAspectRatioSettings()); } void checkShouldApplyUserMinAspectRatioOverride(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldApplyUserMinAspectRatioOverride()); } void checkShouldOverrideMinAspectRatio(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldOverrideMinAspectRatio()); } @NonNull private AppCompatAspectRatioOverrides getTopActivityAppCompatAspectRatioOverrides() { return activity().top().mAppCompatController.getAppCompatAspectRatioOverrides(); } } } services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java +89 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.content.pm.ActivityInfo.OVERRIDE_ORIENTATION_ONLY_FOR_CAME import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION; import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH; import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM; Loading @@ -36,6 +37,7 @@ import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; import org.junit.Rule; Loading Loading @@ -286,6 +288,88 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_overrideEnabled_returnsTrue() { runTestScenario((robot) -> { robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideEnabled_returnsTrue() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideEnabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ false); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideDisabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_overrideDisabled_returnsFalse() { runTestScenario((robot) -> { robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyFalse_overrideEnabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyFalse_noOverride_returnsFalse() { runTestScenario((robot) -> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ Loading Loading @@ -323,6 +407,11 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { .shouldApplyFreeformTreatmentForCameraCompat(), expected); } void checkShouldOverrideMinAspectRatioForCamera(boolean expected) { Assert.assertEquals(getAppCompatCameraOverrides() .shouldOverrideMinAspectRatioForCamera(), expected); } void checkIsCameraActive(boolean active) { Assert.assertEquals(getAppCompatCameraOverrides().isCameraActive(), active); } Loading services/tests/wmtests/src/com/android/server/wm/AppCompatComponentPropRobot.java +9 −9 Original line number Diff line number Diff line Loading @@ -32,27 +32,27 @@ import androidx.annotation.NonNull; */ class AppCompatComponentPropRobot { @NonNull private final WindowManagerService mWm; private final PackageManager mPackageManager; AppCompatComponentPropRobot(@NonNull WindowManagerService wm) { mWm = wm; mPackageManager = wm.mContext.getPackageManager(); spyOn(mPackageManager); } void enable(@NonNull String propertyName) { setPropertyValue(propertyName, /* enabled */ true); setPropertyValue(propertyName, "", "", /* enabled */ true); } void disable(@NonNull String propertyName) { setPropertyValue(propertyName, /* enabled */ false); setPropertyValue(propertyName, "", "", /* enabled */ false); } private void setPropertyValue(@NonNull String propertyName, boolean enabled) { private void setPropertyValue(@NonNull String propertyName, @NonNull String packageName, @NonNull String className, boolean enabled) { final PackageManager.Property property = new PackageManager.Property(propertyName, /* value */ enabled, /* packageName */ "", /* className */ ""); final PackageManager pm = mWm.mContext.getPackageManager(); spyOn(pm); /* value */ enabled, packageName, className); try { doReturn(property).when(pm).getProperty(eq(propertyName), anyString()); doReturn(property).when(mPackageManager).getProperty(eq(propertyName), anyString()); } catch (PackageManager.NameNotFoundException e) { fail(e.getLocalizedMessage()); } Loading services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java +0 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,4 @@ class AppCompatConfigurationRobot { doReturn(enabled).when(mAppCompatConfiguration) .isCameraCompatSplitScreenAspectRatioEnabled(); } } services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +0 −317 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/tests/wmtests/src/com/android/server/wm/AppCompatAspectRatioOverridesTest.java 0 → 100644 +316 −0 Original line number Diff line number Diff line /* * 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.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.junit.Assert.assertEquals; import android.compat.testing.PlatformCompatChangeRule; import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import java.util.function.Consumer; /** * Test class for {@link AppCompatAspectRatioOverrides}. * <p> * Build/Install/Run: * atest WmTests:AppCompatAspectRatioOverridesTest */ @Presubmit @RunWith(WindowTestRunner.class) public class AppCompatAspectRatioOverridesTest extends WindowTestsBase { @Rule public TestRule compatChangeRule = new PlatformCompatChangeRule(); @Test public void testShouldApplyUserFullscreenOverride_trueProperty_returnsFalse() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE); robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ false); robot.activity().createActivityWithComponent(); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_falseFullscreenProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_falseSettingsProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ false); }); } @Test public void testShouldApplyUserFullscreenOverride_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioFullscreen(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_FULLSCREEN); robot.checkShouldApplyUserFullscreenOverride(/* expected */ true); }); } @Test public void testShouldEnableUserAspectRatioSettings_falseProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldEnableUserAspectRatioSettings_trueProperty_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ true); }); } @Test public void testShouldEnableUserAspectRatioSettings_ignoreOrientation_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_falseProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.prop().disable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldEnableUserAspectRatioSettings(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_trueProperty_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.prop().enable(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldEnableUserAspectRatioSettings(/* enabled */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_disabledIgnoreOrientationRequest() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ false); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ false); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_returnsTrue() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ true); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ true); }); } @Test public void testShouldApplyUserMinAspectRatioOverride_ignoreOrientation_returnsFalse() { runTestScenario((robot)-> { robot.conf().enableUserAppAspectRatioSettings(/* enabled */ false); robot.activity().setIgnoreOrientationRequest(/* enabled */ true); robot.activity().createActivityWithComponent(); robot.activity().setGetUserMinAspectRatioOverrideCode(USER_MIN_ASPECT_RATIO_3_2); robot.checkShouldApplyUserMinAspectRatioOverride(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_overrideEnabled_returnsTrue() { runTestScenario((robot)-> { robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_propertyTrue_overrideEnabled_returnsTrue() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ true); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_propertyTrue_overrideDisabled_returnsFalse() { runTestScenario((robot)-> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testShouldOverrideMinAspectRatio_overrideDisabled_returnsFalse() { runTestScenario((robot)-> { robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testshouldOverrideMinAspectRatio_propertyFalse_overrideEnabled_returnsFalse() { runTestScenario((robot)-> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO}) public void testshouldOverrideMinAspectRatio_propertyFalse_noOverride_returnsFalse() { runTestScenario((robot)-> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatio(/* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ void runTestScenario(@NonNull Consumer<AspectRatioOverridesRobotTest> consumer) { spyOn(mWm.mAppCompatConfiguration); final AspectRatioOverridesRobotTest robot = new AspectRatioOverridesRobotTest(mWm, mAtm, mSupervisor); consumer.accept(robot); } private static class AspectRatioOverridesRobotTest extends AppCompatRobotBase { AspectRatioOverridesRobotTest(@NonNull WindowManagerService wm, @NonNull ActivityTaskManagerService atm, @NonNull ActivityTaskSupervisor supervisor) { super(wm, atm, supervisor); } void checkShouldApplyUserFullscreenOverride(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldApplyUserFullscreenOverride()); } void checkShouldEnableUserAspectRatioSettings(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldEnableUserAspectRatioSettings()); } void checkShouldApplyUserMinAspectRatioOverride(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldApplyUserMinAspectRatioOverride()); } void checkShouldOverrideMinAspectRatio(boolean expected) { assertEquals(expected, getTopActivityAppCompatAspectRatioOverrides() .shouldOverrideMinAspectRatio()); } @NonNull private AppCompatAspectRatioOverrides getTopActivityAppCompatAspectRatioOverrides() { return activity().top().mAppCompatController.getAppCompatAspectRatioOverrides(); } } }
services/tests/wmtests/src/com/android/server/wm/AppCompatCameraOverridesTest.java +89 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.content.pm.ActivityInfo.OVERRIDE_ORIENTATION_ONLY_FOR_CAME import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION; import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ALLOW_REFRESH; import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.window.flags.Flags.FLAG_CAMERA_COMPAT_FOR_FREEFORM; Loading @@ -36,6 +37,7 @@ import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; import org.junit.Rule; Loading Loading @@ -286,6 +288,88 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_overrideEnabled_returnsTrue() { runTestScenario((robot) -> { robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideEnabled_returnsTrue() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ true); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideEnabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ false); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyTrue_overrideDisabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().enable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_overrideDisabled_returnsFalse() { runTestScenario((robot) -> { robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @EnableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyFalse_overrideEnabled_returnsFalse() { runTestScenario((robot) -> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } @Test @DisableCompatChanges({OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA}) public void shouldOverrideMinAspectRatioForCamera_propertyFalse_noOverride_returnsFalse() { runTestScenario((robot) -> { robot.prop().disable(PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE); robot.activity().createActivityWithComponent(); robot.activity().activateCameraInPolicy(/* isCameraActive */ true); robot.checkShouldOverrideMinAspectRatioForCamera(/* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ Loading Loading @@ -323,6 +407,11 @@ public class AppCompatCameraOverridesTest extends WindowTestsBase { .shouldApplyFreeformTreatmentForCameraCompat(), expected); } void checkShouldOverrideMinAspectRatioForCamera(boolean expected) { Assert.assertEquals(getAppCompatCameraOverrides() .shouldOverrideMinAspectRatioForCamera(), expected); } void checkIsCameraActive(boolean active) { Assert.assertEquals(getAppCompatCameraOverrides().isCameraActive(), active); } Loading
services/tests/wmtests/src/com/android/server/wm/AppCompatComponentPropRobot.java +9 −9 Original line number Diff line number Diff line Loading @@ -32,27 +32,27 @@ import androidx.annotation.NonNull; */ class AppCompatComponentPropRobot { @NonNull private final WindowManagerService mWm; private final PackageManager mPackageManager; AppCompatComponentPropRobot(@NonNull WindowManagerService wm) { mWm = wm; mPackageManager = wm.mContext.getPackageManager(); spyOn(mPackageManager); } void enable(@NonNull String propertyName) { setPropertyValue(propertyName, /* enabled */ true); setPropertyValue(propertyName, "", "", /* enabled */ true); } void disable(@NonNull String propertyName) { setPropertyValue(propertyName, /* enabled */ false); setPropertyValue(propertyName, "", "", /* enabled */ false); } private void setPropertyValue(@NonNull String propertyName, boolean enabled) { private void setPropertyValue(@NonNull String propertyName, @NonNull String packageName, @NonNull String className, boolean enabled) { final PackageManager.Property property = new PackageManager.Property(propertyName, /* value */ enabled, /* packageName */ "", /* className */ ""); final PackageManager pm = mWm.mContext.getPackageManager(); spyOn(pm); /* value */ enabled, packageName, className); try { doReturn(property).when(pm).getProperty(eq(propertyName), anyString()); doReturn(property).when(mPackageManager).getProperty(eq(propertyName), anyString()); } catch (PackageManager.NameNotFoundException e) { fail(e.getLocalizedMessage()); } Loading
services/tests/wmtests/src/com/android/server/wm/AppCompatConfigurationRobot.java +0 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,4 @@ class AppCompatConfigurationRobot { doReturn(enabled).when(mAppCompatConfiguration) .isCameraCompatSplitScreenAspectRatioEnabled(); } }
services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +0 −317 File changed.Preview size limit exceeded, changes collapsed. Show changes