Merge changes from topic "biometric-manager"
* changes: Move biometric setting observer from KeyguardUpdateMonitor to BiometricService Change BiometricManager#hasEnrolledBiometrics to canAuthenticate
This commit is contained in:
@@ -33,6 +33,13 @@ public interface BiometricConstants {
|
||||
// removal.
|
||||
//
|
||||
|
||||
/**
|
||||
* This was not added here since it would update BiometricPrompt API. But, is used in
|
||||
* BiometricManager.
|
||||
* @hide
|
||||
*/
|
||||
int BIOMETRIC_ERROR_NONE = 0;
|
||||
|
||||
/**
|
||||
* The hardware is unavailable. Try again later.
|
||||
*/
|
||||
|
||||
@@ -17,16 +17,35 @@
|
||||
package android.hardware.biometrics;
|
||||
|
||||
import static android.Manifest.permission.USE_BIOMETRIC;
|
||||
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
|
||||
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
|
||||
/**
|
||||
* A class that contains biometric utilities. For authentication, see {@link BiometricPrompt}.
|
||||
*/
|
||||
public class BiometricManager {
|
||||
|
||||
private static final String TAG = "BiometricManager";
|
||||
|
||||
/**
|
||||
* No error detected.
|
||||
*/
|
||||
public static final int ERROR_NONE = BiometricConstants.BIOMETRIC_ERROR_NONE;
|
||||
|
||||
/**
|
||||
* The hardware is unavailable. Try again later.
|
||||
*/
|
||||
public static final int ERROR_UNAVAILABLE = BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* The user does not have any biometrics enrolled.
|
||||
*/
|
||||
public static final int ERROR_NO_BIOMETRICS = BiometricConstants.BIOMETRIC_ERROR_NO_BIOMETRICS;
|
||||
|
||||
private final Context mContext;
|
||||
private final IBiometricService mService;
|
||||
|
||||
@@ -41,16 +60,42 @@ public class BiometricManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there is at least one biometric enrolled.
|
||||
* Determine if biometrics can be used. In other words, determine if {@link BiometricPrompt}
|
||||
* can be expected to be shown (hardware available, templates enrolled, user-enabled).
|
||||
*
|
||||
* @return true if at least one biometric is enrolled, false otherwise
|
||||
* @return Returns {@link #ERROR_NO_BIOMETRICS} if the user does not have any enrolled, or
|
||||
* {@link #ERROR_UNAVAILABLE} if none are currently supported/enabled. Returns
|
||||
* {@link #ERROR_NONE} if a biometric can currently be used (enrolled and available).
|
||||
*/
|
||||
@RequiresPermission(USE_BIOMETRIC)
|
||||
public boolean hasEnrolledBiometrics() {
|
||||
try {
|
||||
return mService.hasEnrolledBiometrics(mContext.getOpPackageName());
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
public int canAuthenticate() {
|
||||
if (mService != null) {
|
||||
try {
|
||||
return mService.canAuthenticate(mContext.getOpPackageName());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
} else {
|
||||
Slog.w(TAG, "hasEnrolledBiometrics(): Service not connected");
|
||||
return ERROR_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for changes to biometric eligibility on keyguard from user settings.
|
||||
* @param callback
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(USE_BIOMETRIC_INTERNAL)
|
||||
public void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.registerEnabledOnKeyguardCallback(callback);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
} else {
|
||||
Slog.w(TAG, "registerEnabledOnKeyguardCallback(): Service not connected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 android.hardware.biometrics.BiometricSourceType;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
oneway interface IBiometricEnabledOnKeyguardCallback {
|
||||
void onChanged(in BiometricSourceType type, boolean enabled);
|
||||
}
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package android.hardware.biometrics;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
/**
|
||||
* Communication channel from the BiometricPrompt (SysUI) back to AuthenticationClient.
|
||||
* @hide
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.hardware.biometrics;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
|
||||
import android.hardware.biometrics.IBiometricPromptReceiver;
|
||||
import android.hardware.biometrics.IBiometricServiceReceiver;
|
||||
|
||||
@@ -37,6 +38,9 @@ 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(String opPackageName);
|
||||
// Checks if biometrics can be used.
|
||||
int canAuthenticate(String opPackageName);
|
||||
|
||||
// Register callback for when keyguard biometric eligibility changes.
|
||||
void registerEnabledOnKeyguardCallback(IBiometricEnabledOnKeyguardCallback callback);
|
||||
}
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package android.hardware.biometrics;
|
||||
|
||||
import android.hardware.biometrics.BiometricSourceType;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
/**
|
||||
* Communication channel from the BiometricService back to BiometricPrompt.
|
||||
* @hide
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package android.hardware.face;
|
||||
|
||||
import android.hardware.face.Face;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
/**
|
||||
* Communication channel from the FaceService back to FaceAuthenticationManager.
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package android.hardware.fingerprint;
|
||||
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
/**
|
||||
* Communication channel from the FingerprintService back to FingerprintManager.
|
||||
|
||||
Reference in New Issue
Block a user