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

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

Return correct error when HW there is no biometric hardware

Devices that have no biometric hardware should still get the
BIOMETRIC_ERROR_HW_NOT_PRESENT error. Currently they get the
BIOMETRIC_ERROR_HW_UNAVAILABLE error which is slightly wrong.

Fixes: 119109074

Test: Builds
Change-Id: I32134a35fd2844bc6a4a64ded9695ae596496ef2
parent b95e7b7b
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -857,11 +857,17 @@ final class SystemServiceRegistry {
                    @Override
                    public BiometricManager createService(ContextImpl ctx)
                            throws ServiceNotFoundException {
                        if (BiometricManager.hasBiometrics(ctx)) {
                            final IBinder binder =
                                    ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE);
                            final IBiometricService service =
                                    IBiometricService.Stub.asInterface(binder);
                            return new BiometricManager(ctx.getOuterContext(), service);
                        } else {
                            // Allow access to the manager when service is null. This saves memory
                            // on devices without biometric hardware.
                            return new BiometricManager(ctx.getOuterContext(), null);
                        }
                    }
                });

+22 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import android.annotation.IntDef;
import android.annotation.RequiresPermission;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.util.Slog;

@@ -64,6 +65,19 @@ public class BiometricManager {

    private final Context mContext;
    private final IBiometricService mService;
    private final boolean mHasHardware;

    /**
     * @param context
     * @return
     * @hide
     */
    public static boolean hasBiometrics(Context context) {
        final PackageManager pm = context.getPackageManager();
        return pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
                || pm.hasSystemFeature(PackageManager.FEATURE_IRIS)
                || pm.hasSystemFeature(PackageManager.FEATURE_FACE);
    }

    /**
     * @hide
@@ -73,6 +87,8 @@ public class BiometricManager {
    public BiometricManager(Context context, IBiometricService service) {
        mContext = context;
        mService = service;

        mHasHardware = hasBiometrics(context);
    }

    /**
@@ -92,11 +108,15 @@ public class BiometricManager {
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            if (!mHasHardware) {
                return BIOMETRIC_ERROR_NO_HARDWARE;
            } else {
                Slog.w(TAG, "hasEnrolledBiometrics(): Service not connected");
                return BIOMETRIC_ERROR_UNAVAILABLE;
            }
        }
    }

    /**
     * Listens for changes to biometric eligibility on keyguard from user settings.
+1 −1
Original line number Diff line number Diff line
@@ -1619,7 +1619,7 @@ public final class SystemServer {

            if (hasFeatureFace || hasFeatureIris || hasFeatureFingerprint) {
                // Start this service after all biometric services.
                traceBeginAndSlog("StartBiometricPromptService");
                traceBeginAndSlog("StartBiometricService");
                mSystemServiceManager.startService(BiometricService.class);
                traceEnd();
            }