From 6b76cd3c2eee43d40fbac3a719f2c68de5be6805 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 8 Oct 2019 00:37:19 +0800 Subject: Fix mis-overridden of activity level unifying - AWT#inSizeCompatMode is overridden by ActivityRecord but they were used for different purposes. - Add missing ConfigurationContainerListener of display level. So the configuration got from ActivityRecord#getParent (Task) is synced with TaskRecord. - Initial Task with TaskRecord's resolved configuration instead. That avoids the orientation being locked. Bug: 80414790 Test: atest AppWindowTokenTests#testSizeCompatBounds Test: Launch an unresizable portrait activity, after calling setRequestedOrientation to rotate, the restart button won't appear. Test: 1. Enter split-screen in portrait. 2. Finish the activity in secondary. 3. Launch the same activity from recents. 4. Drag divider to top. 5. Check the orientation is still portrait. Change-Id: Ib3b54a74e98d1e85ea4f7707f17bac51d6dbe21b --- .../java/com/android/server/wm/AppWindowToken.java | 4 ++-- .../java/com/android/server/wm/DisplayContent.java | 13 +++++++---- services/core/java/com/android/server/wm/Task.java | 25 ++++++---------------- .../java/com/android/server/wm/WindowState.java | 4 ++-- .../com/android/server/wm/AppWindowTokenTests.java | 6 +++--- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index 721de613166e..b1ef60185d8d 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -1735,13 +1735,13 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree } /** @return {@code true} if the compatibility bounds is taking effect. */ - boolean inSizeCompatMode() { + boolean hasSizeCompatBounds() { return mSizeCompatBounds != null; } @Override float getSizeCompatScale() { - return inSizeCompatMode() ? mSizeCompatScale : super.getSizeCompatScale(); + return hasSizeCompatBounds() ? mSizeCompatScale : super.getSizeCompatScale(); } @Override diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 12def36019b0..0844323e08fa 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -221,7 +221,7 @@ import java.util.function.Predicate; * particular Display. */ class DisplayContent extends WindowContainer - implements WindowManagerPolicy.DisplayContentInfo { + implements WindowManagerPolicy.DisplayContentInfo, ConfigurationContainerListener { private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; /** The default scaling mode that scales content automatically. */ @@ -1136,10 +1136,12 @@ class DisplayContent extends WindowContainer implements ConfigurationConta mResizeMode = resizeMode; mSupportsPictureInPicture = supportsPictureInPicture; mTaskRecord = taskRecord; + mTaskDescription = taskDescription; + + // Tasks have no set orientation value (including SCREEN_ORIENTATION_UNSPECIFIED). + setOrientation(SCREEN_ORIENTATION_UNSET); if (mTaskRecord != null) { // This can be null when we call createTaskInStack in WindowTestUtils. Remove this after // unification. mTaskRecord.registerConfigurationChangeListener(this); + } else { + setBounds(getResolvedOverrideBounds()); } - setBounds(getResolvedOverrideBounds()); - mTaskDescription = taskDescription; - - // Tasks have no set orientation value (including SCREEN_ORIENTATION_UNSPECIFIED) not unless - // set through the override configuration. - int orientation = SCREEN_ORIENTATION_UNSET; - switch (getResolvedOverrideConfiguration().orientation) { - case ORIENTATION_PORTRAIT: - orientation = SCREEN_ORIENTATION_PORTRAIT; - break; - case ORIENTATION_LANDSCAPE: - orientation = SCREEN_ORIENTATION_LANDSCAPE; - break; - } - setOrientation(orientation); } @Override diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 1270658dbedd..82b9d460029d 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -836,7 +836,7 @@ class WindowState extends WindowContainer implements WindowManagerP */ boolean inSizeCompatMode() { return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0 - || (mAppToken != null && mAppToken.inSizeCompatMode() + || (mAppToken != null && mAppToken.hasSizeCompatBounds() // Exclude starting window because it is not displayed by the application. && mAttrs.type != TYPE_APPLICATION_STARTING); } @@ -2320,7 +2320,7 @@ class WindowState extends WindowContainer implements WindowManagerP } // The offset of compatibility bounds is applied to surface of {@link #AppWindowToken} // and frame, so it is unnecessary to translate twice in surface based coordinates. - final int surfaceOffsetX = mAppToken.inSizeCompatMode() + final int surfaceOffsetX = mAppToken.hasSizeCompatBounds() ? mAppToken.getBounds().left : 0; mTmpRect.offset(surfaceOffsetX - mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top); region.set(mTmpRect); 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 fcda49472e8d..26617355cfbf 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java @@ -221,7 +221,7 @@ public class AppWindowTokenTests extends WindowTestsBase { containerBounds.set(0, 0, 600, 800); mToken.onConfigurationChanged(newParentConfig); - assertTrue(mToken.inSizeCompatMode()); + assertTrue(mToken.hasSizeCompatBounds()); assertEquals(containerAppBounds, mToken.getBounds()); assertEquals((float) containerAppBounds.width() / fixedBounds.width(), mToken.getSizeCompatScale(), 0.0001f /* delta */); @@ -231,7 +231,7 @@ public class AppWindowTokenTests extends WindowTestsBase { containerBounds.set(containerAppBounds); mToken.onConfigurationChanged(newParentConfig); - assertTrue(mToken.inSizeCompatMode()); + assertTrue(mToken.hasSizeCompatBounds()); // Don't scale up, so the bounds keep the same as the fixed width. assertEquals(fixedBounds.width(), mToken.getBounds().width()); // Assert the position is horizontal center. @@ -243,7 +243,7 @@ public class AppWindowTokenTests extends WindowTestsBase { containerBounds.set(0, 0, 1200, 2000); mToken.onConfigurationChanged(newParentConfig); // Assert don't use fixed bounds because the region is enough. - assertFalse(mToken.inSizeCompatMode()); + assertFalse(mToken.hasSizeCompatBounds()); } @Test -- cgit v1.2.3-59-g8ed1b