Merge "Register the single fingerprint sensor only if" into udc-qpr-dev
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user