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

Commit 3fbe9fef authored by Eden Mendel's avatar Eden Mendel
Browse files

AI-generated suggestion for a Null Pointer Exception.

Bug: 433865328

Flag: EXEMPT bugfix

Provide Feedback: Help us improve by voting and commenting on the CL.
Report bugs or provide feedback: go/ai-npe-fixer-feedback

AI reasoning:
- The upstream fix filters out any null `SensorPropertiesInternal` objects from the list returned by `BiometricService.getSensorProperties()`. This prevents nulls from propagating up the call stack.
- The midstream fix adds a null check in `BiometricService.getSensorProperties()` to ensure that null `SensorPropertiesInternal` objects are not added to the list that is returned to the caller.
- The downstream fix adds a null check in `SensorPropertiesInternal.from()` to prevent the NPE. It also changes the annotation of the `prop` parameter and the return type to `@Nullable` to reflect the possibility of null values.

Change-Id: Id48d71d9f93cb1fa3960e83662e4ff2766cd155d
parent 1d360925
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.biometrics;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

@@ -38,7 +39,11 @@ public class SensorPropertiesInternal implements Parcelable {
    public final boolean resetLockoutRequiresHardwareAuthToken;
    public final boolean resetLockoutRequiresChallenge;

    public static SensorPropertiesInternal from(@NonNull SensorPropertiesInternal prop) {
    @Nullable
    public static SensorPropertiesInternal from(@Nullable SensorPropertiesInternal prop) {
        if (prop == null) {
            return null;
        }
        return new SensorPropertiesInternal(prop.sensorId, prop.sensorStrength,
                prop.maxEnrollmentsPerUser, prop.componentInfo,
                prop.resetLockoutRequiresHardwareAuthToken, prop.resetLockoutRequiresChallenge);
+3 −1
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * System service that provides an interface for authenticating with biometrics and
@@ -268,7 +269,8 @@ public class AuthService extends SystemService {
            try {
                // Get the result from BiometricService, since it is the source of truth for all
                // biometric sensors.
                return mInjector.getBiometricService().getSensorProperties(opPackageName);
                return mInjector.getBiometricService().getSensorProperties(opPackageName)
                        .stream().filter(p -> p != null).collect(Collectors.toList());
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
+3 −1
Original line number Diff line number Diff line
@@ -902,8 +902,10 @@ public class BiometricService extends SystemService {
                // "List<? extends SensorPropertiesInternal> ...
                final SensorPropertiesInternal prop = SensorPropertiesInternal
                        .from(sensor.impl.getSensorProperties(opPackageName));
                if (prop != null) {
                    sensors.add(prop);
                }
            }

            return sensors;
        }