diff options
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 16 | ||||
| -rw-r--r-- | core/java/android/hardware/biometrics/BiometricManager.java | 24 | ||||
| -rw-r--r-- | services/java/com/android/server/SystemServer.java | 2 |
3 files changed, 34 insertions, 8 deletions
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index e95f9abed908..713f752fc45b 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -857,11 +857,17 @@ final class SystemServiceRegistry { @Override public BiometricManager createService(ContextImpl ctx) throws ServiceNotFoundException { - final IBinder binder = - ServiceManager.getServiceOrThrow(Context.BIOMETRIC_SERVICE); - final IBiometricService service = - IBiometricService.Stub.asInterface(binder); - return new BiometricManager(ctx.getOuterContext(), service); + 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); + } } }); diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java index fe006045bf0f..ff58c7525a3a 100644 --- a/core/java/android/hardware/biometrics/BiometricManager.java +++ b/core/java/android/hardware/biometrics/BiometricManager.java @@ -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); } /** @@ -93,8 +109,12 @@ public class BiometricManager { throw e.rethrowFromSystemServer(); } } else { - Slog.w(TAG, "hasEnrolledBiometrics(): Service not connected"); - return BIOMETRIC_ERROR_UNAVAILABLE; + if (!mHasHardware) { + return BIOMETRIC_ERROR_NO_HARDWARE; + } else { + Slog.w(TAG, "hasEnrolledBiometrics(): Service not connected"); + return BIOMETRIC_ERROR_UNAVAILABLE; + } } } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 54a140dec713..71b0622907af 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -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(); } |