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

Commit dc961591 authored by Jeff Pu's avatar Jeff Pu Committed by Android (Google) Code Review
Browse files

Merge "Allow Biometric TestApi to use virtual hal" into main

parents f72d1928 97270611
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ filegroup {
        // AIDL sources from external directories
        ":android.frameworks.location.altitude-V2-java-source",
        ":android.hardware.biometrics.common-V4-java-source",
        ":android.hardware.biometrics.fingerprint-V3-java-source",
        ":android.hardware.biometrics.fingerprint-V5-java-source",
        ":android.hardware.biometrics.face-V4-java-source",
        ":android.hardware.gnss-V2-java-source",
        ":android.hardware.graphics.common-V3-java-source",
+5 −5
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ flag {
}

flag {
    name: "de_hidl"
  name: "use_vhal_for_testing"
  namespace: "biometrics_framework"
    description: "feature flag for biometrics de-hidl"
    bug: "287332354"
  description: "This flag controls whether virtual HAL is used for testing instead of TestHal "
  bug: "294254230"
}
+50 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.hardware.biometrics.ITestSession;
import android.hardware.biometrics.ITestSessionCallback;
import android.hardware.biometrics.SensorLocationInternal;
import android.hardware.biometrics.fingerprint.IFingerprint;
import android.hardware.biometrics.fingerprint.IVirtualHal;
import android.hardware.biometrics.fingerprint.PointerContext;
import android.hardware.biometrics.fingerprint.SensorProps;
import android.hardware.fingerprint.Fingerprint;
@@ -59,6 +60,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.biometrics.AuthenticationStatsBroadcastReceiver;
import com.android.server.biometrics.AuthenticationStatsCollector;
import com.android.server.biometrics.BiometricHandlerProvider;
import com.android.server.biometrics.Flags;
import com.android.server.biometrics.Utils;
import com.android.server.biometrics.log.BiometricContext;
import com.android.server.biometrics.log.BiometricLogger;
@@ -133,6 +135,8 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
    @Nullable private ISidefpsController mSidefpsController;
    private final AuthSessionCoordinator mAuthSessionCoordinator;
    @Nullable private AuthenticationStatsCollector mAuthenticationStatsCollector;
    @Nullable private IVirtualHal mVhal;
    @Nullable private String mHalInstanceNameCurrent;

    private final class BiometricTaskStackListener extends TaskStackListener {
        @Override
@@ -293,11 +297,30 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
    @VisibleForTesting
    synchronized IFingerprint getHalInstance() {
        if (mTestHalEnabled) {
            if (Flags.useVhalForTesting()) {
                if (!mHalInstanceNameCurrent.contains("virtual")) {
                    Slog.i(getTag(), "Switching fingerprint hal from " + mHalInstanceName
                            + " to virtual hal");
                    mHalInstanceNameCurrent = "virtual";
                    mDaemon = null;
                }
            } else {
                // Enabling the test HAL for a single sensor in a multi-sensor HAL currently enables
                // the test HAL for all sensors under that HAL. This can be updated in the future if
                // necessary.
                return new TestHal();
            }
        } else {
            if (mHalInstanceNameCurrent == null) {
                mHalInstanceNameCurrent = mHalInstanceName;
            } else if (mHalInstanceNameCurrent.contains("virtual")
                    && mHalInstanceNameCurrent != mHalInstanceName) {
                Slog.i(getTag(), "Switching fingerprint from virtual hal " + "to "
                        + mHalInstanceName);
                mHalInstanceNameCurrent = mHalInstanceName;
                mDaemon = null;
            }
        }

        if (mDaemon != null) {
            return mDaemon;
@@ -308,7 +331,7 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
        mDaemon = IFingerprint.Stub.asInterface(
                Binder.allowBlocking(
                        ServiceManager.waitForDeclaredService(
                                IFingerprint.DESCRIPTOR + "/" + mHalInstanceName)));
                                IFingerprint.DESCRIPTOR + "/" + mHalInstanceNameCurrent)));
        if (mDaemon == null) {
            Slog.e(getTag(), "Unable to get daemon");
            return null;
@@ -952,4 +975,26 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
    public void sendFingerprintReEnrollNotification() {
        mAuthenticationStatsCollector.sendFingerprintReEnrollNotification();
    }

    /**
     * Return virtual hal AIDL interface if it is used for testing
     *
     */
    public IVirtualHal getVhal() throws RemoteException {
        if (mVhal == null && useVhalForTesting()) {
            mVhal = IVirtualHal.Stub.asInterface(mDaemon.asBinder().getExtension());
            if (mVhal == null) {
                Slog.e(getTag(), "Unable to get virtual hal interface");
            }
        }

        return mVhal;
    }

    /**
     * Return true if vhal_for_testing feature is enabled and test is active
     */
    public boolean useVhalForTesting() {
        return (Flags.useVhalForTesting() && mTestHalEnabled);
    }
}