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

Commit cf61afd7 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

9/n: Remove MetricsLogger and Constants from biometrics

1) MetricsLogger is succeeded by biometric atoms
2) As a result, constants can be deleted as well

This removes unnecessary "coupling interfaces" in the ClientMonitor
subclasses.

Bug: 157790417
Test: Enroll, auth, remove, not affected

Change-Id: I2aab38c2f24747bb983bd7250ddafb383a2f9518
parent a8e084c6
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import java.util.ArrayList;
 */
public abstract class AuthenticationClient extends ClientMonitor {

    private static final String TAG = "Biometrics/AuthenticationClient";

    private final boolean mIsStrongBiometric;
    private final long mOpId;
    private final boolean mRequireConfirmation;
@@ -56,7 +58,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
        try {
            mActivityTaskManager.registerTaskStackListener(mTaskStackListener);
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "Could not register task stack listener", e);
            Slog.e(TAG, "Could not register task stack listener", e);
        }
    }

@@ -68,17 +70,17 @@ public abstract class AuthenticationClient extends ClientMonitor {
        try {
            mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener);
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "Could not unregister task stack listener", e);
            Slog.e(TAG, "Could not unregister task stack listener", e);
        }
    }

    public AuthenticationClient(Context context, Constants constants,
    public AuthenticationClient(Context context,
            BiometricServiceBase.DaemonWrapper daemon, IBinder token,
            ClientMonitorCallbackConverter listener, int targetUserId, int groupId, long opId,
            boolean restricted, String owner, int cookie, boolean requireConfirmation, int sensorId,
            boolean isStrongBiometric, int statsModality, int statsClient,
            TaskStackListener taskStackListener, LockoutTracker lockoutTracker, Surface surface) {
        super(context, constants, daemon, token, listener, targetUserId, groupId,
        super(context, daemon, token, listener, targetUserId, groupId,
                restricted, owner, cookie, sensorId, statsModality,
                BiometricsProtoEnums.ACTION_AUTHENTICATE, statsClient);
        mIsStrongBiometric = isStrongBiometric;
@@ -139,11 +141,10 @@ public abstract class AuthenticationClient extends ClientMonitor {

        final ClientMonitorCallbackConverter listener = getListener();

        mMetricsLogger.action(mConstants.actionBiometricAuth(), authenticated);
        boolean result = false;

        try {
            if (DEBUG) Slog.v(getLogTag(), "onAuthenticated(" + authenticated + ")"
            if (DEBUG) Slog.v(TAG, "onAuthenticated(" + authenticated + ")"
                    + ", ID:" + identifier.getBiometricId()
                    + ", Owner: " + getOwnerString()
                    + ", isBP: " + isBiometricPrompt()
@@ -172,7 +173,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
                    if (mIsStrongBiometric) {
                        KeyStore.getInstance().addAuthToken(byteToken);
                    } else {
                        Slog.d(getLogTag(), "Skipping addAuthToken");
                        Slog.d(TAG, "Skipping addAuthToken");
                    }

                    try {
@@ -186,11 +187,11 @@ public abstract class AuthenticationClient extends ClientMonitor {
                                    byteToken, getTargetUserId(), mIsStrongBiometric);
                        }
                    } catch (RemoteException e) {
                        Slog.e(getLogTag(), "Remote exception", e);
                        Slog.e(TAG, "Remote exception", e);
                    }
                } else {
                    // Client not listening
                    Slog.w(getLogTag(), "Client not listening");
                    Slog.w(TAG, "Client not listening");
                    result = true;
                }
            } else {
@@ -212,7 +213,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
                result = lockoutMode != LockoutTracker.LOCKOUT_NONE; // in a lockout mode
            }
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "Remote exception", e);
            Slog.e(TAG, "Remote exception", e);
            result = true;
        }
        return result;
@@ -228,14 +229,13 @@ public abstract class AuthenticationClient extends ClientMonitor {
            mStartTimeMs = System.currentTimeMillis();
            final int result = getDaemonWrapper().authenticate(mOpId, getGroupId(), mSurface);
            if (result != 0) {
                Slog.w(getLogTag(), "startAuthentication failed, result=" + result);
                mMetricsLogger.histogram(mConstants.tagAuthStartError(), result);
                Slog.w(TAG, "startAuthentication failed, result=" + result);
                onError(BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
                return result;
            }
            if (DEBUG) Slog.w(getLogTag(), "client " + getOwnerString() + " is authenticating...");
            if (DEBUG) Slog.w(TAG, "client " + getOwnerString() + " is authenticating...");
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "startAuthentication failed", e);
            Slog.e(TAG, "startAuthentication failed", e);
            return ERROR_ESRCH;
        }
        return 0; // success
@@ -244,7 +244,7 @@ public abstract class AuthenticationClient extends ClientMonitor {
    @Override
    public int stop(boolean initiatedByClient) {
        if (mAlreadyCancelled) {
            Slog.w(getLogTag(), "stopAuthentication: already cancelled!");
            Slog.w(TAG, "stopAuthentication: already cancelled!");
            return 0;
        }

@@ -253,13 +253,13 @@ public abstract class AuthenticationClient extends ClientMonitor {
        try {
            final int result = getDaemonWrapper().cancel();
            if (result != 0) {
                Slog.w(getLogTag(), "stopAuthentication failed, result=" + result);
                Slog.w(TAG, "stopAuthentication failed, result=" + result);
                return result;
            }
            if (DEBUG) Slog.w(getLogTag(), "client " + getOwnerString() +
            if (DEBUG) Slog.w(TAG, "client " + getOwnerString() +
                    " is no longer authenticating");
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "stopAuthentication failed", e);
            Slog.e(TAG, "stopAuthentication failed", e);
            return ERROR_ESRCH;
        }

@@ -270,20 +270,20 @@ public abstract class AuthenticationClient extends ClientMonitor {
    @Override
    public boolean onEnrollResult(BiometricAuthenticator.Identifier identifier,
            int remaining) {
        if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for authenticate!");
        if (DEBUG) Slog.w(TAG, "onEnrollResult() called for authenticate!");
        return true; // Invalid for Authenticate
    }

    @Override
    public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) {
        if (DEBUG) Slog.w(getLogTag(), "onRemoved() called for authenticate!");
        if (DEBUG) Slog.w(TAG, "onRemoved() called for authenticate!");
        return true; // Invalid for Authenticate
    }

    @Override
    public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier,
            int remaining) {
        if (DEBUG) Slog.w(getLogTag(), "onEnumerationResult() called for authenticate!");
        if (DEBUG) Slog.w(TAG, "onEnumerationResult() called for authenticate!");
        return true; // Invalid for Authenticate
    }
}
+1 −11
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import android.view.Surface;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.SystemService;
@@ -87,7 +86,6 @@ public abstract class BiometricServiceBase extends SystemService
    protected final IActivityTaskManager mActivityTaskManager;
    public final PowerManager mPowerManager;
    private final UserManager mUserManager;
    private final MetricsLogger mMetricsLogger;
    protected final BiometricTaskStackListener mTaskStackListener =
            new BiometricTaskStackListener();
    private final ResetClientStateRunnable mResetClientState = new ResetClientStateRunnable();
@@ -136,11 +134,6 @@ public abstract class BiometricServiceBase extends SystemService
     */
    protected abstract BiometricUtils getBiometricUtils();

    /**
     * @return the metrics constants for a biometric implementation.
     */
    protected abstract Constants getConstants();

    /**
     * @param userId
     * @return true if the enrollment limit has been reached.
@@ -354,7 +347,6 @@ public abstract class BiometricServiceBase extends SystemService
        mPowerManager = mContext.getSystemService(PowerManager.class);
        mUserManager = UserManager.get(mContext);
        mPerformanceTracker = PerformanceTracker.getInstanceForSensorId(getSensorId());
        mMetricsLogger = new MetricsLogger();
    }

    @Override
@@ -365,7 +357,6 @@ public abstract class BiometricServiceBase extends SystemService
    @Override
    public void serviceDied(long cookie) {
        Slog.e(getTag(), "HAL died");
        mMetricsLogger.count(getConstants().tagHalDied(), 1);
        mPerformanceTracker.incrementHALDeathCount();
        mCurrentUserId = UserHandle.USER_NULL;

@@ -554,7 +545,6 @@ public abstract class BiometricServiceBase extends SystemService
        }

        mHandler.post(() -> {
            mMetricsLogger.histogram(getConstants().tagAuthToken(), opId != 0L ? 1 : 0);
            startAuthentication(client, opPackageName);
        });
    }
@@ -931,7 +921,7 @@ public abstract class BiometricServiceBase extends SystemService
            final List<? extends BiometricAuthenticator.Identifier> enrolledList =
                    getEnrolledTemplates(userId);

            InternalCleanupClient client = new InternalCleanupClient(getContext(), getConstants(),
            InternalCleanupClient client = new InternalCleanupClient(getContext(),
                    getDaemonWrapper(), null /* serviceListener */, userId, userId,
                    restricted, getContext().getOpPackageName(), getSensorId(), statsModality(),
                    enrolledList, getBiometricUtils());
+11 −19
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Slog;

import com.android.internal.logging.MetricsLogger;

import java.util.ArrayList;
import java.util.NoSuchElementException;

@@ -37,6 +35,9 @@ import java.util.NoSuchElementException;
 * the biometric's HAL for the specific action (e.g. authenticate, enroll, enumerate, etc.).
 */
public abstract class ClientMonitor extends LoggableMonitor implements IBinder.DeathRecipient {

    private static final String TAG = "Biometrics/ClientMonitor";

    protected static final int ERROR_ESRCH = 3; // Likely HAL is dead. See errno.h.
    protected static final boolean DEBUG = BiometricServiceBase.DEBUG;
    private static final AudioAttributes FINGERPRINT_SONFICATION_ATTRIBUTES =
@@ -62,9 +63,6 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
    // is never 0.
    private final int mCookie;

    protected final MetricsLogger mMetricsLogger;
    protected final Constants mConstants;

    protected boolean mAlreadyCancelled;
    protected boolean mAlreadyDone;

@@ -79,14 +77,13 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
     * permission
     * @param owner name of the client that owns this
     */
    public ClientMonitor(Context context, Constants constants,
    public ClientMonitor(Context context,
            BiometricServiceBase.DaemonWrapper daemon, IBinder token,
            ClientMonitorCallbackConverter listener, int userId, int groupId,
            boolean restricted, String owner, int cookie, int sensorId, int statsModality,
            int statsAction, int statsClient) {
        super(statsModality, statsAction, statsClient);
        mContext = context;
        mConstants = constants;
        mDaemon = daemon;
        mToken = token;
        mListener = listener;
@@ -98,18 +95,13 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
        mSensorId = sensorId;
        mSuccessVibrationEffect = VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
        mErrorVibrationEffect = VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);
        mMetricsLogger = new MetricsLogger();
        try {
            if (token != null) {
                token.linkToDeath(this, 0);
            }
        } catch (RemoteException e) {
            Slog.w(getLogTag(), "caught remote exception in linkToDeath: ", e);
        }
            Slog.w(TAG, "caught remote exception in linkToDeath: ", e);
        }

    protected String getLogTag() {
        return mConstants.logTag();
    }

    public int getCookie() {
@@ -164,7 +156,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
    protected final boolean onAcquiredInternal(int acquiredInfo, int vendorCode,
            boolean shouldSend) {
        super.logOnAcquired(mContext, acquiredInfo, vendorCode, getTargetUserId());
        if (DEBUG) Slog.v(getLogTag(), "Acquired: " + acquiredInfo + " " + vendorCode
        if (DEBUG) Slog.v(TAG, "Acquired: " + acquiredInfo + " " + vendorCode
                + ", shouldSend: " + shouldSend);
        try {
            if (mListener != null && shouldSend) {
@@ -172,7 +164,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
            }
            return false; // acquisition continues...
        } catch (RemoteException e) {
            Slog.w(getLogTag(), "Failed to invoke sendAcquired", e);
            Slog.w(TAG, "Failed to invoke sendAcquired", e);
            return true;
        } finally {
            // Good scans will keep the device awake
@@ -195,7 +187,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
                mListener.onError(getSensorId(), getCookie(), error, vendorCode);
            }
        } catch (RemoteException e) {
            Slog.w(getLogTag(), "Failed to invoke sendError", e);
            Slog.w(TAG, "Failed to invoke sendError", e);
        }
        return true; // errors always remove current client
    }
@@ -206,7 +198,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
                mToken.unlinkToDeath(this, 0);
            } catch (NoSuchElementException e) {
                // TODO: remove when duplicate call bug is found
                Slog.e(getLogTag(), "destroy(): " + this + ":", new Exception("here"));
                Slog.e(TAG, "destroy(): " + this + ":", new Exception("here"));
            }
            mToken = null;
        }
@@ -220,7 +212,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D

    void binderDiedInternal(boolean clearListener) {
        // If the current client dies we should cancel the current operation.
        Slog.e(getLogTag(), "Binder died, cancelling client");
        Slog.e(TAG, "Binder died, cancelling client");
        stop(false /* initiatedByClient */);
        mToken = null;
        if (clearListener) {
@@ -232,7 +224,7 @@ public abstract class ClientMonitor extends LoggableMonitor implements IBinder.D
    protected void finalize() throws Throwable {
        try {
            if (mToken != null) {
                if (DEBUG) Slog.w(getLogTag(), "removing leaked reference: " + mToken);
                if (DEBUG) Slog.w(TAG, "removing leaked reference: " + mToken);
                onError(BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE,
                        0 /* vendorCode */);
            }
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.biometrics.sensors;

public interface Constants {
    /** The log tag */
    String logTag();

    /** Strings for MetricsLogger.count() and MetricsLogger.histogram() */
    String tagHalDied();
    String tagAuthToken();
    String tagAuthStartError();
    String tagEnrollStartError();
    String tagEnumerateStartError();
    String tagRemoveStartError();

    /** Integers for MetricsLogger.action() */
    int actionBiometricAuth();
    int actionBiometricEnroll();
}
 No newline at end of file
+15 −13
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ import java.util.Arrays;
 * A class to keep track of the enrollment state for a given client.
 */
public class EnrollClient extends ClientMonitor {

    private static final String TAG = "Biometrics/EnrollClient";

    private final byte[] mCryptoToken;
    private final BiometricUtils mBiometricUtils;
    private final int[] mDisabledFeatures;
@@ -44,13 +47,13 @@ public class EnrollClient extends ClientMonitor {

    private long mEnrollmentStartTimeMs;

    public EnrollClient(Context context, Constants constants,
    public EnrollClient(Context context,
            BiometricServiceBase.DaemonWrapper daemon, IBinder token,
            ClientMonitorCallbackConverter listener, int userId, int groupId,
            byte[] cryptoToken, boolean restricted, String owner, BiometricUtils utils,
            final int[] disabledFeatures, int timeoutSec, int statsModality,
            PowerManager powerManager, Surface surface, int sensorId, boolean shouldVibrate) {
        super(context, constants, daemon, token, listener, userId, groupId, restricted,
        super(context, daemon, token, listener, userId, groupId, restricted,
                owner, 0 /* cookie */, sensorId, statsModality, BiometricsProtoEnums.ACTION_ENROLL,
                BiometricsProtoEnums.CLIENT_UNKNOWN);
        mBiometricUtils = utils;
@@ -89,7 +92,7 @@ public class EnrollClient extends ClientMonitor {
        if (mShouldVibrate) {
            vibrateSuccess();
        }
        mMetricsLogger.action(mConstants.actionBiometricEnroll());

        try {
            final ClientMonitorCallbackConverter listener = getListener();
            if (listener != null) {
@@ -97,7 +100,7 @@ public class EnrollClient extends ClientMonitor {
            }
            return remaining == 0;
        } catch (RemoteException e) {
            Slog.w(getLogTag(), "Failed to notify EnrollResult:", e);
            Slog.w(TAG, "Failed to notify EnrollResult:", e);
            return true;
        }
    }
@@ -114,13 +117,12 @@ public class EnrollClient extends ClientMonitor {
            final int result = getDaemonWrapper().enroll(mCryptoToken, getGroupId(), mTimeoutSec,
                    disabledFeatures, mSurface);
            if (result != 0) {
                Slog.w(getLogTag(), "startEnroll failed, result=" + result);
                mMetricsLogger.histogram(mConstants.tagEnrollStartError(), result);
                Slog.w(TAG, "startEnroll failed, result=" + result);
                onError(BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
                return result;
            }
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "startEnroll failed", e);
            Slog.e(TAG, "startEnroll failed", e);
        }
        return 0; // success
    }
@@ -128,18 +130,18 @@ public class EnrollClient extends ClientMonitor {
    @Override
    public int stop(boolean initiatedByClient) {
        if (mAlreadyCancelled) {
            Slog.w(getLogTag(), "stopEnroll: already cancelled!");
            Slog.w(TAG, "stopEnroll: already cancelled!");
            return 0;
        }

        try {
            final int result = getDaemonWrapper().cancel();
            if (result != 0) {
                Slog.w(getLogTag(), "startEnrollCancel failed, result = " + result);
                Slog.w(TAG, "startEnrollCancel failed, result = " + result);
                return result;
            }
        } catch (RemoteException e) {
            Slog.e(getLogTag(), "stopEnrollment failed", e);
            Slog.e(TAG, "stopEnrollment failed", e);
        }
        mAlreadyCancelled = true;
        return 0;
@@ -147,21 +149,21 @@ public class EnrollClient extends ClientMonitor {

    @Override
    public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) {
        if (DEBUG) Slog.w(getLogTag(), "onRemoved() called for enroll!");
        if (DEBUG) Slog.w(TAG, "onRemoved() called for enroll!");
        return true; // Invalid for EnrollClient
    }

    @Override
    public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier,
            int remaining) {
        if (DEBUG) Slog.w(getLogTag(), "onEnumerationResult() called for enroll!");
        if (DEBUG) Slog.w(TAG, "onEnumerationResult() called for enroll!");
        return true; // Invalid for EnrollClient
    }

    @Override
    public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
            boolean authenticated, ArrayList<Byte> token) {
        if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for enroll!");
        if (DEBUG) Slog.w(TAG, "onAuthenticated() called for enroll!");
        return true; // Invalid for EnrollClient
    }

Loading