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

Commit a85b4a2d authored by Kevin Chyn's avatar Kevin Chyn Committed by Android (Google) Code Review
Browse files

Merge "Return correct error when HW there is no biometric hardware"

parents c578d38e e739daf2
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
@@ -1627,7 +1627,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();
            }