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

Commit 9e24f4a3 authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Only stop face auth if display is off & awake

To avoid the race condition of the display
turning on after the power manager wakeing up signal.

Test: atest KeyguardUpdateMonitorTest
Test: manually trigger face auth from the power button 15 times.
See that face auth runs each time.
Bug: 300226174

Change-Id: Ib58b6f311298d4d0c97c548565f0f046df3f8349
parent 37e92b6e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ data class KeyguardFaceListenModel(
    override var userId: Int = 0,
    override var listening: Boolean = false,
    // keep sorted
    var allowedDisplayState: Boolean = false,
    var allowedDisplayStateWhileAwake: Boolean = false,
    var alternateBouncerShowing: Boolean = false,
    var authInterruptActive: Boolean = false,
    var biometricSettingEnabledForUser: Boolean = false,
@@ -58,7 +58,7 @@ data class KeyguardFaceListenModel(
            userId.toString(),
            listening.toString(),
            // keep sorted
            allowedDisplayState.toString(),
            allowedDisplayStateWhileAwake.toString(),
            alternateBouncerShowing.toString(),
            authInterruptActive.toString(),
            biometricSettingEnabledForUser.toString(),
@@ -98,7 +98,7 @@ data class KeyguardFaceListenModel(
                userId = model.userId
                listening = model.listening
                // keep sorted
                allowedDisplayState = model.allowedDisplayState
                allowedDisplayStateWhileAwake = model.allowedDisplayStateWhileAwake
                alternateBouncerShowing = model.alternateBouncerShowing
                authInterruptActive = model.authInterruptActive
                biometricSettingEnabledForUser = model.biometricSettingEnabledForUser
@@ -143,7 +143,7 @@ data class KeyguardFaceListenModel(
                "userId",
                "listening",
                // keep sorted
                "allowedDisplayState",
                "allowedDisplayStateWhileAwake",
                "alternateBouncerShowing",
                "authInterruptActive",
                "biometricSettingEnabledForUser",
+14 −8
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import static com.android.keyguard.FaceAuthUiEvent.FACE_AUTH_UPDATED_STARTED_WAK
import static com.android.keyguard.FaceAuthUiEvent.FACE_AUTH_UPDATED_STRONG_AUTH_CHANGED;
import static com.android.keyguard.FaceAuthUiEvent.FACE_AUTH_UPDATED_USER_SWITCHING;
import static com.android.systemui.DejankUtils.whitelistIpcs;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_OPENED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN;

@@ -161,6 +162,7 @@ import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.DumpsysTableLogger;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.keyguard.domain.interactor.FaceAuthenticationListener;
import com.android.systemui.keyguard.domain.interactor.KeyguardFaceAuthInteractor;
import com.android.systemui.keyguard.shared.constants.TrustAgentUiEvent;
@@ -343,15 +345,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                return;
            }

            if (mDisplayTracker.getDisplay(mDisplayTracker.getDefaultDisplayId()).getState()
            if (mWakefulness.getWakefulness() == WAKEFULNESS_AWAKE
                    && mDisplayTracker.getDisplay(mDisplayTracker.getDefaultDisplayId()).getState()
                    == Display.STATE_OFF) {
                mAllowedDisplayStateForFaceAuth = false;
                mAllowedDisplayStateWhileAwakeForFaceAuth = false;
                updateFaceListeningState(
                        BIOMETRIC_ACTION_STOP,
                        FACE_AUTH_DISPLAY_OFF
                );
            } else {
                mAllowedDisplayStateForFaceAuth = true;
                mAllowedDisplayStateWhileAwakeForFaceAuth = true;
            }
        }
    };
@@ -375,7 +378,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private boolean mOccludingAppRequestingFp;
    private boolean mOccludingAppRequestingFace;
    private boolean mSecureCameraLaunched;
    private boolean mAllowedDisplayStateForFaceAuth = true;
    private boolean mAllowedDisplayStateWhileAwakeForFaceAuth = true;
    @VisibleForTesting
    protected boolean mTelephonyCapable;
    private boolean mAllowFingerprintOnCurrentOccludingActivity;
@@ -423,6 +426,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private KeyguardFaceAuthInteractor mFaceAuthInteractor;
    private final TaskStackChangeListeners mTaskStackChangeListeners;
    private final IActivityTaskManager mActivityTaskManager;
    private final WakefulnessLifecycle mWakefulness;
    private final DisplayTracker mDisplayTracker;
    private final LockPatternUtils mLockPatternUtils;
    @VisibleForTesting
@@ -2208,7 +2212,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        Trace.beginSection("KeyguardUpdateMonitor#handleStartedWakingUp");
        Assert.isMainThread();

        mAllowedDisplayStateForFaceAuth = true;
        mAllowedDisplayStateWhileAwakeForFaceAuth = true;
        updateFingerprintListeningState(BIOMETRIC_ACTION_UPDATE);
        if (mFaceWakeUpTriggersConfig.shouldTriggerFaceAuthOnWakeUpFrom(pmWakeReason)) {
            FACE_AUTH_UPDATED_STARTED_WAKING_UP.setExtraInfo(pmWakeReason);
@@ -2364,7 +2368,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            Optional<FingerprintInteractiveToAuthProvider> interactiveToAuthProvider,
            TaskStackChangeListeners taskStackChangeListeners,
            IActivityTaskManager activityTaskManagerService,
            DisplayTracker displayTracker) {
            DisplayTracker displayTracker,
            WakefulnessLifecycle wakefulness) {
        mContext = context;
        mSubscriptionManager = subscriptionManager;
        mUserTracker = userTracker;
@@ -2411,6 +2416,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                .collect(Collectors.toSet());
        mTaskStackChangeListeners = taskStackChangeListeners;
        mActivityTaskManager = activityTaskManagerService;
        mWakefulness = wakefulness;
        mDisplayTracker = displayTracker;
        mDisplayTracker.addDisplayChangeCallback(mDisplayCallback, mainExecutor);

@@ -3213,7 +3219,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                && faceAndFpNotAuthenticated
                && !mGoingToSleep
                && isPostureAllowedForFaceAuth
                && mAllowedDisplayStateForFaceAuth;
                && mAllowedDisplayStateWhileAwakeForFaceAuth;

        // Aggregate relevant fields for debug logging.
        logListenerModelData(
@@ -3221,7 +3227,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    System.currentTimeMillis(),
                    user,
                    shouldListen,
                    mAllowedDisplayStateForFaceAuth,
                    mAllowedDisplayStateWhileAwakeForFaceAuth,
                    mAlternateBouncerShowing,
                    mAuthInterruptActive,
                    biometricEnabledForUser,
+63 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWE
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
import static android.telephony.SubscriptionManager.DATA_ROAMING_DISABLE;
import static android.telephony.SubscriptionManager.NAME_SOURCE_CARRIER_ID;

import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
@@ -38,11 +39,17 @@ import static com.android.keyguard.KeyguardUpdateMonitor.BIOMETRIC_STATE_CANCELL
import static com.android.keyguard.KeyguardUpdateMonitor.DEFAULT_CANCEL_SIGNAL_TIMEOUT;
import static com.android.keyguard.KeyguardUpdateMonitor.HAL_POWER_PRESS_TIMEOUT;
import static com.android.keyguard.KeyguardUpdateMonitor.getCurrentUser;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_WAKING;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_CLOSED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_OPENED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -139,6 +146,7 @@ import com.android.systemui.biometrics.AuthController;
import com.android.systemui.biometrics.FingerprintInteractiveToAuthProvider;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.settings.FakeDisplayTracker;
@@ -276,6 +284,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    private TaskStackChangeListeners mTaskStackChangeListeners;
    @Mock
    private IActivityTaskManager mActivityTaskManager;
    @Mock
    private WakefulnessLifecycle mWakefulness;

    private List<FaceSensorPropertiesInternal> mFaceSensorProperties;
    private List<FingerprintSensorPropertiesInternal> mFingerprintSensorProperties;
@@ -2999,8 +3009,57 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // THEN face listening is stopped.
        verify(faceCancel).cancel();
        verify(callback).onBiometricRunningStateChanged(
                eq(false), eq(BiometricSourceType.FACE)); // beverlyt
                eq(false), eq(BiometricSourceType.FACE));
    }

    @Test
    public void onDisplayOff_whileAsleep_doesNotStopFaceAuth() throws RemoteException {
        enableStopFaceAuthOnDisplayOff();
        when(mWakefulness.getWakefulness()).thenReturn(WAKEFULNESS_ASLEEP);

        // GIVEN device is listening for face
        mKeyguardUpdateMonitor.setKeyguardShowing(true, false);
        mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);
        mTestableLooper.processAllMessages();
        verifyFaceAuthenticateCall();

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

        // WHEN the default display state changes to OFF
        triggerDefaultDisplayStateChangeToOff();

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

    @Test
    public void onDisplayOff_whileWaking_doesNotStopFaceAuth() throws RemoteException {
        enableStopFaceAuthOnDisplayOff();
        when(mWakefulness.getWakefulness()).thenReturn(WAKEFULNESS_WAKING);

        // GIVEN device is listening for face
        mKeyguardUpdateMonitor.setKeyguardShowing(true, false);
        mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);
        mTestableLooper.processAllMessages();
        verifyFaceAuthenticateCall();

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

        // WHEN the default display state changes to OFF
        triggerDefaultDisplayStateChangeToOff();

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

    private void triggerDefaultDisplayStateChangeToOn() {
@@ -3307,6 +3366,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        clearInvocations(mStatusBarStateController);
        mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mContext);
        setupBiometrics(mKeyguardUpdateMonitor);
        when(mWakefulness.getWakefulness()).thenReturn(WAKEFULNESS_AWAKE);
        assertThat(mDisplayTracker.getDisplayCallbacks().size()).isEqualTo(1);
    }

@@ -3387,7 +3447,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
                    mPackageManager, mFaceManager, mFingerprintManager, mBiometricManager,
                    mFaceWakeUpTriggersConfig, mDevicePostureController,
                    Optional.of(mInteractiveToAuthProvider),
                    mTaskStackChangeListeners, mActivityTaskManager, mDisplayTracker);
                    mTaskStackChangeListeners, mActivityTaskManager, mDisplayTracker,
                    mWakefulness);
            setStrongAuthTracker(KeyguardUpdateMonitorTest.this.mStrongAuthTracker);
        }