Merge "Do not set orientation to requested configuration" into rvc-dev

This commit is contained in:
Riddle Hsu
2020-06-02 05:35:15 +00:00
committed by Android (Google) Code Review
3 changed files with 29 additions and 9 deletions

View File

@@ -1165,15 +1165,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);
}
}

View File

@@ -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;
@@ -294,6 +295,27 @@ public class AppWindowTokenTests extends WindowTestsBase {
mWm.mDisplayFrozen = false;
}
@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);

View File

@@ -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);