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

Commit 861744dd authored by Ilya Matyukhin's avatar Ilya Matyukhin
Browse files

Refactor FingerprintStateListener to BiometricStateListener

This will allow to reuse the logic around onEnrollmentsChanged for face.

Face doesn't have a mechanism to cache the enrollment state, and there
is nothing fingerprint-specific in FingerprintStateListener, so it's an
obvious choice the refactor this class to support all biometrics.

Bug: 221037350
Test: atest com.android.server.biometrics
Test: atest com.android.systemui.biometrics
Test: atest KeyguardUpdateMonitorTest
Test: com.android.server.biometrics
Change-Id: Id039136c8fb01627de5a0f3e92d2f9fd89500539
parent 0ae3528d
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.hardware.fingerprint;
package android.hardware.biometrics;

import android.annotation.IntDef;

@@ -22,10 +22,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Interface for handling state changes in fingerprint-related events.
 * Interface for handling state changes in biometric sensors.
 * @hide
 */
public abstract class FingerprintStateListener extends IFingerprintStateListener.Stub {
public abstract class BiometricStateListener extends IBiometricStateListener.Stub {
    // Operation has not started yet.
    public static final int STATE_IDLE = 0;

@@ -43,16 +43,19 @@ public abstract class FingerprintStateListener extends IFingerprintStateListener

    @IntDef({STATE_IDLE, STATE_ENROLLING, STATE_KEYGUARD_AUTH, STATE_BP_AUTH, STATE_AUTH_OTHER})
    @Retention(RetentionPolicy.SOURCE)
    public @interface State {}
    public @interface State {
    }

    /**
     * Defines behavior in response to state update
     * @param newState new state of fingerprint sensor
     * @param newState new state of the biometric sensor
     */
    public void onStateChanged(@FingerprintStateListener.State int newState) {}
    public void onStateChanged(@BiometricStateListener.State int newState) {
    }

    /**
     * Invoked when enrollment state changes for the specified user
     */
    public void onEnrollmentsChanged(int userId, int sensorId, boolean hasEnrollments) {}
    public void onEnrollmentsChanged(int userId, int sensorId, boolean hasEnrollments) {
    }
}
+5 −7
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -13,16 +13,14 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.hardware.fingerprint;

import android.hardware.fingerprint.Fingerprint;
package android.hardware.biometrics;

/**
 * Communication channel for FingerprintManager to register the FingerprintStateListener
 * in FingerprintService.
 * Communication channel between <Biometric>Manager and <Biometric>Service for passing the
 * listener.
 * @hide
 */
oneway interface IFingerprintStateListener {
oneway interface IBiometricStateListener {
    void onStateChanged(int newState);
    void onEnrollmentsChanged(int userId, int sensorId, boolean hasEnrollments);
}
+5 −4
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricFingerprintConstants;
import android.hardware.biometrics.BiometricPrompt;
import android.hardware.biometrics.BiometricStateListener;
import android.hardware.biometrics.BiometricTestSession;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.hardware.biometrics.SensorProperties;
@@ -918,13 +919,13 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing


    /**
     * Forwards FingerprintStateListener to FingerprintService
     * @param listener new FingerprintStateListener being added
     * Forwards BiometricStateListener to FingerprintService
     * @param listener new BiometricStateListener being added
     * @hide
     */
    public void registerFingerprintStateListener(@NonNull FingerprintStateListener listener) {
    public void registerBiometricStateListener(@NonNull BiometricStateListener listener) {
        try {
            mService.registerFingerprintStateListener(listener);
            mService.registerBiometricStateListener(listener);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −3
Original line number Diff line number Diff line
@@ -17,13 +17,13 @@ package android.hardware.fingerprint;

import android.hardware.biometrics.IBiometricSensorReceiver;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.hardware.biometrics.IBiometricStateListener;
import android.hardware.biometrics.IInvalidationCallback;
import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
import android.hardware.fingerprint.IFingerprintClientActiveCallback;
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback;
import android.hardware.fingerprint.IFingerprintServiceReceiver;
import android.hardware.fingerprint.IFingerprintStateListener;
import android.hardware.fingerprint.IUdfpsOverlayController;
import android.hardware.fingerprint.ISidefpsController;
import android.hardware.fingerprint.Fingerprint;
@@ -169,6 +169,6 @@ interface IFingerprintService {
    // Sets the controller for managing the SideFPS overlay.
    void setSidefpsController(in ISidefpsController controller);

    // Registers FingerprintStateListener in list stored by FingerprintService.
    void registerFingerprintStateListener(IFingerprintStateListener listener);
    // Registers BiometricStateListener.
    void registerBiometricStateListener(IBiometricStateListener listener);
}
+3 −3
Original line number Diff line number Diff line
@@ -2194,7 +2194,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }

        // don't start running fingerprint until they're registered
        if (!mAuthController.areAllAuthenticatorsRegistered()) {
        if (!mAuthController.areAllFingerprintAuthenticatorsRegistered()) {
            return;
        }
        final boolean shouldListenForFingerprint = shouldListenForFingerprint(isUdfpsSupported());
@@ -3619,8 +3619,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId);
            BiometricAuthenticated fingerprint = mUserFingerprintAuthenticated.get(userId);
            pw.println("  Fingerprint state (user=" + userId + ")");
            pw.println("    areAllAuthenticatorsRegistered="
                    + mAuthController.areAllAuthenticatorsRegistered());
            pw.println("    areAllFpAuthenticatorsRegistered="
                    + mAuthController.areAllFingerprintAuthenticatorsRegistered());
            pw.println("    allowed="
                    + (fingerprint != null
                            && isUnlockingWithBiometricAllowed(fingerprint.mIsStrongBiometric)));
Loading