Loading services/core/java/com/android/server/wm/LetterboxUiController.java +33 −9 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ 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.ActivityInfo.isFixedOrientation; import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; import static android.content.pm.ActivityInfo.screenOrientationToString; Loading @@ -44,6 +45,7 @@ import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; Loading Loading @@ -642,6 +644,10 @@ final class LetterboxUiController { @ScreenOrientation int overrideOrientationIfNeeded(@ScreenOrientation int candidate) { if (shouldApplyUserFullscreenOverride()) { return SCREEN_ORIENTATION_USER; } // In some cases (e.g. Kids app) we need to map the candidate orientation to some other // orientation. candidate = mActivityRecord.mWmService.mapOrientationRequest(candidate); Loading Loading @@ -1103,20 +1109,28 @@ final class LetterboxUiController { } boolean shouldApplyUserMinAspectRatioOverride() { if (!mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()) { if (!mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled() || mActivityRecord.mDisplayContent == null || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) { return false; } try { final int userAspectRatio = mActivityRecord.mAtmService.getPackageManager() .getUserMinAspectRatio(mActivityRecord.packageName, mActivityRecord.mUserId); mUserAspectRatio = userAspectRatio; return userAspectRatio != USER_MIN_ASPECT_RATIO_UNSET; } catch (RemoteException e) { // Don't apply user aspect ratio override Slog.w(TAG, "Exception thrown retrieving aspect ratio user override " + this, e); mUserAspectRatio = getUserMinAspectRatioOverrideCode(); return mUserAspectRatio != USER_MIN_ASPECT_RATIO_UNSET && mUserAspectRatio != USER_MIN_ASPECT_RATIO_FULLSCREEN; } boolean shouldApplyUserFullscreenOverride() { if (!mLetterboxConfiguration.isUserAppAspectRatioFullscreenEnabled() || mActivityRecord.mDisplayContent == null || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) { return false; } mUserAspectRatio = getUserMinAspectRatioOverrideCode(); return mUserAspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN; } float getUserMinAspectRatio() { Loading @@ -1137,6 +1151,16 @@ final class LetterboxUiController { } } private int getUserMinAspectRatioOverrideCode() { try { return mActivityRecord.mAtmService.getPackageManager() .getUserMinAspectRatio(mActivityRecord.packageName, mActivityRecord.mUserId); } catch (RemoteException e) { Slog.w(TAG, "Exception thrown retrieving aspect ratio user override " + this, e); } return mUserAspectRatio; } private float getDisplaySizeMinAspectRatio() { final DisplayArea displayArea = mActivityRecord.getDisplayArea(); if (displayArea == null) { Loading services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ 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.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER; Loading Loading @@ -778,6 +779,34 @@ public class LetterboxUiControllerTest extends WindowTestsBase { /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED), SCREEN_ORIENTATION_PORTRAIT); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_returnsUser() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED), SCREEN_ORIENTATION_USER); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_userFullScreenOverrideOverSystem_returnsUser() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT), SCREEN_ORIENTATION_USER); } @Test public void testOverrideOrientationIfNeeded_userFullScreenOverrideDisabled_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT), SCREEN_ORIENTATION_PORTRAIT); } // shouldUseDisplayLandscapeNaturalOrientation @Test Loading Loading
services/core/java/com/android/server/wm/LetterboxUiController.java +33 −9 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ 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.ActivityInfo.isFixedOrientation; import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; import static android.content.pm.ActivityInfo.screenOrientationToString; Loading @@ -44,6 +45,7 @@ import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_16_9; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_3_2; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_4_3; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_DISPLAY_SIZE; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN; import static android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; Loading Loading @@ -642,6 +644,10 @@ final class LetterboxUiController { @ScreenOrientation int overrideOrientationIfNeeded(@ScreenOrientation int candidate) { if (shouldApplyUserFullscreenOverride()) { return SCREEN_ORIENTATION_USER; } // In some cases (e.g. Kids app) we need to map the candidate orientation to some other // orientation. candidate = mActivityRecord.mWmService.mapOrientationRequest(candidate); Loading Loading @@ -1103,20 +1109,28 @@ final class LetterboxUiController { } boolean shouldApplyUserMinAspectRatioOverride() { if (!mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled()) { if (!mLetterboxConfiguration.isUserAppAspectRatioSettingsEnabled() || mActivityRecord.mDisplayContent == null || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) { return false; } try { final int userAspectRatio = mActivityRecord.mAtmService.getPackageManager() .getUserMinAspectRatio(mActivityRecord.packageName, mActivityRecord.mUserId); mUserAspectRatio = userAspectRatio; return userAspectRatio != USER_MIN_ASPECT_RATIO_UNSET; } catch (RemoteException e) { // Don't apply user aspect ratio override Slog.w(TAG, "Exception thrown retrieving aspect ratio user override " + this, e); mUserAspectRatio = getUserMinAspectRatioOverrideCode(); return mUserAspectRatio != USER_MIN_ASPECT_RATIO_UNSET && mUserAspectRatio != USER_MIN_ASPECT_RATIO_FULLSCREEN; } boolean shouldApplyUserFullscreenOverride() { if (!mLetterboxConfiguration.isUserAppAspectRatioFullscreenEnabled() || mActivityRecord.mDisplayContent == null || !mActivityRecord.mDisplayContent.getIgnoreOrientationRequest()) { return false; } mUserAspectRatio = getUserMinAspectRatioOverrideCode(); return mUserAspectRatio == USER_MIN_ASPECT_RATIO_FULLSCREEN; } float getUserMinAspectRatio() { Loading @@ -1137,6 +1151,16 @@ final class LetterboxUiController { } } private int getUserMinAspectRatioOverrideCode() { try { return mActivityRecord.mAtmService.getPackageManager() .getUserMinAspectRatio(mActivityRecord.packageName, mActivityRecord.mUserId); } catch (RemoteException e) { Slog.w(TAG, "Exception thrown retrieving aspect ratio user override " + this, e); } return mUserAspectRatio; } private float getDisplaySizeMinAspectRatio() { final DisplayArea displayArea = mActivityRecord.getDisplayArea(); if (displayArea == null) { Loading
services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ 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.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER; Loading Loading @@ -778,6 +779,34 @@ public class LetterboxUiControllerTest extends WindowTestsBase { /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED), SCREEN_ORIENTATION_PORTRAIT); } @Test public void testOverrideOrientationIfNeeded_userFullscreenOverride_returnsUser() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_UNSPECIFIED), SCREEN_ORIENTATION_USER); } @Test @EnableCompatChanges({OVERRIDE_UNDEFINED_ORIENTATION_TO_PORTRAIT, OVERRIDE_ANY_ORIENTATION}) public void testOverrideOrientationIfNeeded_userFullScreenOverrideOverSystem_returnsUser() { spyOn(mController); doReturn(true).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT), SCREEN_ORIENTATION_USER); } @Test public void testOverrideOrientationIfNeeded_userFullScreenOverrideDisabled_returnsUnchanged() { spyOn(mController); doReturn(false).when(mController).shouldApplyUserFullscreenOverride(); assertEquals(mController.overrideOrientationIfNeeded( /* candidate */ SCREEN_ORIENTATION_PORTRAIT), SCREEN_ORIENTATION_PORTRAIT); } // shouldUseDisplayLandscapeNaturalOrientation @Test Loading