Loading services/core/java/com/android/server/wm/ActivityRecord.java +4 −2 Original line number Diff line number Diff line Loading @@ -8293,7 +8293,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A */ @Override protected int getOverrideOrientation() { return mLetterboxUiController.overrideOrientationIfNeeded(super.getOverrideOrientation()); return mAppCompatController.getOrientationPolicy() .overrideOrientationIfNeeded(super.getOverrideOrientation()); } /** Loading Loading @@ -10825,7 +10826,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A proto.write(SHOULD_OVERRIDE_MIN_ASPECT_RATIO, mLetterboxUiController.shouldOverrideMinAspectRatio()); proto.write(SHOULD_IGNORE_ORIENTATION_REQUEST_LOOP, mLetterboxUiController.shouldIgnoreOrientationRequestLoop()); mAppCompatController.getAppCompatCapability().getAppCompatOrientationCapability() .shouldIgnoreOrientationRequestLoop()); proto.write(SHOULD_OVERRIDE_FORCE_RESIZE_APP, mLetterboxUiController.shouldOverrideForceResizeApp()); proto.write(SHOULD_ENABLE_USER_ASPECT_RATIO_SETTINGS, Loading services/core/java/com/android/server/wm/LetterboxUiController.java +0 −28 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager.TaskDescription; import android.app.CameraCompatTaskInfo.FreeformCameraCompatMode; import android.content.pm.ActivityInfo.ScreenOrientation; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; Loading Loading @@ -151,27 +150,6 @@ final class LetterboxUiController { } } /** * Whether an app is calling {@link android.app.Activity#setRequestedOrientation} * in a loop and orientation request should be ignored. * * <p>This should only be called once in response to * {@link android.app.Activity#setRequestedOrientation}. See * {@link #shouldIgnoreRequestedOrientation} for more details. * * <p>This treatment is enabled when the following conditions are met: * <ul> * <li>Flag gating the treatment is enabled * <li>Opt-out component property isn't enabled * <li>Per-app override is enabled * <li>App has requested orientation more than 2 times within 1-second * timer and activity is not letterboxed for fixed orientation * </ul> */ boolean shouldIgnoreOrientationRequestLoop() { return getAppCompatCapability().getAppCompatOrientationCapability() .shouldIgnoreOrientationRequestLoop(); } @VisibleForTesting int getSetOrientationRequestCounter() { Loading Loading @@ -299,12 +277,6 @@ final class LetterboxUiController { return getAppCompatCapability().shouldUseDisplayLandscapeNaturalOrientation(); } @ScreenOrientation int overrideOrientationIfNeeded(@ScreenOrientation int candidate) { return mActivityRecord.mAppCompatController.getOrientationPolicy() .overrideOrientationIfNeeded(candidate); } boolean isOverrideOrientationOnlyForCameraEnabled() { return getAppCompatCapability().isOverrideOrientationOnlyForCameraEnabled(); } Loading services/tests/wmtests/src/com/android/server/wm/AppCompatOrientationPolicyTest.java 0 → 100644 +570 −0 File added.Preview size limit exceeded, changes collapsed. Show changes services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +0 −336 Original line number Diff line number Diff line Loading @@ -18,27 +18,14 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP; import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_FAKE_FOCUS; import static android.content.pm.ActivityInfo.OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA; import static android.content.pm.ActivityInfo.OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA; import static android.content.pm.ActivityInfo.OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR; import static android.content.pm.ActivityInfo.OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT; import static android.content.pm.ActivityInfo.OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; 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.content.res.Configuration.ORIENTATION_LANDSCAPE; Loading @@ -49,7 +36,6 @@ 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_DISPLAY_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES; 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; Loading Loading @@ -535,322 +521,6 @@ public class LetterboxUiControllerTest extends WindowTestsBase { return mainWindow; } // overrideOrientationIfNeeded @Test public void testOverrideOrientationIfNeeded_mapInvokedOnRequest() throws Exception { mController = new LetterboxUiController(mWm, mActivity); spyOn(mWm); mController.overrideOrientationIfNeeded(SCREEN_ORIENTATION_PORTRAIT); verify(mWm).mapOrientationRequest(SCREEN_ORIENTATION_PORTRAIT); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUser() throws Exception { mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_optOut_returnsUnchanged() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrides_optOutSystem_returnsUser() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); prepareActivityThatShouldApplyUserFullscreenOverride(); // fullscreen override still applied assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrides_optOutUser_returnsUser() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, /* value */ false); prepareActivityThatShouldApplyUserFullscreenOverride(); // fullscreen override still applied assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUnchanged() throws Exception { mDisplayContent.setIgnoreOrientationRequest(false); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenAndUserOverrideEnabled_returnsUnchanged() throws Exception { doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioSettingsEnabled(); mActivity = setUpActivityWithComponent(); spyOn(mActivity.mLetterboxUiController); doReturn(USER_MIN_ASPECT_RATIO_3_2).when(mActivity.mLetterboxUiController) .getUserMinAspectRatioOverrideCode(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_portraitOverrideEnabled_returnsPortrait() throws Exception { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR}) public void testOverrideOrientationIfNeeded_portraitOverrideEnabled_returnsNosensor() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR}) public void testOverrideOrientationIfNeeded_nosensorOverride_orientationFixed_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE}) public void testOverrideOrientationIfNeeded_reverseLandscapeOverride_orientationPortraitOrUndefined_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE}) public void testOverrideOrientationIfNeeded_reverseLandscapeOverride_orientationLandscape_returnsReverseLandscape() { assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_LANDSCAPE)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_portraitOverride_orientationFixed_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_NOSENSOR)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_portraitAndIgnoreFixedOverrides_returnsPortrait() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_NOSENSOR)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_noSensorAndIgnoreFixedOverrides_returnsNosensor() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_propertyIsFalse_returnsUnchanged() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA}) public void testOverrideOrientationIfNeeded_whenCameraNotActive_returnsUnchanged() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(false).when(mDisplayContent.mDisplayRotationCompatPolicy) .isActivityEligibleForOrientationOverride(eq(mActivity)); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA}) public void testOverrideOrientationIfNeeded_whenCameraActive_returnsPortrait() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isActivityEligibleForOrientationOverride(eq(mActivity)); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_returnsUser() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mActivity.mAppCompatController .getOrientationPolicy() .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_cameraActivity_noChange() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isCameraActive(mActivity, /* mustBeFullscreen= */ true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_systemFullscreenOverride_cameraActivity_noChange() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mController); doReturn(true).when(mController).isSystemOverrideToFullscreenEnabled(); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isCameraActive(mActivity, /* mustBeFullscreen= */ true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_respectOrientationRequestOverUserFullScreen() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(false); assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_userFullScreenOverrideOverSystem_returnsUser() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mActivity.mAppCompatController .getOrientationPolicy() .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_respectOrientationReqOverUserFullScreenAndSystem() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(false); assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_userFullScreenOverrideDisabled_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_userAspectRatioApplied_unspecifiedOverridden() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserMinAspectRatioOverride(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_LOCKED)); // unchanged if orientation is specified assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_LANDSCAPE)); } @Test public void testOverrideOrientationIfNeeded_userAspectRatioNotApplied_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserMinAspectRatioOverride(); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } // shouldApplyUser...Override @Test public void testShouldApplyUserFullscreenOverride_trueProperty_returnsFalse() throws Exception { Loading Loading @@ -1528,12 +1198,6 @@ public class LetterboxUiControllerTest extends WindowTestsBase { mDisplayContent.setIgnoreOrientationRequest(true); } private void prepareActivityThatShouldIgnoreRequestedOrientationDuringRelaunch() { doReturn(true).when(mLetterboxConfiguration) .isPolicyForIgnoringRequestedOrientationEnabled(); mController.setRelaunchingAfterRequestedOrientationChanged(true); } private ActivityRecord setUpActivityWithComponent() { mDisplayContent = new TestDisplayContent .Builder(mAtm, /* dw */ 1000, /* dh */ 2000).build(); Loading Loading
services/core/java/com/android/server/wm/ActivityRecord.java +4 −2 Original line number Diff line number Diff line Loading @@ -8293,7 +8293,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A */ @Override protected int getOverrideOrientation() { return mLetterboxUiController.overrideOrientationIfNeeded(super.getOverrideOrientation()); return mAppCompatController.getOrientationPolicy() .overrideOrientationIfNeeded(super.getOverrideOrientation()); } /** Loading Loading @@ -10825,7 +10826,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A proto.write(SHOULD_OVERRIDE_MIN_ASPECT_RATIO, mLetterboxUiController.shouldOverrideMinAspectRatio()); proto.write(SHOULD_IGNORE_ORIENTATION_REQUEST_LOOP, mLetterboxUiController.shouldIgnoreOrientationRequestLoop()); mAppCompatController.getAppCompatCapability().getAppCompatOrientationCapability() .shouldIgnoreOrientationRequestLoop()); proto.write(SHOULD_OVERRIDE_FORCE_RESIZE_APP, mLetterboxUiController.shouldOverrideForceResizeApp()); proto.write(SHOULD_ENABLE_USER_ASPECT_RATIO_SETTINGS, Loading
services/core/java/com/android/server/wm/LetterboxUiController.java +0 −28 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager.TaskDescription; import android.app.CameraCompatTaskInfo.FreeformCameraCompatMode; import android.content.pm.ActivityInfo.ScreenOrientation; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; Loading Loading @@ -151,27 +150,6 @@ final class LetterboxUiController { } } /** * Whether an app is calling {@link android.app.Activity#setRequestedOrientation} * in a loop and orientation request should be ignored. * * <p>This should only be called once in response to * {@link android.app.Activity#setRequestedOrientation}. See * {@link #shouldIgnoreRequestedOrientation} for more details. * * <p>This treatment is enabled when the following conditions are met: * <ul> * <li>Flag gating the treatment is enabled * <li>Opt-out component property isn't enabled * <li>Per-app override is enabled * <li>App has requested orientation more than 2 times within 1-second * timer and activity is not letterboxed for fixed orientation * </ul> */ boolean shouldIgnoreOrientationRequestLoop() { return getAppCompatCapability().getAppCompatOrientationCapability() .shouldIgnoreOrientationRequestLoop(); } @VisibleForTesting int getSetOrientationRequestCounter() { Loading Loading @@ -299,12 +277,6 @@ final class LetterboxUiController { return getAppCompatCapability().shouldUseDisplayLandscapeNaturalOrientation(); } @ScreenOrientation int overrideOrientationIfNeeded(@ScreenOrientation int candidate) { return mActivityRecord.mAppCompatController.getOrientationPolicy() .overrideOrientationIfNeeded(candidate); } boolean isOverrideOrientationOnlyForCameraEnabled() { return getAppCompatCapability().isOverrideOrientationOnlyForCameraEnabled(); } Loading
services/tests/wmtests/src/com/android/server/wm/AppCompatOrientationPolicyTest.java 0 → 100644 +570 −0 File added.Preview size limit exceeded, changes collapsed. Show changes
services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +0 −336 Original line number Diff line number Diff line Loading @@ -18,27 +18,14 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.FORCE_NON_RESIZE_APP; import static android.content.pm.ActivityInfo.FORCE_RESIZE_APP; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION_TO_USER; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FORCE_ROTATION; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_REFRESH; import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_ENABLE_REFRESH_VIA_PAUSE; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_FAKE_FOCUS; import static android.content.pm.ActivityInfo.OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO; import static android.content.pm.ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_ONLY_FOR_CAMERA; import static android.content.pm.ActivityInfo.OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA; import static android.content.pm.ActivityInfo.OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR; import static android.content.pm.ActivityInfo.OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT; import static android.content.pm.ActivityInfo.OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; 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.content.res.Configuration.ORIENTATION_LANDSCAPE; Loading @@ -49,7 +36,6 @@ 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_DISPLAY_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_MIN_ASPECT_RATIO_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES; 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; Loading Loading @@ -535,322 +521,6 @@ public class LetterboxUiControllerTest extends WindowTestsBase { return mainWindow; } // overrideOrientationIfNeeded @Test public void testOverrideOrientationIfNeeded_mapInvokedOnRequest() throws Exception { mController = new LetterboxUiController(mWm, mActivity); spyOn(mWm); mController.overrideOrientationIfNeeded(SCREEN_ORIENTATION_PORTRAIT); verify(mWm).mapOrientationRequest(SCREEN_ORIENTATION_PORTRAIT); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUser() throws Exception { mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_optOut_returnsUnchanged() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrides_optOutSystem_returnsUser() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); prepareActivityThatShouldApplyUserFullscreenOverride(); // fullscreen override still applied assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrides_optOutUser_returnsUser() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE, /* value */ false); prepareActivityThatShouldApplyUserFullscreenOverride(); // fullscreen override still applied assertEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenOverrideEnabled_returnsUnchanged() throws Exception { mDisplayContent.setIgnoreOrientationRequest(false); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_ANY_ORIENTATION_TO_USER}) public void testOverrideOrientationIfNeeded_fullscreenAndUserOverrideEnabled_returnsUnchanged() throws Exception { doReturn(true).when(mLetterboxConfiguration).isUserAppAspectRatioSettingsEnabled(); mActivity = setUpActivityWithComponent(); spyOn(mActivity.mLetterboxUiController); doReturn(USER_MIN_ASPECT_RATIO_3_2).when(mActivity.mLetterboxUiController) .getUserMinAspectRatioOverrideCode(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_portraitOverrideEnabled_returnsPortrait() throws Exception { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR}) public void testOverrideOrientationIfNeeded_portraitOverrideEnabled_returnsNosensor() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR}) public void testOverrideOrientationIfNeeded_nosensorOverride_orientationFixed_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE}) public void testOverrideOrientationIfNeeded_reverseLandscapeOverride_orientationPortraitOrUndefined_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_LANDSCAPE_ORIENTATION_TO_REVERSE_LANDSCAPE}) public void testOverrideOrientationIfNeeded_reverseLandscapeOverride_orientationLandscape_returnsReverseLandscape() { assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_LANDSCAPE)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_portraitOverride_orientationFixed_returnsUnchanged() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_NOSENSOR)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_portraitAndIgnoreFixedOverrides_returnsPortrait() { assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_NOSENSOR)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_NOSENSOR, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_noSensorAndIgnoreFixedOverrides_returnsNosensor() { assertEquals(SCREEN_ORIENTATION_NOSENSOR, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT}) public void testOverrideOrientationIfNeeded_propertyIsFalse_returnsUnchanged() throws Exception { mockThatProperty(PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE, /* value */ false); mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA}) public void testOverrideOrientationIfNeeded_whenCameraNotActive_returnsUnchanged() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(false).when(mDisplayContent.mDisplayRotationCompatPolicy) .isActivityEligibleForOrientationOverride(eq(mActivity)); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ORIENTATION_ONLY_FOR_CAMERA}) public void testOverrideOrientationIfNeeded_whenCameraActive_returnsPortrait() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isActivityEligibleForOrientationOverride(eq(mActivity)); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_returnsUser() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mActivity.mAppCompatController .getOrientationPolicy() .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_cameraActivity_noChange() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isCameraActive(mActivity, /* mustBeFullscreen= */ true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_systemFullscreenOverride_cameraActivity_noChange() { doReturn(true).when(mLetterboxConfiguration).isCameraCompatTreatmentEnabled(); doReturn(true).when(mLetterboxConfiguration) .isCameraCompatTreatmentEnabledAtBuildTime(); // Recreate DisplayContent with DisplayRotationCompatPolicy mActivity = setUpActivityWithComponent(); mController = new LetterboxUiController(mWm, mActivity); spyOn(mController); doReturn(true).when(mController).isSystemOverrideToFullscreenEnabled(); spyOn(mDisplayContent.mDisplayRotationCompatPolicy); doReturn(true).when(mDisplayContent.mDisplayRotationCompatPolicy) .isCameraActive(mActivity, /* mustBeFullscreen= */ true); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_respectOrientationRequestOverUserFullScreen() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(false); assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_userFullScreenOverrideOverSystem_returnsUser() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(true); assertEquals(SCREEN_ORIENTATION_USER, mActivity.mAppCompatController .getOrientationPolicy() .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_respectOrientationReqOverUserFullScreenAndSystem() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); mDisplayContent.setIgnoreOrientationRequest(false); assertNotEquals(SCREEN_ORIENTATION_USER, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_userFullScreenOverrideDisabled_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT)); } @Test public void testOverrideOrientationIfNeeded_userAspectRatioApplied_unspecifiedOverridden() { spyOn(mActivity.mLetterboxUiController); doReturn(true).when(mActivity.mLetterboxUiController) .shouldApplyUserMinAspectRatioOverride(); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); assertEquals(SCREEN_ORIENTATION_PORTRAIT, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_LOCKED)); // unchanged if orientation is specified assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.mLetterboxUiController .overrideOrientationIfNeeded(/* candidate */ SCREEN_ORIENTATION_LANDSCAPE)); } @Test public void testOverrideOrientationIfNeeded_userAspectRatioNotApplied_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserMinAspectRatioOverride(); assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED)); } // shouldApplyUser...Override @Test public void testShouldApplyUserFullscreenOverride_trueProperty_returnsFalse() throws Exception { Loading Loading @@ -1528,12 +1198,6 @@ public class LetterboxUiControllerTest extends WindowTestsBase { mDisplayContent.setIgnoreOrientationRequest(true); } private void prepareActivityThatShouldIgnoreRequestedOrientationDuringRelaunch() { doReturn(true).when(mLetterboxConfiguration) .isPolicyForIgnoringRequestedOrientationEnabled(); mController.setRelaunchingAfterRequestedOrientationChanged(true); } private ActivityRecord setUpActivityWithComponent() { mDisplayContent = new TestDisplayContent .Builder(mAtm, /* dw */ 1000, /* dh */ 2000).build(); Loading