diff options
7 files changed, 112 insertions, 10 deletions
diff --git a/api/current.txt b/api/current.txt index 3beb491c5412..7d3698a7ee14 100755 --- a/api/current.txt +++ b/api/current.txt @@ -9527,6 +9527,7 @@ package android.content { field public static final int BIND_IMPORTANT = 64; // 0x40 field public static final int BIND_NOT_FOREGROUND = 4; // 0x4 field public static final int BIND_WAIVE_PRIORITY = 32; // 0x20 + field public static final java.lang.String BIOMETRIC_SERVICE = "biometric"; field public static final java.lang.String BLUETOOTH_SERVICE = "bluetooth"; field public static final java.lang.String CAMERA_SERVICE = "camera"; field public static final java.lang.String CAPTIONING_SERVICE = "captioning"; @@ -15934,6 +15935,10 @@ package android.hardware { package android.hardware.biometrics { + public class BiometricManager { + method public boolean hasEnrolledBiometrics(); + } + public class BiometricPrompt { method public void authenticate(android.hardware.biometrics.BiometricPrompt.CryptoObject, android.os.CancellationSignal, java.util.concurrent.Executor, android.hardware.biometrics.BiometricPrompt.AuthenticationCallback); method public void authenticate(android.os.CancellationSignal, java.util.concurrent.Executor, android.hardware.biometrics.BiometricPrompt.AuthenticationCallback); diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 003f36438c5a..a6791660d045 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -53,6 +53,8 @@ import android.hardware.ISerialManager; import android.hardware.SensorManager; import android.hardware.SerialManager; import android.hardware.SystemSensorManager; +import android.hardware.biometrics.BiometricManager; +import android.hardware.biometrics.IBiometricService; import android.hardware.camera2.CameraManager; import android.hardware.display.DisplayManager; import android.hardware.face.FaceManager; @@ -818,6 +820,19 @@ final class SystemServiceRegistry { } }); + registerService(Context.BIOMETRIC_SERVICE, BiometricManager.class, + new CachedServiceFetcher<BiometricManager>() { + @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); + } + }); + registerService(Context.TV_INPUT_SERVICE, TvInputManager.class, new CachedServiceFetcher<TvInputManager>() { @Override diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 369fa975253e..981be833f3c0 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3031,6 +3031,7 @@ public abstract class Context { AUDIO_SERVICE, FINGERPRINT_SERVICE, //@hide: FACE_SERVICE, + BIOMETRIC_SERVICE, MEDIA_ROUTER_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, @@ -3681,14 +3682,6 @@ public abstract class Context { public static final String AUDIO_SERVICE = "audio"; /** - * Use with {@link #getSystemService(String)} - * - * @hide - * @see #getSystemService(String) - */ - public static final String BIOMETRIC_SERVICE = "biometric"; - - /** * Use with {@link #getSystemService(String)} to retrieve a * {@link android.hardware.fingerprint.FingerprintManager} for handling management * of fingerprints. @@ -3700,7 +3693,6 @@ public abstract class Context { /** * Use with {@link #getSystemService(String)} to retrieve a - * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.face.FaceManager} for handling management * of face authentication. * @@ -3711,6 +3703,16 @@ public abstract class Context { public static final String FACE_SERVICE = "face"; /** + * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.hardware.biometrics.BiometricManager} for handling management + * of face authentication. + * + * @see #getSystemService + * @see android.hardware.biometrics.BiometricManager + */ + public static final String BIOMETRIC_SERVICE = "biometric"; + + /** * Use with {@link #getSystemService} to retrieve a * {@link android.media.MediaRouter} for controlling and managing * routing of media. diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java new file mode 100644 index 000000000000..36e978b77cab --- /dev/null +++ b/core/java/android/hardware/biometrics/BiometricManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.biometrics; + +import static android.Manifest.permission.USE_BIOMETRIC; + +import android.annotation.RequiresPermission; +import android.content.Context; +import android.os.RemoteException; + +/** + * A class that contains biometric utilities. For authentication, see {@link BiometricPrompt}. + */ +public class BiometricManager { + + private final Context mContext; + private final IBiometricService mService; + + /** + * @hide + * @param context + * @param service + */ + public BiometricManager(Context context, IBiometricService service) { + mContext = context; + mService = service; + } + + /** + * Determine if there is at least one biometric enrolled. + * + * @return true if at least one biometric is enrolled, false otherwise + */ + @RequiresPermission(USE_BIOMETRIC) + public boolean hasEnrolledBiometrics() { + try { + return mService.hasEnrolledBiometrics(); + } catch (RemoteException e) { + return false; + } + } +} diff --git a/core/java/android/hardware/biometrics/IBiometricService.aidl b/core/java/android/hardware/biometrics/IBiometricService.aidl index 363741a93c67..bfd6941d1583 100644 --- a/core/java/android/hardware/biometrics/IBiometricService.aidl +++ b/core/java/android/hardware/biometrics/IBiometricService.aidl @@ -36,4 +36,7 @@ interface IBiometricService { // Cancel authentication for the given sessionId void cancelAuthentication(IBinder token, String opPackageName); + + // Returns true if the user has at least one enrolled biometric. + boolean hasEnrolledBiometrics(); }
\ No newline at end of file diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java index c0fcd9e86805..fa22b84f452e 100644 --- a/services/core/java/com/android/server/biometrics/BiometricService.java +++ b/services/core/java/com/android/server/biometrics/BiometricService.java @@ -198,6 +198,27 @@ public class BiometricService extends SystemService { } }); } + + @Override // Binder call + public boolean hasEnrolledBiometrics() { + checkPermission(); + + boolean hasEnrolled = false; + final long ident = Binder.clearCallingIdentity(); + try { + // Note: On devices with multi-modal authentication, the selection logic will need to + // be updated. + for (int i = 0; i < mAuthenticators.size(); i++) { + if (mAuthenticators.get(i).getAuthenticator().hasEnrolledTemplates()) { + hasEnrolled = true; + break; + } + } + } finally { + Binder.restoreCallingIdentity(ident); + } + return hasEnrolled; + } } private void checkPermission() { diff --git a/services/core/java/com/android/server/biometrics/BiometricServiceBase.java b/services/core/java/com/android/server/biometrics/BiometricServiceBase.java index d25da5900858..b3c7c19eee71 100644 --- a/services/core/java/com/android/server/biometrics/BiometricServiceBase.java +++ b/services/core/java/com/android/server/biometrics/BiometricServiceBase.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ package com.android.server.biometrics; |