diff options
| author | 2019-11-19 11:34:27 -0800 | |
|---|---|---|
| committer | 2019-12-20 13:50:37 -0800 | |
| commit | 966c041b7f7cb5ff386ff7ff7f56fdf28bc84168 (patch) | |
| tree | 3b3eb14b38d97261f1f71a76a27be04b2f3ef65a | |
| parent | 6c9b1f8f8597fc6075dbe502b479c8317873c4c4 (diff) | |
Use tasks' orientation in multi-window activities
Multi-window spec say bounds aren't affected by activity changing
their requested orientation after initial launch. Therefore we shouldn't
pass their requested orientation to them in those cases.
Bug: 145556374
Test: Activities that request different orientations won't get
configurations that don't match their bounds.
Test: ActivityRecordTests
Change-Id: I7fdec464805633b8595a0c18adf8bc54112c7f66
| -rw-r--r-- | services/core/java/com/android/server/wm/ActivityRecord.java | 5 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java | 61 |
2 files changed, 66 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index bfc626828fa0..94975bb626ba 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6304,6 +6304,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A resolveSizeCompatModeConfiguration(newParentConfiguration); } else { super.resolveOverrideConfiguration(newParentConfiguration); + // We ignore activities' requested orientation in multi-window modes. Task level may + // take them into consideration when calculating bounds. + if (getParent() != null && getParent().inMultiWindowMode()) { + resolvedConfig.orientation = Configuration.ORIENTATION_UNDEFINED; + } applyAspectRatio(resolvedConfig.windowConfiguration.getBounds(), newParentConfiguration.windowConfiguration.getAppBounds(), newParentConfiguration.windowConfiguration.getBounds()); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 89723d14090b..65704c891318 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -19,6 +19,7 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; +import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.os.Process.NOBODY_UID; @@ -62,6 +63,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.never; import android.app.ActivityOptions; +import android.app.WindowConfiguration; import android.app.servertransaction.ActivityConfigurationChangeItem; import android.app.servertransaction.ClientTransaction; import android.app.servertransaction.PauseActivityItem; @@ -70,6 +72,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Rect; import android.os.Bundle; import android.os.PersistableBundle; import android.platform.test.annotations.Presubmit; @@ -376,6 +379,64 @@ public class ActivityRecordTests extends ActivityTestsBase { } @Test + public void ignoreRequestedOrientationInFreeformWindows() { + mStack.setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM); + final Rect stableRect = new Rect(); + mStack.getDisplay().mDisplayContent.getStableRect(stableRect); + final boolean isScreenPortrait = stableRect.width() <= stableRect.height(); + final Rect bounds = new Rect(stableRect); + if (isScreenPortrait) { + // Landscape bounds + final int newHeight = stableRect.width() - 10; + bounds.top = stableRect.top + (stableRect.height() - newHeight) / 2; + bounds.bottom = bounds.top + newHeight; + } else { + // Portrait bounds + final int newWidth = stableRect.height() - 10; + bounds.left = stableRect.left + (stableRect.width() - newWidth) / 2; + bounds.right = bounds.left + newWidth; + } + mTask.setBounds(bounds); + + // Requests orientation that's different from its bounds. + mActivity.setRequestedOrientation( + isScreenPortrait ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE); + + // Asserts it has orientation derived from bounds. + assertEquals(isScreenPortrait ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT, + mActivity.getConfiguration().orientation); + } + + @Test + public void ignoreRequestedOrientationInSplitWindows() { + mStack.setWindowingMode(WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); + final Rect stableRect = new Rect(); + mStack.getDisplay().mDisplayContent.getStableRect(stableRect); + final boolean isScreenPortrait = stableRect.width() <= stableRect.height(); + final Rect bounds = new Rect(stableRect); + if (isScreenPortrait) { + // Landscape bounds + final int newHeight = stableRect.width() - 10; + bounds.top = stableRect.top + (stableRect.height() - newHeight) / 2; + bounds.bottom = bounds.top + newHeight; + } else { + // Portrait bounds + final int newWidth = stableRect.height() - 10; + bounds.left = stableRect.left + (stableRect.width() - newWidth) / 2; + bounds.right = bounds.left + newWidth; + } + mTask.setBounds(bounds); + + // Requests orientation that's different from its bounds. + mActivity.setRequestedOrientation( + isScreenPortrait ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE); + + // Asserts it has orientation derived from bounds. + assertEquals(isScreenPortrait ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT, + mActivity.getConfiguration().orientation); + } + + @Test public void testShouldMakeActive_deferredResume() { mActivity.setState(ActivityStack.ActivityState.STOPPED, "Testing"); |