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

Commit 07cf6abe authored by Shawn Lin's avatar Shawn Lin
Browse files

Add metrics for biometrics enumeration and unenrollment misalignment

1. Add a new metric for unenroll
  - Add a reason filed to RemovalClient ctr. Currently, only "user
    request" and "dangling hal" will create a RemovalClient to delete a
    enrollment. "dangling framework" will be done in
    InternalEnumerationClient.
2. Add a new metric for enumeration
3. Add a new template id field to enroll metric

Bug: 345478069
Test: atest FingerprintInternalCleanupClientTest
            FingerprintInternalEnumerateClientTest
            FingerprintRemovalClientTest
            FingerprintEnrollClientTest
            FaceInternalEnumerateClientTest
            FaceRemovalClientTest
            FaceEnrollClientTest
            BiometricSchedulerTest
            BiometricLoggerTest

Flag: EXEMPT adding logs
Change-Id: Iac113ee2d7994505de752fb04648be8a58dbf07f
parent b350432e
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ public class BiometricFrameworkStatsLogger {
    /** {@see FrameworkStatsLog.BIOMETRIC_ENROLLED}. */
    public void enroll(int statsModality, int statsAction, int statsClient,
            int targetUserId, long latency, boolean enrollSuccessful, float ambientLightLux,
            int source) {
            int source, int templateId) {
        FrameworkStatsLog.write(FrameworkStatsLog.BIOMETRIC_ENROLLED,
                statsModality,
                targetUserId,
@@ -124,7 +124,27 @@ public class BiometricFrameworkStatsLogger {
                -1, /* sensorId */
                ambientLightLux,
                source,
                -1 /* templateId*/);
                templateId);
    }

    /** {@see FrameworkStatsLog.BIOMETRIC_UNENROLLED} */
    public void unenrolled(int statsModality, int targetUserId, int reason, int templateId) {
        FrameworkStatsLog.write(FrameworkStatsLog.BIOMETRIC_UNENROLLED,
                statsModality,
                targetUserId,
                reason,
                templateId);
    }

    /** {@see FrameworkStatsLog.BIOMETRIC_ENUMERATED} */
    public void enumerated(int statsModality, int targetUserId, int result, int[] templateIdsHal,
            int[] templateIdsFramework) {
        FrameworkStatsLog.write(FrameworkStatsLog.BIOMETRIC_ENUMERATED,
                statsModality,
                targetUserId,
                result,
                templateIdsHal,
                templateIdsFramework);
    }

    /** {@see FrameworkStatsLog.BIOMETRIC_ERROR_OCCURRED}. */
+50 −3
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import com.android.internal.util.FrameworkStatsLog;
import com.android.server.biometrics.AuthenticationStatsCollector;
import com.android.server.biometrics.Utils;

import java.util.Arrays;

/**
 * Logger for all reported Biometric framework events.
 */
@@ -254,7 +256,7 @@ public class BiometricLogger {

    /** Log enrollment outcome. */
    public void logOnEnrolled(int targetUserId, long latency, boolean enrollSuccessful,
            int source) {
            int source, int templateId) {
        if (!mShouldLogMetrics) {
            return;
        }
@@ -265,7 +267,8 @@ public class BiometricLogger {
                    + ", Client: " + mStatsClient
                    + ", Latency: " + latency
                    + ", Lux: " + mALSProbe.getMostRecentLux()
                    + ", Success: " + enrollSuccessful);
                    + ", Success: " + enrollSuccessful
                    + ", TemplateId: " + templateId);
        } else {
            Slog.v(TAG, "Enroll latency: " + latency);
        }
@@ -275,7 +278,51 @@ public class BiometricLogger {
        }

        mSink.enroll(mStatsModality, mStatsAction, mStatsClient,
                targetUserId, latency, enrollSuccessful, mALSProbe.getMostRecentLux(), source);
                targetUserId, latency, enrollSuccessful, mALSProbe.getMostRecentLux(), source,
                templateId);
    }

    /** Log un-enrollment. */
    public void logOnUnEnrolled(int targetUserId, int reason, int templateId) {
        if (!mShouldLogMetrics) {
            return;
        }

        if (DEBUG) {
            Slog.v(TAG, "UnEnrolled! Modality: " + mStatsModality
                    + ", User: " + targetUserId
                    + ", reason: " + reason
                    + ", templateId: " + templateId);
        }

        if (shouldSkipLogging()) {
            return;
        }

        mSink.unenrolled(mStatsModality, targetUserId, reason, templateId);
    }

    /** Log enumeration. */
    public void logOnEnumerated(int targetUserId, int result, int[] templateIdsHal,
            int[] templateIdsFramework) {
        if (!mShouldLogMetrics) {
            return;
        }

        if (DEBUG) {
            Slog.v(TAG, "Enumerated! Modality: " + mStatsModality
                    + ", User: " + targetUserId
                    + ", result: " + result
                    + ", templateIdsHal: " + Arrays.toString(templateIdsHal)
                    + ", templateIdsFramework: " + Arrays.toString(templateIdsFramework));
        }

        if (shouldSkipLogging()) {
            return;
        }

        mSink.enumerated(mStatsModality, targetUserId, result, templateIdsHal,
                templateIdsFramework);
    }

    /** Report unexpected enrollment reported by the HAL. */
+2 −2
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public abstract class EnrollClient<T> extends AcquisitionClient<T> implements En
            mBiometricUtils.addBiometricForUser(getContext(), getTargetUserId(), identifier);
            getLogger().logOnEnrolled(getTargetUserId(),
                    System.currentTimeMillis() - mEnrollmentStartTimeMs,
                    true /* enrollSuccessful */, mEnrollReason);
                    true /* enrollSuccessful */, mEnrollReason, identifier.getBiometricId());
            mCallback.onClientFinished(this, true /* success */);
        }
        notifyUserActivity();
