Huawei provides the secure fingerprint authentication capability. If the system is insecure, the callback method BioAuthnCallback.onAuthError()returns the error code FingerprintManager.ERROR_SYS_INTEGRITY_FAILED. If the system is secure, fingerprint authentication is performed. For details about the fingerprint authentication error codes, please refer to the API Reference.
The following is the sample code for using the fingerprint authentication capability:
- import android.app.Activity;
- import android.view.View;
- import com.huawei.hms.support.api.fido.bioauthn.BioAuthnCallback;
- import com.huawei.hms.support.api.fido.bioauthn.BioAuthnResult;
- import com.huawei.hms.support.api.fido.bioauthn.FingerprintManager;
- import java.util.concurrent.Executors;
- public class MainActivity extends Activity {
- public void btnFingerAuthenticateWithoutCryptoObjectClicked(View view) {
- // Callback.
- BioAuthnCallback bioAuthnCallback = new BioAuthnCallback() {
- @Override
- public void onAuthError(int errMsgId, CharSequence errString) {
- // Authentication error.
- }
- @Override
- public void onAuthSucceeded(BioAuthnResult result) {
- // Authentication successful.
- }
- @Override
- public void onAuthFailed() {
- // Authentication failed.
- }
- };
- FingerprintManager fingerprintManager =
- new FingerprintManager(this, Executors.newSingleThreadExecutor(), bioAuthnCallback);
- // Whether authentication is supported.
- int errorCode = fingerprintManager.canAuth();
- if (errorCode != 0) {
- // Authentication is not supported.
- return;
- }
- // Perform authentication.
- fingerprintManager.auth();
- }
- }
Huawei provides the secure 3D facial authentication capability. If the system is insecure, the callback method BioAuthnCallback.onAuthError returns the error code FaceManager.FACE_ERROR_SYS_INTEGRITY_FAILED. If the system is secure, 3D facial authentication is performed. For details about the 3D facial authentication error codes, please refer to the API Reference.
1. Only EMUI 10 (API level 29) and later versions support 3D facial authentication. In addition, the device hardware must support 3D facial authentication.
2. WhenCryptoObjectis used for authentication andKeyGenParameterSpec.Builderis used to generate a key,setUserAuthenticationRequired()must be set tofalse. In this version, the KeyStore is not associated with the 3D facial authentication result.
The following is the sample code for using the 3D facial authentication capability:
- import android.app.Activity;
- import android.os.CancellationSignal;
- import android.os.Handler;
- import android.view.View;
- import com.huawei.hms.support.api.fido.bioauthn.BioAuthnCallback;
- import com.huawei.hms.support.api.fido.bioauthn.BioAuthnResult;
- import com.huawei.hms.support.api.fido.bioauthn.CryptoObject;
- import com.huawei.hms.support.api.fido.bioauthn.FaceManager;
- public class MainActivity extends Activity {
- public void btnFaceAuthenticateWithoutCryptoObjectClicked(View view) {
- // Callback.
- BioAuthnCallback callback = new BioAuthnCallback() {
- @Override
- public void onAuthError(int errMsgId, CharSequence errString) {
- // Authentication error.
- }
- @Override
- public void onAuthHelp(int helpMsgId, CharSequence helpString) {
- // Help.
- }
- @Override
- public void onAuthSucceeded(BioAuthnResult result) {
- // Authentication successful.
- }
- @Override
- public void onAuthFailed() {
- // Authentication failed.
- }
- };
- // Cancellation signal.
- CancellationSignal cancellationSignal = new CancellationSignal();
- FaceManager faceManager = new FaceManager(this);
- int errorCode = faceManager.canAuth();
- if (errorCode != 0) {
- // Authentication is not supported.
- return;
- }
- // Flags.
- int flags = 0;
- // Authentication message handler.
- Handler handler = null;
- // It is recommended that CryptoObject be set to null. In this version, KeyStore is not associated with facial authentication.
- // The value false must be passed to KeyGenParameterSpec.Builder.setUserAuthenticationRequired().
- CryptoObject crypto = null;
- faceManager.auth(crypto, cancellationSignal, flags, callback, handler);
- }
- }
For more sample information, click fido-bioauthn-sample.zip to download the sample code.