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

Commit 39a2b97c authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Use biometric onEnrollmentsChanged callback

Instead of manually querying enrollment (IPC) each
time we want to know.

Test: atest KeyguardUpdateMonitorTest
Fixes: 242022358
Change-Id: I20d697f81680af0a061faf9d6ffd0e68ddf22385
parent caf7be76
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -318,8 +318,7 @@ class ActiveUnlockConfig @Inject constructor(

        keyguardUpdateMonitor?.let {
            val anyFaceEnrolled = it.isFaceEnrolled
            val anyFingerprintEnrolled =
                    it.getCachedIsUnlockWithFingerprintPossible(
            val anyFingerprintEnrolled = it.isUnlockWithFingerprintPossible(
                    selectedUserInteractor.getSelectedUserId())
            val udfpsEnrolled = it.isUdfpsEnrolled

@@ -374,9 +373,8 @@ class ActiveUnlockConfig @Inject constructor(
            pw.println("   shouldRequestActiveUnlockOnUnlockIntentFromBiometricEnrollment=" +
                    "${shouldRequestActiveUnlockOnUnlockIntentFromBiometricEnrollment()}")
            pw.println("   faceEnrolled=${it.isFaceEnrolled}")
            pw.println("   fpEnrolled=${
                    it.getCachedIsUnlockWithFingerprintPossible(
                            selectedUserInteractor.getSelectedUserId())}")
            pw.println("   fpUnlockPossible=${
                it.isUnlockWithFingerprintPossible(selectedUserInteractor.getSelectedUserId())}")
            pw.println("   udfpsEnrolled=${it.isUdfpsEnrolled}")
        } ?: pw.println("   keyguardUpdateMonitor is uninitialized")
    }
+1 −1
Original line number Diff line number Diff line
@@ -755,7 +755,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        }
        mView.onResume(
                mSecurityModel.getSecurityMode(mSelectedUserInteractor.getSelectedUserId()),
                mKeyguardStateController.isFaceAuthEnabled());
                mKeyguardStateController.isFaceEnrolled());
    }

    /** Sets an initial message that would override the default message */
+14 −46
Original line number Diff line number Diff line
@@ -441,7 +441,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private int mFaceRunningState = BIOMETRIC_STATE_STOPPED;
    private boolean mIsDreaming;
    private boolean mLogoutEnabled;
    private boolean mIsFaceEnrolled;
    private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private int mPostureState = DEVICE_POSTURE_UNKNOWN;
    private FingerprintInteractiveToAuthProvider mFingerprintInteractiveToAuthProvider;
