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 Original line 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 {
  @FlaggedApi("android.hardware.biometrics.move_fm_api_to_bm") public final class BiometricEnrollmentStatus {
    method @IntRange(from=0) public int getEnrollmentCount();
    method @IntRange(from=0) public int getEnrollmentCount();
    method public int getStrength();
  }
  }
  public class BiometricManager {
  public class BiometricManager {
+17 −3
Original line number Original line Diff line number Diff line
@@ -30,15 +30,29 @@ import java.util.Objects;
@SystemApi
@SystemApi
@FlaggedApi(Flags.FLAG_MOVE_FM_API_TO_BM)
@FlaggedApi(Flags.FLAG_MOVE_FM_API_TO_BM)
public final class BiometricEnrollmentStatus {
public final class BiometricEnrollmentStatus {

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


    /**
    /**
     * @hide
     * @hide
     */
     */
    public BiometricEnrollmentStatus(int enrollmentCount) {
    public BiometricEnrollmentStatus(@BiometricManager.Authenticators.Types int strength,
            int enrollmentCount) {
        mStrength = strength;
        mEnrollmentCount = enrollmentCount;
        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.
     * Returns the number of enrolled biometric for the associated modality.
     *
     *
@@ -51,7 +65,7 @@ public final class BiometricEnrollmentStatus {


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


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


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


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


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


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


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


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


        waitForIdle();
        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(mFaceService).getEnrolledFaces(eq(0), eq(mUserId), eq(TEST_OP_PACKAGE_NAME));
        verify(mFingerprintService).getEnrolledFingerprints(eq(mUserId), eq(TEST_OP_PACKAGE_NAME),
        verify(mFingerprintService).getEnrolledFingerprints(eq(mUserId), eq(TEST_OP_PACKAGE_NAME),
                eq("tag"));
                eq("tag"));