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

Commit 17681607 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

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
parent 3309f233
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -766,15 +766,18 @@ public class BiometricService extends SystemService {
        public long[] getAuthenticatorIds(int callingUserId) {
            checkInternalPermission();

            final List<Long> ids = new ArrayList<>();
            final List<Long> 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;
        }