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

Commit 3f9935f3 authored by Yifei Zhang's avatar Yifei Zhang
Browse files

keyguard: don't skip the first listener dispatch

- Make mDispatchedKeyguardLockedState tri-state.
- Ensure we don't skip the first dispatch, as the value retrieved from
  KeyguardManager may be true if the KeyguardService is not connected
  yet. This will cause inconsistent values.

Flag: com.android.window.flags.dispatch_first_keyguard_locked_state
Test: manual
Bug: 375029840
Change-Id: I0938ed6df24f7ab87ba5aff0519a13ac75c25bc0
parent 4ffe9032
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -545,3 +545,14 @@ flag {
    description: "Adds support for trackpad back gestures on connected displays"
    bug: "382774299"
}

flag {
    namespace: "wear_frameworks"
    name: "dispatch_first_keyguard_locked_state"
    description: "Ensures the first keyguard locked state is dispatched to listeners reigstered through KeyguardManager.addKeyguardLockedStateListener"
    bug: "375029840"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -55,5 +55,7 @@ class WindowManagerFlags {

    final boolean mAodTransition = Flags.aodTransition();

    final boolean mDispatchFirstKeyguardLockedState = Flags.dispatchFirstKeyguardLockedState();

    /* End Available Flags */
}
+17 −4
Original line number Diff line number Diff line
@@ -479,7 +479,11 @@ public class WindowManagerService extends IWindowManager.Stub

    private final List<OnWindowRemovedListener> mOnWindowRemovedListeners = new ArrayList<>();

    private boolean mDispatchedKeyguardLockedState = false;
    /** Indicates whether the first keyguard locked state has been dispatched. */
    private boolean mHasDispatchedKeyguardLockedState = false;

    /** The last dispatched keyguard locked state. */
    private boolean mLastDispatchedKeyguardLockedState = false;

    // VR Vr2d Display Id.
    int mVr2dDisplayId = INVALID_DISPLAY;
@@ -3532,9 +3536,17 @@ public class WindowManagerService extends IWindowManager.Stub
    private void dispatchKeyguardLockedState() {
        mH.post(() -> {
            final boolean isKeyguardLocked = mPolicy.isKeyguardShowing();
            if (mDispatchedKeyguardLockedState == isKeyguardLocked) {
            if (mFlags.mDispatchFirstKeyguardLockedState) {
                // Ensure we don't skip the call for the first dispatch
                if (!mHasDispatchedKeyguardLockedState
                        && mLastDispatchedKeyguardLockedState == isKeyguardLocked) {
                    return;
                }
            } else {
                if (mLastDispatchedKeyguardLockedState == isKeyguardLocked) {
                    return;
                }
            }
            final int n = mKeyguardLockedStateListeners.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
@@ -3545,7 +3557,8 @@ public class WindowManagerService extends IWindowManager.Stub
                }
            }
            mKeyguardLockedStateListeners.finishBroadcast();
            mDispatchedKeyguardLockedState = isKeyguardLocked;
            mLastDispatchedKeyguardLockedState = isKeyguardLocked;
            mHasDispatchedKeyguardLockedState = true;
        });
    }