public class BioFingerprintActivity extends DeviceCVMKeyguardActivity {
private static String TAG = BioFingerprintActivity.class.getName();
private PaymentBusinessService paymentBusinessService;
private DeviceCVMVerifier deviceCVMVerifier;
private CancellationSignal cancellationSignal;
private TextView message;
private boolean isBioFPVerificationStarted = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bio_fingerprint_2);
unlockAndWake();
Bundle extras = getIntent().getExtras();
// get the cvm object passed through the bundle
CHVerificationMethod cvm = (CHVerificationMethod) extras.getSerializable(Tags.CVM);
message = (TextView) findViewById(R.id.message);
paymentBusinessService = PaymentBusinessManager.getPaymentBusinessService();
PaymentService paymentService = paymentBusinessService.getActivatedPaymentService();
// thanks to the cvm object get an intance to the 'DeviceCVMVerifier'
deviceCVMVerifier = (DeviceCVMVerifier) paymentService.getCHVerifier(cvm);
// set the corresponding listener
deviceCVMVerifier.setDeviceCVMVerifyListener(new DeviceCVMVerifyListener() {
@Override
public void onVerifySuccess() {
// Verification is OK!
message.setText("");
BioFingerprintActivity.this.finish();
}
@Override
public void onVerifyError(int errorCode, CharSequence charSequence) {
Log.d(TAG, "BioFingerprintActivity:error :" + errorCode);
// Special case when triggered in lock screen mode
// FINGERPRINT_ERROR_CANCELED error is raised
if (errorCode == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
Log.d(TAG, "restart Fp");
if (cancellationSignal != null)
cancellationSignal.cancel();
isBioFPVerificationStarted=true;
cancellationSignal = new CancellationSignal();
DeviceCVMVerifierInput input = new DeviceCVMVerifierInput(cancellationSignal);
deviceCVMVerifier.startAuthentication(input);
}
// usual handling of error code
else {
message.setText(charSequence + ". Please try again...");
if(errorCode == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT) {
confirmCredential("Verify by Keyguard", "Too many attempts. Please verify using your PIN / Pattern / Password");
}
}
}
@Override
public void onVerifyFailed() {
message.setText("Unable to recognize the fingerprint. Please try again.");
}
@Override
public void onVerifyHelp(int i, CharSequence charSequence) {
message.setText(charSequence + ". Please try again.");
}
});
deviceCVMVerifier.setKeyguardActivity(this);
cancellationSignal = new CancellationSignal();
//Start Authentication when the screen is ON and Unlock
if (DeviceUtil.isDeviceScreenOn(getApplicationContext())) {
Log.d(TAG, "Starting Fingerprint authentication");
DeviceCVMVerifierInput input = new DeviceCVMVerifierInput(cancellationSignal);
deviceCVMVerifier.startAuthentication(input);
} else {
Log.d(TAG, "Screen is de-activated, skipping Fingerprint authentication");
}
}
/* In case of fingerprint verification failure, implementing the following callback is possible
to fallback on the Keyguard verification.
**/
public void onKeyguardFallback(View v) {
Log.d(TAG, "onKeyguardFallback");
// call deviceCVMVerifier.startAuthentication(input)
}
@Override
public void onCancel(View v) {
Log.d(TAG, "Cancel authentication");
cancelTransaction("The transaction has been cancelled.");
}
@Override
public void onBackPressed() {
Log.d(TAG, "onBackPressed()");
cancelTransaction("The transaction has been cancelled.");
}
/*
After cancelling the fingerprint biometric authentication, the Payment service shall be deactivated
**/
private void cancelTransaction(String message) {
if (cancellationSignal != null) {
cancellationSignal.cancel();
}
PaymentBusinessManager.getPaymentBusinessService().deactivate();
}
}