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

Commit fd7df7c0 authored by Chandru S's avatar Chandru S
Browse files

Stop face auth when we transition to unsupported posture, no-op otherwise on posture change.

Fixes: 262492399
Test: atest KeyguardUpdateMonitorTest
Test: manually,
  1. enroll face auth
  2. Go to an face auth unsupported posture for the device
  3. Go to a face auth supported posture for the device
  4. Check the logs to make sure face auth wasn't triggered momentarily.
Change-Id: Ic96ddde93d1f45c1bf667d6b32193e754a79bf06
Merged-In: Ic96ddde93d1f45c1bf667d6b32193e754a79bf06
parent e829ea7f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ data class KeyguardFaceListenModel(
    var keyguardGoingAway: Boolean = false,
    var listeningForFaceAssistant: Boolean = false,
    var occludingAppRequestingFaceAuth: Boolean = false,
    val postureAllowsListening: Boolean = false,
    var postureAllowsListening: Boolean = false,
    var primaryUser: Boolean = false,
    var secureCameraLaunched: Boolean = false,
    var supportsDetect: Boolean = false,
@@ -70,6 +70,7 @@ data class KeyguardFaceListenModel(
            listeningForFaceAssistant.toString(),
            occludingAppRequestingFaceAuth.toString(),
            primaryUser.toString(),
            postureAllowsListening.toString(),
            secureCameraLaunched.toString(),
            supportsDetect.toString(),
            switchingUser.toString(),
@@ -109,6 +110,7 @@ data class KeyguardFaceListenModel(
                listeningForFaceAssistant = model.listeningForFaceAssistant
                occludingAppRequestingFaceAuth = model.occludingAppRequestingFaceAuth
                primaryUser = model.primaryUser
                postureAllowsListening = model.postureAllowsListening
                secureCameraLaunched = model.secureCameraLaunched
                supportsDetect = model.supportsDetect
                switchingUser = model.switchingUser
@@ -152,6 +154,7 @@ data class KeyguardFaceListenModel(
                "listeningForFaceAssistant",
                "occludingAppRequestingFaceAuth",
                "primaryUser",
                "postureAllowsListening",
                "secureCameraLaunched",
                "supportsDetect",
                "switchingUser",
+16 −7
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ import com.android.systemui.shared.system.TaskStackChangeListeners;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt;
import com.android.systemui.telephony.TelephonyListenerManager;
import com.android.systemui.util.Assert;
import com.android.systemui.util.settings.SecureSettings;
@@ -359,7 +360,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private final FaceManager mFaceManager;
    private final LockPatternUtils mLockPatternUtils;
    @VisibleForTesting
    @DevicePostureController.DevicePostureInt
    @DevicePostureInt
    protected int mConfigFaceAuthSupportedPosture;

    private KeyguardBypassController mKeyguardBypassController;
@@ -1846,11 +1847,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    final DevicePostureController.Callback mPostureCallback =
            new DevicePostureController.Callback() {
                @Override
                public void onPostureChanged(int posture) {
                public void onPostureChanged(@DevicePostureInt int posture) {
                    boolean currentPostureAllowsFaceAuth = doesPostureAllowFaceAuth(mPostureState);
                    boolean newPostureAllowsFaceAuth = doesPostureAllowFaceAuth(posture);
                    mPostureState = posture;
                    updateFaceListeningState(BIOMETRIC_ACTION_UPDATE,
                    if (currentPostureAllowsFaceAuth && !newPostureAllowsFaceAuth) {
                        mLogger.d("New posture does not allow face auth, stopping it");
                        updateFaceListeningState(BIOMETRIC_ACTION_STOP,
                                FACE_AUTH_UPDATED_POSTURE_CHANGED);
                    }
                }
            };

    @VisibleForTesting
@@ -2886,9 +2892,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        final boolean biometricEnabledForUser = mBiometricEnabledForUser.get(user);
        final boolean shouldListenForFaceAssistant = shouldListenForFaceAssistant();
        final boolean isUdfpsFingerDown = mAuthController.isUdfpsFingerDown();
        final boolean isPostureAllowedForFaceAuth =
                mConfigFaceAuthSupportedPosture == 0 /* DEVICE_POSTURE_UNKNOWN */ ? true
                        : (mPostureState == mConfigFaceAuthSupportedPosture);
        final boolean isPostureAllowedForFaceAuth = doesPostureAllowFaceAuth(mPostureState);
        // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
        // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
        final boolean shouldListen =
@@ -2937,6 +2941,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        return shouldListen;
    }

    private boolean doesPostureAllowFaceAuth(@DevicePostureInt int posture) {
        return mConfigFaceAuthSupportedPosture == DEVICE_POSTURE_UNKNOWN
                || (posture == mConfigFaceAuthSupportedPosture);
    }

    private void logListenerModelData(@NonNull KeyguardListenModel model) {
        mLogger.logKeyguardListenerModel(model);
        if (model instanceof KeyguardFingerprintListenModel) {
+26 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.keyguard;

import static android.app.StatusBarManager.SESSION_KEYGUARD;
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_LOCKOUT_TIMED;
import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ERROR_LOCKOUT;
import static android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ERROR_LOCKOUT_PERMANENT;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
@@ -2199,6 +2198,32 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
                eq(false), eq(BiometricSourceType.FACE));
    }

    @Test
    public void testPostureChangeToUnsupported_stopsFaceListeningState() {
        // GIVEN device is listening for face
        mKeyguardUpdateMonitor.mConfigFaceAuthSupportedPosture = DEVICE_POSTURE_CLOSED;
        deviceInPostureStateClosed();
        mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);
        mTestableLooper.processAllMessages();
        keyguardIsVisible();

        verifyFaceAuthenticateCall();

        final CancellationSignal faceCancel = spy(mKeyguardUpdateMonitor.mFaceCancelSignal);
        mKeyguardUpdateMonitor.mFaceCancelSignal = faceCancel;
        KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);
        mKeyguardUpdateMonitor.registerCallback(callback);

        // WHEN device is opened
        deviceInPostureStateOpened();
        mTestableLooper.processAllMessages();

        // THEN face listening is stopped.
        verify(faceCancel).cancel();
        verify(callback).onBiometricRunningStateChanged(
                eq(false), eq(BiometricSourceType.FACE));
    }

    @Test
    public void testShouldListenForFace_withLockedDown_returnsFalse()
            throws RemoteException {