From 77e35e9edd58994f65c65d8924f07e27a9c2def0 Mon Sep 17 00:00:00 2001 From: Will Leshner Date: Wed, 4 Jan 2023 09:55:35 -0800 Subject: [PATCH] Avoid lock screen flash when going to dream. This is specifically when entering a dream from a single power button tap on devices that are configured with that behavior. Bug: 261662912 Test: manually by tapping power button to enter a dream and observing that the device is locks at the same time without flashing the lock screen. Change-Id: I89ecce9cc39cb1cb6f7b19068908ba436643223c --- .../server/policy/PhoneWindowManager.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index b7a801a8fc867..c12aa3aa5cdfb 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -575,6 +575,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { // What we do when the user double-taps on home private int mDoubleTapOnHomeBehavior; + // Whether to lock the device after the next app transition has finished. + private boolean mLockAfterAppTransitionFinished; + // Allowed theater mode wake actions private boolean mAllowTheaterModeWakeFromKey; private boolean mAllowTheaterModeWakeFromPowerKey; @@ -1073,11 +1076,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { return; } - // Make sure the device locks. Unfortunately, this has the side-effect of briefly revealing - // the lock screen before the dream appears. Note that locking is a side-effect of the no - // dream action that is executed if we early return above. - // TODO(b/261662912): Find a better way to lock the device that doesn't result in jank. - lockNow(null); + synchronized (mLock) { + // Lock the device after the dream transition has finished. + mLockAfterAppTransitionFinished = true; + } dreamManagerInternal.requestDream(); } @@ -2197,6 +2199,22 @@ public class PhoneWindowManager implements WindowManagerPolicy { handleTransitionForKeyguardLw( keyguardGoingAwayCancelled /* startKeyguardExitAnimation */, true /* notifyOccluded */); + + synchronized (mLock) { + mLockAfterAppTransitionFinished = false; + } + } + + @Override + public void onAppTransitionFinishedLocked(IBinder token) { + synchronized (mLock) { + if (!mLockAfterAppTransitionFinished) { + return; + } + mLockAfterAppTransitionFinished = false; + } + + lockNow(null); } });