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

Commit d2dfe82b authored by Beverly's avatar Beverly
Browse files

Eval KG showing, occluded and visibility together

Keyguard visibility is based on the keyguard showing
and occluded states, but the KUM state changes were previously
separated so that KG would respond to a occlusion change
but not have the newest visibility, so it would
inaccurately update its fingerprint listening state. To avoid this
race condition, this CL consolidates KG showing, occlusion and
visibility changes to a single setKeyguardShowing(showing, occluded)
method. The method updates the KUM state and then sends the change
out to listeners.

This CL also updates some of the vocab used. In the future,
keyguardVisibility from a KUM perspective means that the keyguard
is showing and NOT occluded.

Test: atest SystemUITests
Test: enable a screensaver and successfully authenticate from the
screensaver with a non UDFPS fp sensor
Test: double press power button to the camera (occluded state), and
see that rear FP will stop running. Can still auth when accessing
the photo gallery.
Test: double press power button to the camera (occluded state), and
see that UDFPS affordance isn't available. Can still auth when
accessing the photo gallery.
Test: Setup a timer to go off, see that going to/from the occluded
activity updates the occluded & keyguard visibility state correctly
Bug: 248089638
Fixes: 247580913

Change-Id: I3478be2d304a42beebdb6a4baaf2e571d74e61b1
parent 8fa46d14
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ open class ClockEventController @Inject constructor(

    private var isCharging = false
    private var dozeAmount = 0f
    private var isKeyguardShowing = false
    private var isKeyguardVisible = false

    private val regionSamplingEnabled =
            featureFlags.isEnabled(com.android.systemui.flags.Flags.REGION_SAMPLING)
@@ -145,7 +145,7 @@ open class ClockEventController @Inject constructor(

    private val batteryCallback = object : BatteryStateChangeCallback {
        override fun onBatteryLevelChanged(level: Int, pluggedIn: Boolean, charging: Boolean) {
            if (isKeyguardShowing && !isCharging && charging) {
            if (isKeyguardVisible && !isCharging && charging) {
                clock?.animations?.charge()
            }
            isCharging = charging
@@ -168,9 +168,9 @@ open class ClockEventController @Inject constructor(
    }

    private val keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() {
        override fun onKeyguardVisibilityChanged(showing: Boolean) {
            isKeyguardShowing = showing
            if (!isKeyguardShowing) {
        override fun onKeyguardVisibilityChanged(visible: Boolean) {
            isKeyguardVisible = visible
            if (!isKeyguardVisible) {
                clock?.animations?.doze(if (isDozing) 1f else 0f)
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -212,9 +212,9 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
        }

        @Override
        public void onKeyguardVisibilityChanged(boolean showing) {
            if (showing) {
                if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing);
        public void onKeyguardVisibilityChanged(boolean visible) {
            if (visible) {
                if (DEBUG) Slog.v(TAG, "refresh statusview visible:true");
                refreshTime();
            }
        }
+47 −33
Original line number Diff line number Diff line
@@ -308,7 +308,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    HashMap<Integer, ServiceState> mServiceStates = new HashMap<>();

    private int mPhoneState;
    private boolean mKeyguardIsVisible;
    private boolean mKeyguardShowing;
    private boolean mKeyguardOccluded;
    private boolean mCredentialAttempted;
    private boolean mKeyguardGoingAway;
    private boolean mGoingToSleep;
@@ -318,7 +319,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private boolean mAuthInterruptActive;
    private boolean mNeedsSlowUnlockTransition;
    private boolean mAssistantVisible;
    private boolean mKeyguardOccluded;
    private boolean mOccludingAppRequestingFp;
    private boolean mOccludingAppRequestingFace;
    private boolean mSecureCameraLaunched;
@@ -681,14 +681,42 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    /**
     * Updates KeyguardUpdateMonitor's internal state to know if keyguard is occluded
     * Updates KeyguardUpdateMonitor's internal state to know if keyguard is showing and if
     * its occluded. The keyguard is considered visible if its showing and NOT occluded.
     */
    public void setKeyguardOccluded(boolean occluded) {
    public void setKeyguardShowing(boolean showing, boolean occluded) {
        final boolean occlusionChanged = mKeyguardOccluded != occluded;
        final boolean showingChanged = mKeyguardShowing != showing;
        if (!occlusionChanged && !showingChanged) {
            return;
        }

        final boolean wasKeyguardVisible = isKeyguardVisible();
        mKeyguardShowing = showing;
        mKeyguardOccluded = occluded;
        final boolean isKeyguardVisible = isKeyguardVisible();
        mLogger.logKeyguardShowingChanged(showing, occluded, isKeyguardVisible);

        if (isKeyguardVisible != wasKeyguardVisible) {
            if (isKeyguardVisible) {
                mSecureCameraLaunched = false;
            }
            for (int i = 0; i < mCallbacks.size(); i++) {
                KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
                if (cb != null) {
                    cb.onKeyguardVisibilityChanged(isKeyguardVisible);
                }
            }
        }

        if (occlusionChanged) {
            updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE,
                    FACE_AUTH_UPDATED_KEYGUARD_OCCLUSION_CHANGED);
        } else if (showingChanged) {
            updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE,
                    FACE_AUTH_UPDATED_KEYGUARD_VISIBILITY_CHANGED);
        }
    }


    /**
     * Request to listen for face authentication when an app is occluding keyguard.
@@ -2442,7 +2470,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        // Triggers:
        final boolean triggerActiveUnlockForAssistant = shouldTriggerActiveUnlockForAssistant();
        final boolean awakeKeyguard = mBouncerFullyShown || mUdfpsBouncerShowing
                || (mKeyguardIsVisible && !mGoingToSleep
                || (isKeyguardVisible() && !mGoingToSleep
                && mStatusBarState != StatusBarState.SHADE_LOCKED);

        // Gates:
@@ -2518,7 +2546,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        final boolean userDoesNotHaveTrust = !getUserHasTrust(user);
        final boolean shouldListenForFingerprintAssistant = shouldListenForFingerprintAssistant();
        final boolean shouldListenKeyguardState =
                mKeyguardIsVisible
                isKeyguardVisible()
                        || !mDeviceInteractive
                        || (mBouncerIsOrWillBeShowing && !mKeyguardGoingAway)
                        || mGoingToSleep
@@ -2567,7 +2595,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    mFingerprintLockedOut,
                    mGoingToSleep,
                    mKeyguardGoingAway,
                    mKeyguardIsVisible,
                    isKeyguardVisible(),
                    mKeyguardOccluded,
                    mOccludingAppRequestingFp,
                    mIsPrimaryUser,
@@ -2589,7 +2617,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }

        final boolean statusBarShadeLocked = mStatusBarState == StatusBarState.SHADE_LOCKED;
        final boolean awakeKeyguard = mKeyguardIsVisible && mDeviceInteractive
        final boolean awakeKeyguard = isKeyguardVisible() && mDeviceInteractive
                && !statusBarShadeLocked;
        final int user = getCurrentUser();
        final int strongAuth = mStrongAuthTracker.getStrongAuthForUser(user);
@@ -3146,32 +3174,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        callbacksRefreshCarrierInfo();
    }

    /**
     * Whether the keyguard is showing and not occluded.
     */
    public boolean isKeyguardVisible() {
        return mKeyguardIsVisible;
        return isKeyguardShowing() && !mKeyguardOccluded;
    }

    /**
     * Notifies that the visibility state of Keyguard has changed.
     *
     * <p>Needs to be called from the main thread.
     * Whether the keyguard is showing. It may still be occluded and not visible.
     */
    public void onKeyguardVisibilityChanged(boolean showing) {
        Assert.isMainThread();
        mLogger.logKeyguardVisibilityChanged(showing);
        mKeyguardIsVisible = showing;

        if (showing) {
            mSecureCameraLaunched = false;
        }

        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onKeyguardVisibilityChangedRaw(showing);
            }
        }
        updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE,
                FACE_AUTH_UPDATED_KEYGUARD_VISIBILITY_CHANGED);
    public boolean isKeyguardShowing() {
        return mKeyguardShowing;
    }

    /**
@@ -3380,7 +3394,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        callback.onTimeChanged();
        callback.onPhoneStateChanged(mPhoneState);
        callback.onRefreshCarrierInfo();
        callback.onKeyguardVisibilityChangedRaw(mKeyguardIsVisible);
        callback.onKeyguardVisibilityChanged(isKeyguardVisible());
        callback.onTelephonyCapable(mTelephonyCapable);

        for (Entry<Integer, SimData> data : mSimDatas.entrySet()) {
+6 −20
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.keyguard;

import android.hardware.biometrics.BiometricSourceType;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.view.WindowManagerPolicyConstants;

@@ -32,10 +31,6 @@ import java.util.TimeZone;
 */
public class KeyguardUpdateMonitorCallback {

    private static final long VISIBILITY_CHANGED_COLLAPSE_MS = 1000;
    private long mVisibilityChangedCalled;
    private boolean mShowing;

    /**
     * Called when the battery status changes, e.g. when plugged in or unplugged, charge
     * level, etc. changes.
@@ -74,21 +69,6 @@ public class KeyguardUpdateMonitorCallback {
     */
    public void onPhoneStateChanged(int phoneState) { }

    /**
     * Called when the visibility of the keyguard changes.
     * @param showing Indicates if the keyguard is now visible.
     */
    public void onKeyguardVisibilityChanged(boolean showing) { }

    public void onKeyguardVisibilityChangedRaw(boolean showing) {
        final long now = SystemClock.elapsedRealtime();
        if (showing == mShowing
                && (now - mVisibilityChangedCalled) < VISIBILITY_CHANGED_COLLAPSE_MS) return;
        onKeyguardVisibilityChanged(showing);
        mVisibilityChangedCalled = now;
        mShowing = showing;
    }

    /**
     * Called when the keyguard enters or leaves bouncer mode.
     * @param bouncerIsOrWillBeShowing if true, keyguard is showing the bouncer or transitioning
@@ -96,6 +76,12 @@ public class KeyguardUpdateMonitorCallback {
     */
    public void onKeyguardBouncerStateChanged(boolean bouncerIsOrWillBeShowing) { }

    /**
     * Called when the keyguard visibility changes.
     * @param visible whether the keyguard is showing and is NOT occluded
     */
    public void onKeyguardVisibilityChanged(boolean visible) { }

    /**
     * Called when the keyguard fully transitions to the bouncer or is no longer the bouncer
     * @param bouncerIsFullyShowing if true, keyguard is fully showing the bouncer
+5 −8
Original line number Diff line number Diff line
@@ -446,14 +446,6 @@ public class LockIconViewController extends ViewController<LockIconView> impleme

    private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
            new KeyguardUpdateMonitorCallback() {
                @Override
                public void onKeyguardVisibilityChanged(boolean showing) {
                    // reset mIsBouncerShowing state in case it was preemptively set
                    // onLongPress
                    mIsBouncerShowing = mKeyguardViewController.isBouncerShowing();
                    updateVisibility();
                }

                @Override
                public void onKeyguardBouncerStateChanged(boolean bouncer) {
                    mIsBouncerShowing = bouncer;
@@ -507,6 +499,11 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
            // If biometrics were removed, local vars mCanDismissLockScreen and
            // mUserUnlockedWithBiometric may not be updated.
            mCanDismissLockScreen = mKeyguardStateController.canDismissLockScreen();

            // reset mIsBouncerShowing state in case it was preemptively set
            // onLongPress
            mIsBouncerShowing = mKeyguardViewController.isBouncerShowing();

            updateKeyguardShowing();
            if (mIsKeyguardShowing) {
                mUserUnlockedWithBiometric =
Loading