Fix possible NPE in fingerprint service provider

Test: atest FingerprintManagerTest

Bug: 179073068
Change-Id: If624d54834c443b727e574333a4bd116f11a297c
This commit is contained in:
Curtis Belmonte
2021-03-15 14:04:08 -07:00
parent 69237805b0
commit 13c7b270e2
3 changed files with 19 additions and 4 deletions

View File

@@ -67,7 +67,13 @@ public interface ServiceProvider {
@NonNull
List<FingerprintSensorPropertiesInternal> getSensorProperties();
@NonNull
/**
* Returns the internal properties of the specified sensor, if owned by this provider.
*
* @param sensorId The ID of a fingerprint sensor, or -1 for any sensor.
* @return An object representing the internal properties of the specified sensor.
*/
@Nullable
FingerprintSensorPropertiesInternal getSensorProperties(int sensorId);
void scheduleResetLockout(int sensorId, int userId, @Nullable byte[] hardwareAuthToken);

View File

@@ -16,6 +16,8 @@
package com.android.server.biometrics.sensors.fingerprint.aidl;
import static android.hardware.fingerprint.FingerprintManager.SENSOR_ID_ANY;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -240,10 +242,17 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
return props;
}
@NonNull
@Nullable
@Override
public FingerprintSensorPropertiesInternal getSensorProperties(int sensorId) {
return mSensors.get(sensorId).getSensorProperties();
if (mSensors.size() == 0) {
return null;
} else if (sensorId == SENSOR_ID_ANY) {
return mSensors.valueAt(0).getSensorProperties();
} else {
final Sensor sensor = mSensors.get(sensorId);
return sensor != null ? sensor.getSensorProperties() : null;
}
}
private void scheduleLoadAuthenticatorIds(int sensorId) {

View File

@@ -515,7 +515,7 @@ public class Fingerprint21 implements IHwBinder.DeathRecipient, ServiceProvider
return properties;
}
@NonNull
@Nullable
@Override
public FingerprintSensorPropertiesInternal getSensorProperties(int sensorId) {
return mSensorProperties;