From 1e022839cae76e1d88893842c1bf685edba3e09a Mon Sep 17 00:00:00 2001 From: Tommy Webb Date: Thu, 12 Jan 2023 19:25:20 -0500 Subject: Fix stuck screen from display change timeout Occasionally, a remote display change is not processed within the timeout period. One prominent example is when a device is not able to complete its rotation from landscape back to portrait in time after the display is turned off. When this happens, and the callback is called after the timeout instead, DisplayContent#sendNewConfiguration abandons its effort when it sees there are pending display changes, but this callback itself might be the pending display change, and it does not expect itself to be included as part of this decision. Remove all callbacks before calling the last one to prevent this. Test: Manual: Build and run with REMOTE_DISPLAY_CHANGE_TIMEOUT_MS = 50, or some other low value. Enter landscape mode, e.g. by playing a video. Turn off the screen. Wait 3 seconds. Turn the screen back on. The lock screen will appear as normal. Previously, the screen would remain black until a restart or `adb shell wm` change interaction. Bug: 266535056 Change-Id: I53659d5580cdd70b4c7138dcca770b11f5397194 --- .../com/android/server/wm/RemoteDisplayChangeController.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/RemoteDisplayChangeController.java b/services/core/java/com/android/server/wm/RemoteDisplayChangeController.java index 43baebc7255a..e646f14a3e13 100644 --- a/services/core/java/com/android/server/wm/RemoteDisplayChangeController.java +++ b/services/core/java/com/android/server/wm/RemoteDisplayChangeController.java @@ -114,9 +114,15 @@ public class RemoteDisplayChangeController { // timed-out, so run all continue callbacks and clear the list synchronized (mService.mGlobalLock) { for (int i = 0; i < mCallbacks.size(); ++i) { - mCallbacks.get(i).onContinueRemoteDisplayChange(null /* transaction */); + final ContinueRemoteDisplayChangeCallback callback = mCallbacks.get(i); + if (i == mCallbacks.size() - 1) { + // Clear all callbacks before calling the last one, so that if the callback + // itself calls {@link #isWaitingForRemoteDisplayChange()}, it will get + // {@code false}. After all, there is nothing pending after this one. + mCallbacks.clear(); + } + callback.onContinueRemoteDisplayChange(null /* transaction */); } - mCallbacks.clear(); } } -- cgit v1.2.3-59-g8ed1b