Fix race condition between lockNow() and updateLockscreenTimeout
If updateLockscreenTimeout gets called before the Runnable queued from lockNow gets executed, lockNow request will be ignored. Fix this by not clearing out the runnable if it's pending lock request. Test: Switch user, ensure lockscreen comes up Bug: 161149543 Change-Id: Ie486396fd7328edf8ca0912df92524bb82a1fb7f
This commit is contained in:
@@ -595,6 +595,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
private KeyCombinationManager mKeyCombinationManager;
|
private KeyCombinationManager mKeyCombinationManager;
|
||||||
private SingleKeyGestureDetector mSingleKeyGestureDetector;
|
private SingleKeyGestureDetector mSingleKeyGestureDetector;
|
||||||
|
|
||||||
|
private boolean mLockNowPending = false;
|
||||||
|
|
||||||
private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
|
private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
|
||||||
private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
|
private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
|
||||||
private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
|
private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
|
||||||
@@ -4817,6 +4819,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
mKeyguardDelegate.doKeyguardTimeout(options);
|
mKeyguardDelegate.doKeyguardTimeout(options);
|
||||||
}
|
}
|
||||||
mLockScreenTimerActive = false;
|
mLockScreenTimerActive = false;
|
||||||
|
mLockNowPending = false;
|
||||||
options = null;
|
options = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4826,7 +4829,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
|
final ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lockNow(Bundle options) {
|
public void lockNow(Bundle options) {
|
||||||
@@ -4838,6 +4841,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
mScreenLockTimeout.setLockOptions(options);
|
mScreenLockTimeout.setLockOptions(options);
|
||||||
}
|
}
|
||||||
mHandler.post(mScreenLockTimeout);
|
mHandler.post(mScreenLockTimeout);
|
||||||
|
synchronized (mScreenLockTimeout) {
|
||||||
|
mLockNowPending = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (b/113840485): Move this logic to DisplayPolicy when lockscreen supports multi-display.
|
// TODO (b/113840485): Move this logic to DisplayPolicy when lockscreen supports multi-display.
|
||||||
@@ -4853,6 +4859,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
|
|
||||||
private void updateLockScreenTimeout() {
|
private void updateLockScreenTimeout() {
|
||||||
synchronized (mScreenLockTimeout) {
|
synchronized (mScreenLockTimeout) {
|
||||||
|
if (mLockNowPending) {
|
||||||
|
Log.w(TAG, "lockNow pending, ignore updating lockscreen timeout");
|
||||||
|
return;
|
||||||
|
}
|
||||||
final boolean enable = !mAllowLockscreenWhenOnDisplays.isEmpty()
|
final boolean enable = !mAllowLockscreenWhenOnDisplays.isEmpty()
|
||||||
&& mDefaultDisplayPolicy.isAwake()
|
&& mDefaultDisplayPolicy.isAwake()
|
||||||
&& mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId);
|
&& mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId);
|
||||||
|
|||||||
Reference in New Issue
Block a user