@@ -2083,7 +2082,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private boolean mFingerprintLockedOut;
    private boolean mFingerprintLockedOutPermanent;
    private boolean mFaceLockedOutPermanent;
    private final HashMap<Integer, Boolean> mIsUnlockWithFingerprintPossible = new HashMap<>();

    /**
     * When we receive a {@link android.content.Intent#ACTION_SIM_STATE_CHANGED} broadcast,
@@ -2701,16 +2699,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }
    }

    private void updateFaceEnrolled(int userId) {
        final Boolean isFaceEnrolled = isFaceSupported()
                && mBiometricEnabledForUser.get(userId)
                && mAuthController.isFaceAuthEnrolled(userId);
        if (mIsFaceEnrolled != isFaceEnrolled) {
            mLogger.logFaceEnrolledUpdated(mIsFaceEnrolled, isFaceEnrolled);
        }
        mIsFaceEnrolled = isFaceEnrolled;
    }

    private boolean isFaceSupported() {
        return mFaceManager != null && !mFaceSensorProperties.isEmpty();
    }
@@ -2749,11 +2737,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        return mAuthController.isSfpsSupported();
    }

    /**
     * @return true if there's at least one face enrolled for the given user.
     */
    public boolean isFaceEnrolled(int userId) {
        return mAuthController.isFaceAuthEnrolled(userId);
    }

    /**
     * @return true if there's at least one face enrolled
     */
    public boolean isFaceEnrolled() {
        return mIsFaceEnrolled;
        return isFaceEnrolled(mSelectedUserInteractor.getSelectedUserId());
    }

    private final UserTracker.Callback mUserChangedCallback = new UserTracker.Callback() {
@@ -3442,49 +3437,22 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    @SuppressLint("MissingPermission")
    @VisibleForTesting
    boolean isUnlockWithFingerprintPossible(int userId) {
        // TODO (b/242022358), make this rely on onEnrollmentChanged event and update it only once.
        boolean newFpEnrolled = isFingerprintSupported()
                && !isFingerprintDisabled(userId) && mFpm.hasEnrolledTemplates(userId);
        Boolean oldFpEnrolled = mIsUnlockWithFingerprintPossible.getOrDefault(userId, false);
        if (oldFpEnrolled != newFpEnrolled) {
            mLogger.logFpEnrolledUpdated(userId, oldFpEnrolled, newFpEnrolled);
        }
        mIsUnlockWithFingerprintPossible.put(userId, newFpEnrolled);
        return mIsUnlockWithFingerprintPossible.get(userId);
    }

    /**
     * Cached value for whether fingerprint is enrolled and possible to use for authentication.
     * Note: checking fingerprint enrollment directly with the AuthController requires an IPC.
     */
    public boolean getCachedIsUnlockWithFingerprintPossible(int userId) {
        return mIsUnlockWithFingerprintPossible.getOrDefault(userId, false);
    public boolean isUnlockWithFingerprintPossible(int userId) {
        return isFingerprintSupported()
                && !isFingerprintDisabled(userId) && mAuthController.isFingerprintEnrolled(userId);
    }

    /**
     * @deprecated This is being migrated to use modern architecture.
     */
    @VisibleForTesting
    @Deprecated
    private boolean isUnlockWithFacePossible(int userId) {
    public boolean isUnlockWithFacePossible(int userId) {
        if (isFaceAuthInteractorEnabled()) {
            return getFaceAuthInteractor() != null
                    && getFaceAuthInteractor().isFaceAuthEnabledAndEnrolled();
        }
        return isFaceAuthEnabledForUser(userId) && !isFaceDisabled(userId);
    }

    /**
     * If face hardware is available, user has enrolled and enabled auth via setting.
     *
     * @deprecated This is being migrated to use modern architecture.
     */
    @Deprecated
    public boolean isFaceAuthEnabledForUser(int userId) {
        // TODO (b/242022358), make this rely on onEnrollmentChanged event and update it only once.
        updateFaceEnrolled(userId);
        return mIsFaceEnrolled;
        return isFaceSupported() && isFaceEnrolled(userId) && !isFaceDisabled(userId);
    }

    private void notifyAboutEnrollmentChange(@BiometricAuthenticator.Modality int modality) {
+0 −13
Original line number Diff line number Diff line
@@ -660,19 +660,6 @@ constructor(@KeyguardUpdateMonitorLog private val logBuffer: LogBuffer) {
        )
    }

    fun logFpEnrolledUpdated(userId: Int, oldValue: Boolean, newValue: Boolean) {
        logBuffer.log(
            TAG,
            DEBUG,
            {
                int1 = userId
                bool1 = oldValue
                bool2 = newValue
            },
            { "Fp enrolled state changed for userId: $int1 old: $bool1, new: $bool2" }
        )
    }

    fun logTrustUsuallyManagedUpdated(
        userId: Int,
        oldValue: Boolean,
+1 −1
Original line number Diff line number Diff line
@@ -405,7 +405,7 @@ constructor(
    /** Whether we want to wait to show the bouncer in case passive auth succeeds. */
    private fun usePrimaryBouncerPassiveAuthDelay(): Boolean {
        val canRunFaceAuth =
            keyguardStateController.isFaceAuthEnabled &&
            keyguardStateController.isFaceEnrolled &&
                keyguardUpdateMonitor.isUnlockingWithBiometricAllowed(BiometricSourceType.FACE) &&
                keyguardUpdateMonitor.doesCurrentPostureAllowFaceAuth()
        val canRunActiveUnlock =
Loading