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

Commit 294f4a1e authored by Joe Bolinger's avatar Joe Bolinger
Browse files

Copy startup & callback mechanism from fingerprint to face service.

Refactors some fingerprint-only logic into a shared module so the face service can apply the same start & callback model. This will enable some keyguard optimizations for face auth that were previously made for fingerprint.

Bug: 221037350
Test: atest KeyguardUpdateMonitorTest AuthControllerTest DozeSensorsTest LockIconViewControllerTest FaceServiceRegistryTest FingerprintServiceRegistryTest BiometricStateCallbackTest
Test: manual (via BP test app)
Change-Id: I88a489ef0eaf9a9e5645e5e6f9b9381187b25fab
parent b6336476
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricFaceConstants;
import android.hardware.biometrics.BiometricStateListener;
import android.hardware.biometrics.CryptoObject;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.os.Binder;
@@ -673,6 +674,45 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        return new ArrayList<>();
    }

    /**
     * Forwards BiometricStateListener to FaceService.
     *
     * @param listener new BiometricStateListener being added
     * @hide
     */
    public void registerBiometricStateListener(@NonNull BiometricStateListener listener) {
        try {
            mService.registerBiometricStateListener(listener);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Adds a callback that gets called when the service registers all of the face
     * authenticators (HALs).
     *
     * If the face authenticators are already registered when the callback is added, the
     * callback is invoked immediately.
     *
     * The callback is automatically removed after it's invoked.
     *
     * @hide
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void addAuthenticatorsRegisteredCallback(
            IFaceAuthenticatorsRegisteredCallback callback) {
        if (mService != null) {
            try {
                mService.addAuthenticatorsRegisteredCallback(callback);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            Slog.w(TAG, "addAuthenticatorsRegisteredCallback(): Service not connected!");
        }
    }

    /**
     * @hide
     */
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 android.hardware.face;

import android.hardware.face.FaceSensorPropertiesInternal;
import java.util.List;

/**
 * Callback to notify FaceManager that FaceService has registered all of the
 * face authenticators (HALs).
 * See {@link android.hardware.face.IFaceService#registerAuthenticators}.
 *
 * @hide
 */
oneway interface IFaceAuthenticatorsRegisteredCallback {
    /**
     * Notifies FaceManager that all of the face authenticators have been registered.
     *
     * @param sensors A consolidated list of sensor properties for all of the authenticators.
     */
    void onAllAuthenticatorsRegistered(in List<FaceSensorPropertiesInternal> sensors);
}
+9 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@ package android.hardware.face;

import android.hardware.biometrics.IBiometricSensorReceiver;
import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
import android.hardware.biometrics.IBiometricStateListener;
import android.hardware.biometrics.IInvalidationCallback;
import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
import android.hardware.face.IFaceAuthenticatorsRegisteredCallback;
import android.hardware.face.IFaceServiceReceiver;
import android.hardware.face.Face;
import android.hardware.face.FaceSensorPropertiesInternal;
@@ -163,4 +165,11 @@ interface IFaceService {
    // hidlSensors must be non-null and empty. See AuthService.java
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    void registerAuthenticators(in List<FaceSensorPropertiesInternal> hidlSensors);

    // Adds a callback which gets called when the service registers all of the face
    // authenticators. The callback is automatically removed after it's invoked.
    void addAuthenticatorsRegisteredCallback(IFaceAuthenticatorsRegisteredCallback callback);

    // Registers BiometricStateListener.
    void registerBiometricStateListener(IBiometricStateListener listener);
}
+2 −0
Original line number Diff line number Diff line
@@ -202,8 +202,10 @@ interface IFingerprintService {
    void setSidefpsController(in ISidefpsController controller);

    // Registers BiometricStateListener.
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    void registerBiometricStateListener(IBiometricStateListener listener);

    // Sends a power button pressed event to all listeners.
    @EnforcePermission("USE_BIOMETRIC_INTERNAL")
    oneway void onPowerPressed();
}
+4 −2
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricFingerprintConstants;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricSourceType;
@@ -2019,12 +2020,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        // in case authenticators aren't registered yet at this point:
        mAuthController.addCallback(new AuthController.Callback() {
            @Override
            public void onAllAuthenticatorsRegistered() {
            public void onAllAuthenticatorsRegistered(
                    @BiometricAuthenticator.Modality int modality) {
                mainExecutor.execute(() -> updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE));
            }

            @Override
            public void onEnrollmentsChanged() {
            public void onEnrollmentsChanged(@BiometricAuthenticator.Modality int modality) {
                mainExecutor.execute(() -> updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE));
            }
        });
Loading