I am implementing the android native fingerprint API's in my application. As per documentation FINGERPRINT_ERROR_TIMEOUT (3) is the error code that should be received in case there is a timeout. Also mentioned is:
int FINGERPRINT_ERROR_TIMEOUT
Error state returned when the current request has been running too long.
This is intended to prevent programs from waiting for the fingerprint sensor indefinitely.
The timeout is platform and sensor-specific, but is generally on the order of 30 seconds.
In my case this timeout callback is not happening. I am currently using Samsung S7 to test this. Can anybody help out as to how can we configure this value and in identifying why the timeout isn't happening by default.
Edit1:
Adding the code for the fingerprint handler:
@RequiresApi(api = Build.VERSION_CODES.M)
public class FingerprintHandler extends
FingerprintManager.AuthenticationCallback {
private CancellationSignal cancellationSignal;
private Context appContext;
private boolean sendCancellation=false;
public FingerprintHandler(Context context) {
appContext = context;
}
public void startAuth(FingerprintManager manager,
FingerprintManager.CryptoObject cryptoObject) {
cancellationSignal = new CancellationSignal();
if (ActivityCompat.checkSelfPermission(appContext,
Manifest.permission.USE_FINGERPRINT) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
@Override
public void onAuthenticationError(int errMsgId,
CharSequence errString) {
Log.d(TAG,"Authentication error callback");
Log.d(TAG,"Error Value: "+errMsgId);
switch(errMsgId){
case FINGERPRINT_ERROR_LOCKOUT:
Log.d(TAG,"Fingerprint error lockout");
nativeLocked = true;
mPreferences.edit().putLong(LAST_FAILURE, System.currentTimeMillis()).apply();
mPreferences.edit().putBoolean("nativeLocked", true).apply();
showError(getString(R.string.test_bio_fingerprint_fingerprint_authentication_failed));
mCancelButton.setEnabled(true);
dialogHandler.postDelayed(new Runnable() {
@Override
public void run() {
mCancelButton.setEnabled(true);
dismissDialog();
sendFailure();
}
}, SUCCESS_OR_FAIL_DELAY_MILLIS);
break;
case FINGERPRINT_ERROR_CANCELED:
Log.d(TAG,"Fingerprint has been cancelled");
if(sendCancellation) {
dismissDialog();
if (useEye)
sendCancelForEye();
else
sendCancel();
}
break;
}
}
@Override
public void onAuthenticationHelp(int helpMsgId,
CharSequence helpString) {
Log.d(TAG,"Authentication helper callback");
retryWithError(R.string.test_bio_fingerprint_fingerprint_too_fast);
}
@Override
public void onAuthenticationFailed() {
Log.d(TAG,"Authentication failed callback");
retryWithError(R.string.test_bio_fingerprint_fingerprint_not_recognized);
}
@Override
public void onAuthenticationSucceeded(
FingerprintManager.AuthenticationResult result) {
Log.d(TAG,"Authentication successfull callback");
onAuthenticationSuccess();
}
public void stopListening(boolean sendCancellation) {
this.sendCancellation=sendCancellation;
Log.d(TAG,"stopListening called");
if (cancellationSignal != null) {
cancellationSignal.cancel();
cancellationSignal = null;
}
}
}
This handler has been put inside a FingerprintDialog class which extends the DialogFragment class.
The below code is where he handler is initialized and the authentication is started:
helper = new FingerprintHandler(getContext());
fingerprintManager =(FingerprintManager) getContext().getSystemService(FINGERPRINT_SERVICE);
helper.startAuth(fingerprintManager, null);
Edit 2: Also it would be great if someone could point me to a source where this implementation works properly, where the timeout value has been configured. I could then compare my implementation with the working one to figure out if there is any issue in my implementation. I couldn't find anything helpful on the android developers site or on stackoverflow. I have raised an issue with google also: https://issuetracker.google.com/issues/63629654