From bb0270fa54ffa480e9ea6b9b6fc2539b7cebe624 Mon Sep 17 00:00:00 2001 From: Garfield Tan Date: Wed, 5 Dec 2018 11:30:27 -0800 Subject: [PATCH] Convert orientation constants before further resolution. Orientation constant in Configuration is different from those in ActivityInfo, so convert them before using it. Fixes: 120481263 Test: Manual test & atest WmTests:TaskLaunchParamsModifierTests Change-Id: I2fb65e4adf2714699d450f174f8c2660701b3431 --- .../server/wm/TaskLaunchParamsModifier.java | 15 ++++- .../wm/TaskLaunchParamsModifierTests.java | 67 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java index 4ae2a79e2697a..1fb7979fa3e29 100644 --- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java +++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java @@ -44,6 +44,7 @@ import android.app.ActivityOptions; import android.app.WindowConfiguration; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; +import android.content.res.Configuration; import android.graphics.Rect; import android.os.Build; import android.util.Slog; @@ -526,12 +527,24 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier { adjustBoundsToAvoidConflict(display, inOutBounds); } + private int convertOrientationToScreenOrientation(int orientation) { + switch (orientation) { + case Configuration.ORIENTATION_LANDSCAPE: + return SCREEN_ORIENTATION_LANDSCAPE; + case Configuration.ORIENTATION_PORTRAIT: + return SCREEN_ORIENTATION_PORTRAIT; + default: + return SCREEN_ORIENTATION_UNSPECIFIED; + } + } + private int resolveOrientation(@NonNull ActivityRecord root, @NonNull ActivityDisplay display, @NonNull Rect bounds) { int orientation = resolveOrientation(root); if (orientation == SCREEN_ORIENTATION_LOCKED) { - orientation = bounds.isEmpty() ? display.getConfiguration().orientation + orientation = bounds.isEmpty() + ? convertOrientationToScreenOrientation(display.getConfiguration().orientation) : orientationFromBounds(bounds); if (DEBUG) { appendLog(bounds.isEmpty() ? "locked-orientation-from-display=" + orientation diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java index 9569c0d5affa2..105f8260022fa 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java @@ -22,7 +22,10 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; +import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; +import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; +import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.util.DisplayMetrics.DENSITY_DEFAULT; import static android.view.Display.DEFAULT_DISPLAY; @@ -749,6 +752,64 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase { assertEquals(new Rect(0, 0, 200, 100), mResult.mBounds); } + @Test + public void testUsesDisplayOrientationForNoSensorOrientation() { + final TestActivityDisplay freeformDisplay = createNewActivityDisplay( + WINDOWING_MODE_FREEFORM); + + final ActivityOptions options = ActivityOptions.makeBasic(); + options.setLaunchDisplayId(freeformDisplay.mDisplayId); + options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM); + + mActivity.info.screenOrientation = SCREEN_ORIENTATION_NOSENSOR; + + assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null, + mActivity, /* source */ null, options, mCurrent, mResult)); + + final int orientationForDisplay = orientationFromBounds(freeformDisplay.getBounds()); + final int orientationForTask = orientationFromBounds(mResult.mBounds); + assertEquals("Launch bounds orientation should be the same as the display, but" + + " display orientation is " + + ActivityInfo.screenOrientationToString(orientationForDisplay) + + " launch bounds orientation is " + + ActivityInfo.screenOrientationToString(orientationForTask), + orientationForDisplay, orientationForTask); + } + + @Test + public void testRespectsAppRequestedOrientation_Landscape() { + final TestActivityDisplay freeformDisplay = createNewActivityDisplay( + WINDOWING_MODE_FREEFORM); + + final ActivityOptions options = ActivityOptions.makeBasic(); + options.setLaunchDisplayId(freeformDisplay.mDisplayId); + options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM); + + mActivity.info.screenOrientation = SCREEN_ORIENTATION_LANDSCAPE; + + assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null, + mActivity, /* source */ null, options, mCurrent, mResult)); + + assertEquals(SCREEN_ORIENTATION_LANDSCAPE, orientationFromBounds(mResult.mBounds)); + } + + @Test + public void testRespectsAppRequestedOrientation_Portrait() { + final TestActivityDisplay freeformDisplay = createNewActivityDisplay( + WINDOWING_MODE_FREEFORM); + + final ActivityOptions options = ActivityOptions.makeBasic(); + options.setLaunchDisplayId(freeformDisplay.mDisplayId); + options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM); + + mActivity.info.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; + + assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null, + mActivity, /* source */ null, options, mCurrent, mResult)); + + assertEquals(SCREEN_ORIENTATION_PORTRAIT, orientationFromBounds(mResult.mBounds)); + } + @Test public void testDefaultSizeSmallerThanBigScreen() { final TestActivityDisplay freeformDisplay = createNewActivityDisplay( @@ -1090,6 +1151,7 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase { display.setWindowingMode(windowingMode); display.setBounds(/* left */ 0, /* top */ 0, /* right */ 1920, /* bottom */ 1080); display.getConfiguration().densityDpi = DENSITY_DEFAULT; + display.getConfiguration().orientation = ORIENTATION_LANDSCAPE; return display; } @@ -1115,6 +1177,11 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase { } } + private int orientationFromBounds(Rect bounds) { + return bounds.width() > bounds.height() ? SCREEN_ORIENTATION_LANDSCAPE + : SCREEN_ORIENTATION_PORTRAIT; + } + private static class WindowLayoutBuilder { private int mWidth = -1; private int mHeight = -1;