目录

1. Fingerprint Authentication

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.

Note:
Only EMUI 4 (API level 23) and later versions support fingerprint authentication. In addition, the device hardware must support fingerprint authentication.

The following is the sample code for using the fingerprint authentication capability:

  1. import android.app.Activity;
  2. import android.view.View;
  3. import com.huawei.hms.support.api.fido.bioauthn.BioAuthnCallback;
  4. import com.huawei.hms.support.api.fido.bioauthn.BioAuthnResult;
  5. import com.huawei.hms.support.api.fido.bioauthn.FingerprintManager;
  6. import java.util.concurrent.Executors;
  7. public class MainActivity extends Activity {
  8.    public void btnFingerAuthenticateWithoutCryptoObjectClicked(View view) {
  9.        // Callback.
  10.        BioAuthnCallback bioAuthnCallback = new BioAuthnCallback() {
  11.            @Override
  12.            public void onAuthError(int errMsgId, CharSequence errString) {
  13.                // Authentication error.
  14.            }
  15.            @Override
  16.            public void onAuthSucceeded(BioAuthnResult result) {
  17.                // Authentication successful.
  18.            }
  19.            @Override
  20.            public void onAuthFailed() {
  21.                // Authentication failed.
  22.            }
  23.        };
  24.        FingerprintManager fingerprintManager =
  25.            new FingerprintManager(this, Executors.newSingleThreadExecutor(), bioAuthnCallback);
  26.        // Whether authentication is supported.
  27.        int errorCode = fingerprintManager.canAuth();
  28.        if (errorCode != 0) {
  29.            // Authentication is not supported.
  30.            return;
  31.        }
  32.        // Perform authentication.
  33.        fingerprintManager.auth();
  34.    }
  35. }

2. 3D Facial Authentication

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.

Note:

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:

  1. import android.app.Activity;
  2. import android.os.CancellationSignal;
  3. import android.os.Handler;
  4. import android.view.View;
  5. import com.huawei.hms.support.api.fido.bioauthn.BioAuthnCallback;
  6. import com.huawei.hms.support.api.fido.bioauthn.BioAuthnResult;
  7. import com.huawei.hms.support.api.fido.bioauthn.CryptoObject;
  8. import com.huawei.hms.support.api.fido.bioauthn.FaceManager;
  9. public class MainActivity extends Activity {
  10.    public void btnFaceAuthenticateWithoutCryptoObjectClicked(View view) {
  11.        // Callback.
  12.        BioAuthnCallback callback = new BioAuthnCallback() {
  13.            @Override
  14.            public void onAuthError(int errMsgId, CharSequence errString) {
  15.                // Authentication error.
  16.            }
  17.            @Override
  18.            public void onAuthHelp(int helpMsgId, CharSequence helpString) {
  19.                // Help.
  20.            }
  21.            @Override
  22.            public void onAuthSucceeded(BioAuthnResult result) {
  23.                // Authentication successful.
  24.            }
  25.            @Override
  26.            public void onAuthFailed() {
  27.                // Authentication failed.
  28.            }
  29.        };
  30.        // Cancellation signal.
  31.        CancellationSignal cancellationSignal = new CancellationSignal();
  32.        FaceManager faceManager = new FaceManager(this);
  33.        int errorCode = faceManager.canAuth();
  34.        if (errorCode != 0) {
  35.            // Authentication is not supported.
  36.            return;
  37.        }
  38.        // Flags.
  39.        int flags = 0;
  40.        // Authentication message handler.
  41.        Handler handler = null;
  42.        // It is recommended that CryptoObject be set to null. In this version, KeyStore is not associated with facial authentication.  
  43.        // The value false must be passed to KeyGenParameterSpec.Builder.setUserAuthenticationRequired().
  44.        CryptoObject crypto = null;
  45.        faceManager.auth(crypto, cancellationSignal, flags, callback, handler);
  46.    }
  47. }
Note:

For more sample information, click fido-bioauthn-sample.zip to download the sample code.