diff options
3 files changed, 29 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index a1fbb597533f..69a191741569 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -1152,15 +1152,12 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< } mOrientation = orientation; - final int configOrientation = getRequestedConfigurationOrientation(); - if (getRequestedOverrideConfiguration().orientation != configOrientation) { - mTmpConfig.setTo(getRequestedOverrideConfiguration()); - mTmpConfig.orientation = configOrientation; - onRequestedOverrideConfigurationChanged(mTmpConfig); - } - final WindowContainer parent = getParent(); if (parent != null) { + if (getConfiguration().orientation != getRequestedConfigurationOrientation()) { + // Resolve the requested orientation. + onConfigurationChanged(parent.getConfiguration()); + } onDescendantOrientationChanged(freezeDisplayToken, requestingContainer); } } diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java index 36d4888fa56e..02de408343c5 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java @@ -21,6 +21,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; +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_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; @@ -295,6 +296,27 @@ public class AppWindowTokenTests extends WindowTestsBase { } @Test + public void testRespectTopFullscreenOrientation() { + final Configuration displayConfig = mActivity.mDisplayContent.getConfiguration(); + final Configuration activityConfig = mActivity.getConfiguration(); + mActivity.setOrientation(SCREEN_ORIENTATION_PORTRAIT); + + assertEquals(Configuration.ORIENTATION_PORTRAIT, displayConfig.orientation); + assertEquals(Configuration.ORIENTATION_PORTRAIT, activityConfig.orientation); + + final ActivityRecord topActivity = WindowTestUtils.createTestActivityRecord(mStack); + topActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); + + assertEquals(Configuration.ORIENTATION_LANDSCAPE, displayConfig.orientation); + // Although the activity requested portrait, it is not the top activity that determines + // the display orientation. So it should be able to inherit the orientation from parent. + // Otherwise its configuration will be inconsistent that its orientation is portrait but + // other screen configurations are in landscape, e.g. screenWidthDp, screenHeightDp, and + // window configuration. + assertEquals(Configuration.ORIENTATION_LANDSCAPE, activityConfig.orientation); + } + + @Test public void testReportOrientationChange() { mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 68bc58493f13..665cf83cd33c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -145,7 +145,8 @@ public class SizeCompatTests extends ActivityTestsBase { final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds(); // The parent configuration doesn't change since the first resolved configuration, so the - // activity should fit in the parent naturally. (size=583x700). + // activity should fit in the parent naturally (size=583x700, appBounds=[9, 100 - 592, 800], + // horizontal offset = round((600 - 583) / 2) = 9)). assertFitted(); final int offsetX = (int) ((1f + displayBounds.width() - appBounds.width()) / 2); // The bounds must be horizontal centered. @@ -160,7 +161,7 @@ public class SizeCompatTests extends ActivityTestsBase { assertFitted(); // After the orientation of activity is changed, even display is not rotated, the aspect - // ratio should be the same (appBounds=[9, 100 - 592, 800], x-offset=round((600-583)/2)=9). + // ratio should be the same (bounds=[0, 0 - 600, 600], appBounds=[0, 100 - 600, 600]). assertEquals(appBounds.width(), appBounds.height() * aspectRatio, 0.5f /* delta */); // The notch is still on top. assertEquals(mActivity.getBounds().height(), appBounds.height() + notchHeight); |