Associate freezing display with a target display id.
Currently, start/stop freezing is always associated with the default
display. As a result, any animations that result from freezing will
occur on the default display. One situation this happens is during a
configuration change, where a screen rotation can be triggered. In
the case of adding a secondary display, a configuration change is
always triggered to apply the override configuration at the display
level. As a result, the default display exhibits a rotation animation
upon unfreezing during surface placement.
This changelist passes down the display id associated with the action
so that the animations may be applied to the right display. In the
scenario described perviously, the secondary display id is passed down
and therefore is the target of the rotation animation during
unfreezing.
Fixes: 35486733
Test: go/wm-smoke
Test: cts-tradefed run singleCommand cts-dev --module CtsViewTestCases --test android.view.cts.SurfaceViewSyncTest#testSmallRect
Change-Id: I87e56f5901934327fc50b3c7e543b5e36b8ff34f
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 525e0ff..71ecaf6 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -1107,7 +1107,7 @@
mAppAnimator.lastFreezeDuration = 0;
mService.mAppsFreezingScreen++;
if (mService.mAppsFreezingScreen == 1) {
- mService.startFreezingDisplayLocked(false, 0, 0);
+ mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
}
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index eef4c9b..a8e0d76 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -987,7 +987,7 @@
}
if (!rotateSeamlessly) {
- mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1]);
+ mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
// startFreezingDisplayLocked can reset the ScreenRotationAnimation.
screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
mDisplayId);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 9d1b3d9..6fd153e 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -20,7 +20,6 @@
import static android.Manifest.permission.READ_FRAME_BUFFER;
import static android.Manifest.permission.REGISTER_WINDOW_MANAGER_LISTENERS;
import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
-import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
import static android.app.StatusBarManager.DISABLE_MASK;
import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED;
@@ -33,6 +32,7 @@
import static android.os.Process.myPid;
import static android.os.UserHandle.USER_NULL;
import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.DOCKED_INVALID;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
@@ -724,6 +724,9 @@
// For frozen screen animations.
private int mExitAnimId, mEnterAnimId;
+ // The display that the rotation animation is applying to.
+ private int mFrozenDisplayId;
+
/** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
* is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
int mTransactionSequence;
@@ -2449,7 +2452,7 @@
} else {
mPolicy.selectRotationAnimationLw(anim);
}
- startFreezingDisplayLocked(false, anim[0], anim[1]);
+ startFreezingDisplayLocked(false, anim[0], anim[1], displayContent);
config = new Configuration(mTempConfiguration);
}
}
@@ -5555,7 +5558,7 @@
if (configChanged) {
mWaitingForConfig = true;
startFreezingDisplayLocked(false /* inTransaction */, 0 /* exitAnim */,
- 0 /* enterAnim */);
+ 0 /* enterAnim */, displayContent);
mH.obtainMessage(H.SEND_NEW_CONFIGURATION, displayId).sendToTarget();
}
@@ -5862,6 +5865,12 @@
}
void startFreezingDisplayLocked(boolean inTransaction, int exitAnim, int enterAnim) {
+ startFreezingDisplayLocked(inTransaction, exitAnim, enterAnim,
+ getDefaultDisplayContentLocked());
+ }
+
+ void startFreezingDisplayLocked(boolean inTransaction, int exitAnim, int enterAnim,
+ DisplayContent displayContent) {
if (mDisplayFrozen) {
return;
}
@@ -5882,6 +5891,10 @@
mDisplayFreezeTime = SystemClock.elapsedRealtime();
mLastFinishedFreezeSource = null;
+ // {@link mDisplayFrozen} prevents us from freezing on multiple displays at the same time.
+ // As a result, we only track the display that has initially froze the screen.
+ mFrozenDisplayId = displayContent.getDisplayId();
+
mInputMonitor.freezeInputDispatchingLw();
// Clear the last input window -- that is just used for
@@ -5901,10 +5914,8 @@
if (CUSTOM_SCREEN_ROTATION) {
mExitAnimId = exitAnim;
mEnterAnimId = enterAnim;
- final DisplayContent displayContent = getDefaultDisplayContentLocked();
- final int displayId = displayContent.getDisplayId();
ScreenRotationAnimation screenRotationAnimation =
- mAnimator.getScreenRotationAnimationLocked(displayId);
+ mAnimator.getScreenRotationAnimationLocked(mFrozenDisplayId);
if (screenRotationAnimation != null) {
screenRotationAnimation.kill();
}
@@ -5915,8 +5926,10 @@
// TODO(multidisplay): rotation on main screen only.
displayContent.updateDisplayInfo();
screenRotationAnimation = new ScreenRotationAnimation(mContext, displayContent,
- mFxSession, inTransaction, mPolicy.isDefaultOrientationForced(), isSecure, this);
- mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
+ mFxSession, inTransaction, mPolicy.isDefaultOrientationForced(), isSecure,
+ this);
+ mAnimator.setScreenRotationAnimationLocked(mFrozenDisplayId,
+ screenRotationAnimation);
}
}
@@ -5940,6 +5953,13 @@
if (DEBUG_ORIENTATION) Slog.d(TAG_WM,
"stopFreezingDisplayLocked: Unfreezing now");
+ final DisplayContent displayContent = mRoot.getDisplayContent(mFrozenDisplayId);
+
+ // We must make a local copy of the displayId as it can be potentially overwritten later on
+ // in this method. For example, {@link startFreezingDisplayLocked} may be called as a result
+ // of update rotation, but we reference the frozen display after that call in this method.
+ final int displayId = mFrozenDisplayId;
+ mFrozenDisplayId = INVALID_DISPLAY;
mDisplayFrozen = false;
mLastDisplayFreezeDuration = (int)(SystemClock.elapsedRealtime() - mDisplayFreezeTime);
StringBuilder sb = new StringBuilder(128);
@@ -5958,8 +5978,6 @@
boolean updateRotation = false;
- final DisplayContent displayContent = getDefaultDisplayContentLocked();
- final int displayId = displayContent.getDisplayId();
ScreenRotationAnimation screenRotationAnimation =
mAnimator.getScreenRotationAnimationLocked(displayId);
if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null