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

Commit f82f206b authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Add getStrength() to BiometricEnrollmentStatus" into main

parents aac730e0 00db992f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5165,6 +5165,7 @@ package android.hardware.biometrics {
  @FlaggedApi("android.hardware.biometrics.move_fm_api_to_bm") public final class BiometricEnrollmentStatus {
    method @IntRange(from=0) public int getEnrollmentCount();
    method public int getStrength();
  }
  public class BiometricManager {
+17 −3
Original line number Diff line number Diff line
@@ -30,15 +30,29 @@ import java.util.Objects;
@SystemApi
@FlaggedApi(Flags.FLAG_MOVE_FM_API_TO_BM)
public final class BiometricEnrollmentStatus {

    private final @BiometricManager.Authenticators.Types int mStrength;
    private final int mEnrollmentCount;

    /**
     * @hide
     */
    public BiometricEnrollmentStatus(int enrollmentCount) {
    public BiometricEnrollmentStatus(@BiometricManager.Authenticators.Types int strength,
            int enrollmentCount) {
        mStrength = strength;
        mEnrollmentCount = enrollmentCount;
    }

    /**
     * Returns the strength of enrolled biometric for the associated modality.
     *
     * @return The strength of enrolled biometric.
     */
    @BiometricManager.Authenticators.Types
    public int getStrength() {
        return mStrength;
    }

    /**
     * Returns the number of enrolled biometric for the associated modality.
     *
@@ -51,7 +65,7 @@ public final class BiometricEnrollmentStatus {

    @Override
    public int hashCode() {
        return Objects.hash(mEnrollmentCount);
        return Objects.hash(mStrength, mEnrollmentCount);
    }

    @Override
@@ -59,6 +73,6 @@ public final class BiometricEnrollmentStatus {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        BiometricEnrollmentStatus other = (BiometricEnrollmentStatus) obj;
        return mEnrollmentCount == other.mEnrollmentCount;
        return mStrength == other.mStrength && mEnrollmentCount == other.mEnrollmentCount;
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public final class BiometricEnrollmentStatusInternal implements Parcelable {
    }

    private BiometricEnrollmentStatusInternal(Parcel in) {
        this(in.readInt(), new BiometricEnrollmentStatus(in.readInt()));
        this(in.readInt(), new BiometricEnrollmentStatus(in.readInt(), in.readInt()));
    }

    @NonNull
@@ -81,6 +81,7 @@ public final class BiometricEnrollmentStatusInternal implements Parcelable {
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mModality);
        dest.writeInt(mStatus.getStrength());
        dest.writeInt(mStatus.getEnrollmentCount());
    }

@@ -97,12 +98,13 @@ public final class BiometricEnrollmentStatusInternal implements Parcelable {
        } else if (mModality == BiometricManager.TYPE_FACE) {
            modality = "Face";
        }
        return "Modality: " + modality + ", Enrolled Count: " + mStatus.getEnrollmentCount();
        return "Modality: " + modality + ", Strength: " + mStatus.getStrength()
                + ", Enrolled Count: " + mStatus.getEnrollmentCount();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mModality, mStatus.getEnrollmentCount());
        return Objects.hash(mModality, mStatus.getStrength(), mStatus.getEnrollmentCount());
    }

    @Override
@@ -111,6 +113,7 @@ public final class BiometricEnrollmentStatusInternal implements Parcelable {
        if (obj == null || getClass() != obj.getClass()) return false;
        BiometricEnrollmentStatusInternal other = (BiometricEnrollmentStatusInternal) obj;
        return mModality == other.mModality
                && mStatus.getStrength() == other.mStatus.getStrength()
                && mStatus.getEnrollmentCount() == other.mStatus.getEnrollmentCount();
    }
}
+11 −4
Original line number Diff line number Diff line
@@ -450,7 +450,10 @@ public class AuthService extends SystemService {
                    if (!fpProps.isEmpty()) {
                        int fpCount = fingerprintService.getEnrolledFingerprints(userId,
                                opPackageName, getContext().getAttributionTag()).size();
                        BiometricEnrollmentStatus status = new BiometricEnrollmentStatus(fpCount);
                        int strength = Utils.propertyStrengthToAuthenticatorStrength(
                                fpProps.getFirst().sensorStrength);
                        BiometricEnrollmentStatus status = new BiometricEnrollmentStatus(strength,
                                fpCount);
                        enrollmentStatusList.add(
                                new BiometricEnrollmentStatusInternal(
                                        BiometricManager.TYPE_FINGERPRINT, status));
@@ -466,9 +469,13 @@ public class AuthService extends SystemService {
                    final List<FaceSensorPropertiesInternal> faceProps =
                            faceService.getSensorPropertiesInternal(opPackageName);
                    if (!faceProps.isEmpty()) {
                        int faceCount = faceService.getEnrolledFaces(faceProps.getFirst().sensorId,
                                userId, opPackageName).size();
                        BiometricEnrollmentStatus status = new BiometricEnrollmentStatus(faceCount);
                        FaceSensorPropertiesInternal faceProp = faceProps.getFirst();
                        int faceCount = faceService.getEnrolledFaces(faceProp.sensorId, userId,
                                opPackageName).size();
                        int strength = Utils.propertyStrengthToAuthenticatorStrength(
                                faceProp.sensorStrength);
                        BiometricEnrollmentStatus status = new BiometricEnrollmentStatus(strength,
                                faceCount);
                        enrollmentStatusList.add(
                                new BiometricEnrollmentStatusInternal(
                                        BiometricManager.TYPE_FACE, status));
+11 −2
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.biometrics.AuthenticationStateListener;
import android.hardware.biometrics.BiometricEnrollmentStatusInternal;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
import android.hardware.biometrics.IBiometricService;
@@ -526,7 +527,7 @@ public class AuthServiceTest {
        setInternalAndTestBiometricPermissions(mContext, true /* hasPermission */);
        List<FaceSensorPropertiesInternal> faceProps = List.of(new FaceSensorPropertiesInternal(
                0 /* id */,
                FaceSensorProperties.STRENGTH_STRONG,
                FaceSensorProperties.STRENGTH_CONVENIENCE,
                1 /* maxTemplatesAllowed */,
                new ArrayList<>() /* componentInfo */,
                FaceSensorProperties.TYPE_UNKNOWN,
@@ -548,9 +549,17 @@ public class AuthServiceTest {
        mAuthService = new AuthService(mContext, mInjector);
        mAuthService.onStart();

        final List<BiometricEnrollmentStatusInternal> statusList =
                mAuthService.mImpl.getEnrollmentStatusList(TEST_OP_PACKAGE_NAME);

        waitForIdle();
        assertEquals(BiometricManager.Authenticators.BIOMETRIC_STRONG, statusList.get(
                0).getStatus().getStrength());
        assertEquals(BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE, statusList.get(
                1).getStatus().getStrength());

        //getStatus().getEnrollmentCount() is tested in BiometricSimpleTests.

        verify(mFaceService).getEnrolledFaces(eq(0), eq(mUserId), eq(TEST_OP_PACKAGE_NAME));
        verify(mFingerprintService).getEnrolledFingerprints(eq(mUserId), eq(TEST_OP_PACKAGE_NAME),
                eq("tag"));