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

Commit 6b264052 authored by Jeff Pu's avatar Jeff Pu
Browse files

Register the single fingerprint sensor only if

there is no existing one. And do not register HIDL fingerprint hardware
sensor(s) if the VHAL is enabled.

Bug: 287456517
Test: adb shell dumpsys fingerprint on bramble (B5) device running
        with userdebug/eng build, and verify virtual fingerprint HAL
	does not present.
      atest BiometricsE2eTests:BiometricPromptAuthSuccessTest
Change-Id: I868f975446ec4b4b473c4fbc48370fbb68c0570c
parent 0a5435a5
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ import com.android.internal.R;
import com.android.internal.widget.LockPatternUtils;
import com.android.server.biometrics.sensors.BaseClientMonitor;

import java.util.ArrayList;
import java.util.List;

public class Utils {
@@ -97,33 +96,6 @@ public class Utils {
                Settings.Secure.BIOMETRIC_VIRTUAL_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
    }

    /**
     * Get the enabled HAL instances. If virtual is enabled and available it will be returned as
     * the only instance, otherwise all other instances will be returned.
     *
     * @param context system context
     * @param declaredInstances known instances
     * @return filtered list of enabled instances
     */
    @NonNull
    public static List<String> filterAvailableHalInstances(@NonNull Context context,
            @NonNull List<String> declaredInstances) {
        if (declaredInstances.size() <= 1) {
            return declaredInstances;
        }

        final int virtualAt = declaredInstances.indexOf("virtual");
        if (isVirtualEnabled(context) && virtualAt != -1) {
            return List.of(declaredInstances.get(virtualAt));
        }

        declaredInstances = new ArrayList<>(declaredInstances);
        if (virtualAt != -1) {
            declaredInstances.remove(virtualAt);
        }
        return declaredInstances;
    }

    /**
     * Combines {@link PromptInfo#setDeviceCredentialAllowed(boolean)} with
     * {@link PromptInfo#setAuthenticators(int)}, as the former is not flexible enough.
+35 −5
Original line number Diff line number Diff line
@@ -871,19 +871,22 @@ public class FingerprintService extends SystemService {
            super.registerAuthenticators_enforcePermission();

            mRegistry.registerAll(() -> {
                final List<ServiceProvider> providers = new ArrayList<>();
                providers.addAll(getHidlProviders(hidlSensors));
                List<String> aidlSensors = new ArrayList<>();
                final String[] instances = mAidlInstanceNameSupplier.get();
                if (instances != null) {
                    aidlSensors.addAll(Lists.newArrayList(instances));
                }
                providers.addAll(getAidlProviders(
                        Utils.filterAvailableHalInstances(getContext(), aidlSensors)));

                final Pair<List<FingerprintSensorPropertiesInternal>, List<String>>
                        filteredInstances = filterAvailableHalInstances(hidlSensors, aidlSensors);

                final List<ServiceProvider> providers = new ArrayList<>();
                providers.addAll(getHidlProviders(filteredInstances.first));
                providers.addAll(getAidlProviders(filteredInstances.second));

                return providers;
            });
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.USE_BIOMETRIC_INTERNAL)
        @Override
        public void addAuthenticatorsRegisteredCallback(
@@ -1038,6 +1041,33 @@ public class FingerprintService extends SystemService {
        });
    }

    private Pair<List<FingerprintSensorPropertiesInternal>, List<String>>
                filterAvailableHalInstances(
            @NonNull List<FingerprintSensorPropertiesInternal> hidlInstances,
            @NonNull List<String> aidlInstances) {
        if ((hidlInstances.size() + aidlInstances.size()) <= 1) {
            return new Pair(hidlInstances, aidlInstances);
        }

        final int virtualAt = aidlInstances.indexOf("virtual");
        if (Utils.isVirtualEnabled(getContext())) {
            if (virtualAt != -1) {
                //only virtual instance should be returned
                return new Pair(new ArrayList<>(), List.of(aidlInstances.get(virtualAt)));
            } else {
                Slog.e(TAG, "Could not find virtual interface while it is enabled");
                return new Pair(hidlInstances, aidlInstances);
            }
        } else {
            //remove virtual instance
            aidlInstances = new ArrayList<>(aidlInstances);
            if (virtualAt != -1) {
                aidlInstances.remove(virtualAt);
            }
            return new Pair(hidlInstances, aidlInstances);
        }
    }

    @NonNull
    private List<ServiceProvider> getHidlProviders(
            @NonNull List<FingerprintSensorPropertiesInternal> hidlSensors) {