Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61130ad2 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android Build Coastguard Worker
Browse files

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
(cherry picked from commit 875fa991)
Merged-In: Ie486396fd7328edf8ca0912df92524bb82a1fb7f
(cherry picked from commit 1692babe)
parent f58e054a
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -806,6 +806,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    private final MutableBoolean mTmpBoolean = new MutableBoolean(false);

    private boolean mLockNowPending = false;

    private static final int MSG_ENABLE_POINTER_LOCATION = 1;
    private static final int MSG_DISABLE_POINTER_LOCATION = 2;
    private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
@@ -7520,6 +7522,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    mKeyguardDelegate.doKeyguardTimeout(options);
                }
                mLockScreenTimerActive = false;
                mLockNowPending = false;
                options = null;
            }
        }
@@ -7529,7 +7532,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
    final ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();

    @Override
    public void lockNow(Bundle options) {
@@ -7541,10 +7544,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mScreenLockTimeout.setLockOptions(options);
        }
        mHandler.post(mScreenLockTimeout);
        synchronized (mScreenLockTimeout) {
            mLockNowPending = true;
        }
    }

    private void updateLockScreenTimeout() {
        synchronized (mScreenLockTimeout) {
            if (mLockNowPending) {
                Log.w(TAG, "lockNow pending, ignore updating lockscreen timeout");
                return;
            }
            boolean enable = (mAllowLockscreenWhenOn && mAwake &&
                    mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
            if (mLockScreenTimerActive != enable) {