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

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

25/n: Make InternalCleanupClient generics/templates more correct

InternalCleanup previously did not enforce that the enrolledList passed
into each <Modality>InternalCleanup had the correct biometric type.
For example, a list of faces could be passed to fingerprint cleanup.
While nothing was wrong, it's a bit fragile. This can be more correct,
easier to read, and less prone to type errors if InternalCleanup is
templated on identifier subclass.

Test: Builds
Bug: 157790417
Change-Id: I2511d4cfe3f2b5471a3103532a6e47972acb3cfc
parent 1a8ab724
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -563,7 +563,8 @@ public abstract class BiometricServiceBase<T> extends SystemService
        });
        });
    }
    }


    protected void cleanupInternal(InternalCleanupClient<T> client) {
    protected void cleanupInternal(
            InternalCleanupClient<? extends BiometricAuthenticator.Identifier, T> client) {
        mHandler.post(() -> {
        mHandler.post(() -> {
            if (DEBUG) {
            if (DEBUG) {
                Slog.v(getTag(), "Cleaning up templates for user("
                Slog.v(getTag(), "Cleaning up templates for user("
+5 −7
Original line number Original line Diff line number Diff line
@@ -37,8 +37,8 @@ import java.util.List;
 * 2) The HAL and Framework are not in sync, and
 * 2) The HAL and Framework are not in sync, and
 * {@link #onRemoved(BiometricAuthenticator.Identifier, int)} returns true/
 * {@link #onRemoved(BiometricAuthenticator.Identifier, int)} returns true/
 */
 */
public abstract class InternalCleanupClient<T> extends ClientMonitor<T>
public abstract class InternalCleanupClient<S extends BiometricAuthenticator.Identifier, T>
        implements EnumerateConsumer, RemovalConsumer {
        extends ClientMonitor<T> implements EnumerateConsumer, RemovalConsumer {


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


@@ -57,7 +57,7 @@ public abstract class InternalCleanupClient<T> extends ClientMonitor<T>


    private final ArrayList<UserTemplate> mUnknownHALTemplates = new ArrayList<>();
    private final ArrayList<UserTemplate> mUnknownHALTemplates = new ArrayList<>();
    private final BiometricUtils mBiometricUtils;
    private final BiometricUtils mBiometricUtils;
    private final List<? extends BiometricAuthenticator.Identifier> mEnrolledList;
    private final List<S> mEnrolledList;
    private ClientMonitor<T> mCurrentTask;
    private ClientMonitor<T> mCurrentTask;


    private final FinishCallback mEnumerateFinishCallback = clientMonitor -> {
    private final FinishCallback mEnumerateFinishCallback = clientMonitor -> {
@@ -87,8 +87,7 @@ public abstract class InternalCleanupClient<T> extends ClientMonitor<T>


    protected abstract InternalEnumerateClient<T> getEnumerateClient(Context context,
    protected abstract InternalEnumerateClient<T> getEnumerateClient(Context context,
            LazyDaemon<T> lazyDaemon, IBinder token, int userId, String owner,
            LazyDaemon<T> lazyDaemon, IBinder token, int userId, String owner,
            List<? extends BiometricAuthenticator.Identifier> enrolledList, BiometricUtils utils,
            List<S> enrolledList, BiometricUtils utils, int sensorId);
            int sensorId);


    protected abstract RemovalClient<T> getRemovalClient(Context context, LazyDaemon<T> lazyDaemon,
    protected abstract RemovalClient<T> getRemovalClient(Context context, LazyDaemon<T> lazyDaemon,
            IBinder token, int biometricId, int userId, String owner, BiometricUtils utils,
            IBinder token, int biometricId, int userId, String owner, BiometricUtils utils,
@@ -96,8 +95,7 @@ public abstract class InternalCleanupClient<T> extends ClientMonitor<T>


    protected InternalCleanupClient(@NonNull Context context, @NonNull LazyDaemon<T> lazyDaemon,
    protected InternalCleanupClient(@NonNull Context context, @NonNull LazyDaemon<T> lazyDaemon,
            int userId, @NonNull String owner, int sensorId, int statsModality,
            int userId, @NonNull String owner, int sensorId, int statsModality,
            @NonNull List<? extends BiometricAuthenticator.Identifier> enrolledList,
            @NonNull List<S> enrolledList, @NonNull BiometricUtils utils) {
            @NonNull BiometricUtils utils) {
        super(context, lazyDaemon, null /* token */, null /* ClientMonitorCallbackConverter */,
        super(context, lazyDaemon, null /* token */, null /* ClientMonitorCallbackConverter */,
                userId, owner, 0 /* cookie */, sensorId, statsModality,
                userId, owner, 0 /* cookie */, sensorId, statsModality,
                BiometricsProtoEnums.ACTION_ENUMERATE, BiometricsProtoEnums.CLIENT_UNKNOWN);
                BiometricsProtoEnums.ACTION_ENUMERATE, BiometricsProtoEnums.CLIENT_UNKNOWN);
+4 −6
Original line number Original line Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.server.biometrics.sensors.face;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.face.Face;
import android.os.IBinder;
import android.os.IBinder;


import com.android.server.biometrics.sensors.BiometricUtils;
import com.android.server.biometrics.sensors.BiometricUtils;
@@ -35,12 +35,11 @@ import java.util.List;
 * {@link android.hardware.biometrics.face.V1_0} and {@link android.hardware.biometrics.face.V1_1}
 * {@link android.hardware.biometrics.face.V1_0} and {@link android.hardware.biometrics.face.V1_1}
 * HIDL interfaces.
 * HIDL interfaces.
 */
 */
class FaceInternalCleanupClient extends InternalCleanupClient<IBiometricsFace> {
class FaceInternalCleanupClient extends InternalCleanupClient<Face, IBiometricsFace> {


    FaceInternalCleanupClient(@NonNull Context context,
    FaceInternalCleanupClient(@NonNull Context context,
            @NonNull LazyDaemon<IBiometricsFace> lazyDaemon, int userId, @NonNull String owner,
            @NonNull LazyDaemon<IBiometricsFace> lazyDaemon, int userId, @NonNull String owner,
            int sensorId, @NonNull List<? extends BiometricAuthenticator.Identifier> enrolledList,
            int sensorId, @NonNull List<Face> enrolledList, @NonNull BiometricUtils utils) {
            @NonNull BiometricUtils utils) {
        super(context, lazyDaemon, userId, owner, sensorId, BiometricsProtoEnums.MODALITY_FACE,
        super(context, lazyDaemon, userId, owner, sensorId, BiometricsProtoEnums.MODALITY_FACE,
                enrolledList, utils);
                enrolledList, utils);
    }
    }
@@ -48,8 +47,7 @@ class FaceInternalCleanupClient extends InternalCleanupClient<IBiometricsFace> {
    @Override
    @Override
    protected InternalEnumerateClient<IBiometricsFace> getEnumerateClient(Context context,
    protected InternalEnumerateClient<IBiometricsFace> getEnumerateClient(Context context,
            LazyDaemon<IBiometricsFace> lazyDaemon, IBinder token, int userId, String owner,
            LazyDaemon<IBiometricsFace> lazyDaemon, IBinder token, int userId, String owner,
            List<? extends BiometricAuthenticator.Identifier> enrolledList,
            List<Face> enrolledList, BiometricUtils utils, int sensorId) {
            BiometricUtils utils, int sensorId) {
        return new FaceInternalEnumerateClient(context, lazyDaemon, token, userId, owner,
        return new FaceInternalEnumerateClient(context, lazyDaemon, token, userId, owner,
                enrolledList, utils, sensorId);
                enrolledList, utils, sensorId);
    }
    }
+3 −4
Original line number Original line Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.server.biometrics.sensors.face;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.biometrics.face.V1_0.IBiometricsFace;
import android.hardware.face.Face;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Slog;
import android.util.Slog;
@@ -40,9 +40,8 @@ class FaceInternalEnumerateClient extends InternalEnumerateClient<IBiometricsFac


    FaceInternalEnumerateClient(@NonNull Context context,
    FaceInternalEnumerateClient(@NonNull Context context,
            @NonNull LazyDaemon<IBiometricsFace> lazyDaemon, @NonNull IBinder token, int userId,
            @NonNull LazyDaemon<IBiometricsFace> lazyDaemon, @NonNull IBinder token, int userId,
            @NonNull String owner,
            @NonNull String owner, @NonNull List<Face> enrolledList, @NonNull BiometricUtils utils,
            @NonNull List<? extends BiometricAuthenticator.Identifier> enrolledList,
            int sensorId) {
            @NonNull BiometricUtils utils, int sensorId) {
        super(context, lazyDaemon, token, userId, owner, enrolledList, utils, sensorId,
        super(context, lazyDaemon, token, userId, owner, enrolledList, utils, sensorId,
                BiometricsProtoEnums.MODALITY_FACE);
                BiometricsProtoEnums.MODALITY_FACE);
    }
    }
+2 −3
Original line number Original line Diff line number Diff line
@@ -683,7 +683,7 @@ public class FaceService extends BiometricServiceBase<IBiometricsFace> {


    @Override
    @Override
    protected List<Face> getEnrolledTemplates(int userId) {
    protected List<Face> getEnrolledTemplates(int userId) {
        return getBiometricUtils().getBiometricsForUser(getContext(), userId);
        return FaceUtils.getInstance().getBiometricsForUser(getContext(), userId);
    }
    }


    @Override
    @Override
@@ -703,8 +703,7 @@ public class FaceService extends BiometricServiceBase<IBiometricsFace> {


    @Override
    @Override
    protected void doTemplateCleanupForUser(int userId) {
    protected void doTemplateCleanupForUser(int userId) {
        final List<? extends BiometricAuthenticator.Identifier> enrolledList =
        final List<Face> enrolledList = getEnrolledTemplates(userId);
                getEnrolledTemplates(userId);
        final FaceInternalCleanupClient client = new FaceInternalCleanupClient(getContext(),
        final FaceInternalCleanupClient client = new FaceInternalCleanupClient(getContext(),
                mLazyDaemon, userId, getContext().getOpPackageName(), getSensorId(), enrolledList,
                mLazyDaemon, userId, getContext().getOpPackageName(), getSensorId(), enrolledList,
                getBiometricUtils());
                getBiometricUtils());
Loading