android-play-safetynet
android-play-safetynet copied to clipboard
addOnFailureListener not trigger when user dismiss the verify dialog
library version used: com.google.android.gms:play-services-safetynet:11.4.2
I am using safety net captcha API. everything working as expected meaning, both are detected:
- on success (when test with real device and no harms detected)
- one failure listener (when test with Android emulator and verified the steps)
However, Here steps produce issue where on success and on failure are not detected:
- Run app in Android emulator
- Hit the SafetyNet verify with captcha
- As android emulator mark as possible harm, it will shows image for the verification
- Click on listen icon to listen the word
- Click on the screen outside the dialog area, the verification dialog will close
Expected: addOnFailureListener should be triggered because user didn't response to the verification steps when detected as robot
Actual: both OnSuccessListener and addOnFailureListener are not detected
Code:
SafetyNet.getClient(this).verifyWithRecaptcha(YOUR_API_SITE_KEY)
.addOnSuccessListener((Executor) this,
new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
@Override
public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
// Indicates communication with reCAPTCHA service was
// successful.
String userResponseToken = response.getTokenResult();
if (!userResponseToken.isEmpty()) {
// Validate the user response token using the
// reCAPTCHA siteverify API.
}
}
})
.addOnFailureListener((Executor) this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ApiException) {
// An error occurred when communicating with the
// reCAPTCHA service. Refer to the status code to
// handle the error appropriately.
ApiException apiException = (ApiException) e;
int statusCode = apiException.getStatusCode();
Log.d(TAG, "Error: " + CommonStatusCodes
.getStatusCodeString(statusCode));
} else {
// A different, unknown type of error occurred.
Log.d(TAG, "Error: " + e.getMessage());
}
}
});
Questions:
- Is it expected design in which if user dismiss the verification dialog then SafetyNet doesn't notify the listener?
- Are there any other listener for SafetyNet to handle the scenario above of the issue? or other solutions to handling this scenario from SafetyNet SDK?
Thanks
Hello. Did you found solution for that?
@iiw what we end up doing is dismiss all dialogs in onResume. I still think it would be nice to have the listener for this though. Hope it help.
I did same. Thanks.
I'm pretty sure it's a bug, Recaptcha should support or pass cancellation to addOnFailureListener, which I believe correct approach (because it's also the result of the operation), or at least trigger addOnCanceledListener, which also a solution, but I think it not so straightforward, an internal result of the task shouldn't cancel it
@vsay01 can you explain it more clearly when you are dismissing the dialog and how you know dialog is dismissed.
It has been years over it but still it's an open issue, that is nasty...
addOnCanceledListener is still not triggered. Not sure when this issue will be addressed.
5 years and still have this issue..