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
This commit is contained in:
Garfield Tan
2018-12-05 11:30:27 -08:00
parent efd355c1c3
commit bb0270fa54
2 changed files with 81 additions and 1 deletions

View File

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

View File

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