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

Commit 17abbd4f authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge "Stop face auth when we transition to unsupported posture, no-op...

Merge "Stop face auth when we transition to unsupported posture, no-op otherwise on posture change." into udc-dev
parents fd87f823 98769357
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
@@ -160,6 +160,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;
@@ -368,7 +369,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;
@@ -1862,11 +1863,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
@@ -2901,9 +2907,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 =
@@ -2952,6 +2956,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 −0
Original line number Diff line number Diff line
@@ -2209,6 +2209,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 {