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

Commit 168dbdbc authored by jovanak's avatar jovanak
Browse files

For automotive builds: makes sure the keyguard gets automatically

dismissed after every user switch.

Fixes: 123765081
Test: Manual verification of keyguard dismissal after boot and many user switches.
Change-Id: Ie72ad254a41057df7efc79bda97b64f7dc5a980e
parent 147f82a1
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -511,33 +511,53 @@ public class CarStatusBar extends StatusBar implements
        }
    }

    @Override
    public void setLockscreenUser(int newUserId) {
        super.setLockscreenUser(newUserId);
        // Try to dismiss the keyguard after every user switch.
        dismissKeyguardWhenUserSwitcherNotDisplayed();
    }

    @Override
    public void onStateChanged(int newState) {
        super.onStateChanged(newState);

        startSwitchToGuestTimerIfDrivingOnKeyguard();

        if (mFullscreenUserSwitcher == null) {
            return; // Not using the full screen user switcher.
        }

        if (newState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
            if (!mFullscreenUserSwitcher.isVisible()) {
                // Current execution path continues to set state after this, thus we deffer the
                // dismissal to the next execution cycle.
                postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible.
            }
        if (newState != StatusBarState.FULLSCREEN_USER_SWITCHER) {
            hideUserSwitcher();
        } else {
            mFullscreenUserSwitcher.hide();
            dismissKeyguardWhenUserSwitcherNotDisplayed();
        }
    }

    /** Makes the full screen user switcher visible, if applicable. */
    public void showUserSwitcher() {
        if (mFullscreenUserSwitcher != null && mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
            mFullscreenUserSwitcher.show(); // Makes the switcher visible.
        }
    }

    private void hideUserSwitcher() {
        if (mFullscreenUserSwitcher != null) {
            mFullscreenUserSwitcher.hide();
        }
    }

    // We automatically dismiss keyguard unless user switcher is being shown on the keyguard.
    private void dismissKeyguardWhenUserSwitcherNotDisplayed() {
        if (mFullscreenUserSwitcher == null) {
            return; // Not using the full screen user switcher.
        }

        if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER
                && !mFullscreenUserSwitcher.isVisible()) {
            // Current execution path continues to set state after this, thus we deffer the
            // dismissal to the next execution cycle.
            postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible.
        }
    }

    public void postDismissKeyguard() {
        mHandler.post(this::dismissKeyguard);
    }