[go: nahoru, domu]

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
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 721de61..b1ef601 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 @@
     }
 
     /** @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 12def36..0844323 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 @@
  * particular Display.
  */
 class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
-        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 @@
      * values from being replaced by the initializing {@link #ActivityDisplay}.
      */
     void initializeDisplayOverrideConfiguration() {
-        if (mActivityDisplay != null) {
-            mActivityDisplay.getRequestedOverrideConfiguration()
-                    .updateFrom(getRequestedOverrideConfiguration());
+        if (mActivityDisplay == null) {
+            return;
         }
+        mActivityDisplay.onRequestedOverrideConfigurationChanged(
+                getResolvedOverrideConfiguration());
+        mActivityDisplay.registerConfigurationChangeListener(this);
     }
 
     void reconfigureDisplayLocked() {
@@ -2373,6 +2375,9 @@
     void removeImmediately() {
         mRemovingDisplay = true;
         try {
+            if (mActivityDisplay != null) {
+                mActivityDisplay.unregisterConfigurationChangeListener(this);
+            }
             if (mParentWindow != null) {
                 mParentWindow.removeEmbeddedDisplayContent(this);
             }
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 2ad9102..104fe5f 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -20,12 +20,8 @@
 import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PORTRAIT_ONLY;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZABLE_PRESERVE_ORIENTATION;
-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_UNSET;
 import static android.content.res.Configuration.EMPTY;
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
-import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
 import static android.view.SurfaceControl.METADATA_TASK_ID;
 
 import static com.android.server.EventLogTags.WM_TASK_REMOVED;
@@ -135,26 +131,17 @@
         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 1270658..82b9d46 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 @@
      */
     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 @@
             }
             // 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 fcda494..2661735 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 @@
         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 @@
         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 @@
         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