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

Commit 05c21508 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

3/n: Add BiometricManager, hasEnrolledBiometrics()

Fixes: 112570477

Test: BiometricPromptDemo works
Test: Able to get/use BiometricManager
Test: Tested with enrolled and non-enrolled biometrics

Change-Id: I26231894eccc87c42b5b3007aa0b7c6f09830452
parent 352adfec
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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);
+15 −0
Original line number Diff line number Diff line
@@ -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
+11 −9
Original line number Diff line number Diff line
@@ -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,
@@ -3680,14 +3681,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
@@ -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.
     *
@@ -3710,6 +3702,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
+56 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -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
Loading