@@ -123,7 +123,7 @@ public abstract class EnrollClient<T> extends AcquisitionClient<T> implements En
    public void onError(int error, int vendorCode) {
        getLogger().logOnEnrolled(getTargetUserId(),
                System.currentTimeMillis() - mEnrollmentStartTimeMs,
                false /* enrollSuccessful */, mEnrollReason);
                false /* enrollSuccessful */, mEnrollReason, -1 /* templateId */);
        super.onError(error, vendorCode);
    }

+4 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.biometrics.sensors;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.os.Build;
import android.os.IBinder;
import android.util.Slog;
@@ -135,7 +136,7 @@ public abstract class InternalCleanupClient<S extends BiometricAuthenticator.Ide
            Supplier<T> lazyDaemon, IBinder token, int biometricId, int userId, String owner,
            BiometricUtils<S> utils, int sensorId,
            @NonNull BiometricLogger logger, @NonNull BiometricContext biometricContext,
            Map<Integer, Long> authenticatorIds);
            Map<Integer, Long> authenticatorIds, int reason);

    protected InternalCleanupClient(@NonNull Context context, @NonNull Supplier<T> lazyDaemon,
            int userId, @NonNull String owner, int sensorId,
@@ -158,7 +159,8 @@ public abstract class InternalCleanupClient<S extends BiometricAuthenticator.Ide
        mCurrentTask = getRemovalClient(getContext(), mLazyDaemon, getToken(),
                template.mIdentifier.getBiometricId(), template.mUserId,
                getContext().getPackageName(), mBiometricUtils, getSensorId(),
                getLogger(), getBiometricContext(), mAuthenticatorIds);
                getLogger(), getBiometricContext(), mAuthenticatorIds,
                BiometricsProtoEnums.UNENROLL_REASON_DANGLING_HAL);

        getLogger().logUnknownEnrollmentInHal();

+46 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.biometrics.sensors;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.os.IBinder;
import android.util.Slog;

@@ -46,6 +47,10 @@ public abstract class InternalEnumerateClient<T> extends HalClientMonitor<T>
    // List of templates to remove from the HAL
    private List<BiometricAuthenticator.Identifier> mUnknownHALTemplates = new ArrayList<>();
    private final int mInitialEnrolledSize;
    private final int[] mEnrolledIdsFrameworkArray;
    private final List<Integer> mEnrolledIdsHalList = new ArrayList<>();
    private boolean mIsDanglingFramework;
    private boolean mIsDanglingHal;

    protected InternalEnumerateClient(@NonNull Context context, @NonNull Supplier<T> lazyDaemon,
            @NonNull IBinder token, int userId, @NonNull String owner,
@@ -60,14 +65,26 @@ public abstract class InternalEnumerateClient<T> extends HalClientMonitor<T>
        mEnrolledList = enrolledList;
        mInitialEnrolledSize = mEnrolledList.size();
        mUtils = utils;
        // Record ids from frameworks for metrics
        mEnrolledIdsFrameworkArray = new int[mInitialEnrolledSize];
        for (int i = 0; i < mInitialEnrolledSize; i++) {
            mEnrolledIdsFrameworkArray[i] = mEnrolledList.get(i).getBiometricId();
        }
    }

    @Override
    public void onEnumerationResult(BiometricAuthenticator.Identifier identifier,
            int remaining) {
        if (identifier != null) {
            // Record ids from hal for metrics
            mEnrolledIdsHalList.add(identifier.getBiometricId());
        }
        handleEnumeratedTemplate(identifier);
        if (remaining == 0) {
            mIsDanglingHal = !mUnknownHALTemplates.isEmpty();
            mIsDanglingFramework = !mEnrolledList.isEmpty();
            doTemplateCleanup();
            logEnumerationResult();
            mCallback.onClientFinished(this, true /* success */);
        }
    }
@@ -123,7 +140,9 @@ public abstract class InternalEnumerateClient<T> extends HalClientMonitor<T>
                    + identifier.getBiometricId() + " " + identifier.getName());
            mUtils.removeBiometricForUser(getContext(),
                    getTargetUserId(), identifier.getBiometricId());

            getLogger().logOnUnEnrolled(getTargetUserId(),
                    BiometricsProtoEnums.UNENROLL_REASON_DANGLING_FRAMEWORK,
                    identifier.getBiometricId());
            getLogger().logUnknownEnrollmentInFramework();
        }

@@ -134,6 +153,32 @@ public abstract class InternalEnumerateClient<T> extends HalClientMonitor<T>
        mEnrolledList.clear();
    }

    private void logEnumerationResult() {
        final int result;
        if (mIsDanglingFramework && mIsDanglingHal) {
            result = BiometricsProtoEnums.ENUMERATION_RESULT_DANGLING_BOTH;
        } else if (mIsDanglingFramework) {
            result = BiometricsProtoEnums.ENUMERATION_RESULT_DANGLING_FRAMEWORK;
        } else if (mIsDanglingHal) {
            result = BiometricsProtoEnums.ENUMERATION_RESULT_DANGLING_HAL;
        } else {
            result = BiometricsProtoEnums.ENUMERATION_RESULT_OK;
        }

        final int[] idsHalArray = listToArray(mEnrolledIdsHalList);
        getLogger().logOnEnumerated(
                getTargetUserId(), result, idsHalArray, mEnrolledIdsFrameworkArray);
    }

    private int[] listToArray(List<Integer> ids) {
        final int size = ids.size();
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = ids.get(i);
        }
        return array;
    }

    public List<BiometricAuthenticator.Identifier> getUnknownHALTemplates() {
        return mUnknownHALTemplates;
    }
Loading