From 17681607d9e16d2e386ba915718560746439edee Mon Sep 17 00:00:00 2001 From: Kevin Chyn Date: Thu, 25 Mar 2021 17:39:03 -0700 Subject: [PATCH] Update getAuthenticatorId logic 1) Theoretically, 0 is a valid random authenticatorId 2) A more precise way of handling this is by checking enrollment status. If the sensor has no enrollments, do not add its authenticatorId to the list Bug: 183142128 Test: atest CtsBiometricsTestCases Change-Id: I80e9b27a297480b02015b20788d56703833245ab --- .../server/biometrics/BiometricService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java index 63e7b4b843663..70f26aca3f631 100644 --- a/services/core/java/com/android/server/biometrics/BiometricService.java +++ b/services/core/java/com/android/server/biometrics/BiometricService.java @@ -766,15 +766,18 @@ public class BiometricService extends SystemService { public long[] getAuthenticatorIds(int callingUserId) { checkInternalPermission(); - final List ids = new ArrayList<>(); + final List authenticatorIds = new ArrayList<>(); for (BiometricSensor sensor : mSensors) { try { - final long id = sensor.impl.getAuthenticatorId(callingUserId); - if (Utils.isAtLeastStrength(sensor.getCurrentStrength(), - Authenticators.BIOMETRIC_STRONG) && id != 0) { - ids.add(id); + final boolean hasEnrollments = sensor.impl.hasEnrolledTemplates(callingUserId, + getContext().getOpPackageName()); + final long authenticatorId = sensor.impl.getAuthenticatorId(callingUserId); + if (hasEnrollments && Utils.isAtLeastStrength(sensor.getCurrentStrength(), + Authenticators.BIOMETRIC_STRONG)) { + authenticatorIds.add(authenticatorId); } else { - Slog.d(TAG, "Sensor " + sensor + ", sensorId " + id + Slog.d(TAG, "Sensor " + sensor + ", sensorId " + sensor.id + + ", hasEnrollments: " + hasEnrollments + " cannot participate in Keystore operations"); } } catch (RemoteException e) { @@ -782,9 +785,9 @@ public class BiometricService extends SystemService { } } - long[] result = new long[ids.size()]; - for (int i = 0; i < ids.size(); i++) { - result[i] = ids.get(i); + long[] result = new long[authenticatorIds.size()]; + for (int i = 0; i < authenticatorIds.size(); i++) { + result[i] = authenticatorIds.get(i); } return result; }