android-play-safetynet icon indicating copy to clipboard operation
android-play-safetynet copied to clipboard

addOnFailureListener not trigger when user dismiss the verify dialog

Open vsay01 opened this issue 6 years ago • 8 comments

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

vsay01 avatar Mar 07 '18 03:03 vsay01

Hello. Did you found solution for that?

iiw avatar Feb 21 '19 10:02 iiw

@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.

vsay01 avatar Mar 01 '19 15:03 vsay01

I did same. Thanks.

iiw avatar Mar 01 '19 18:03 iiw

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

gildor avatar Oct 29 '20 04:10 gildor

@vsay01 can you explain it more clearly when you are dismissing the dialog and how you know dialog is dismissed.

vedraj360 avatar Oct 11 '21 11:10 vedraj360

It has been years over it but still it's an open issue, that is nasty...

mayuce avatar Dec 06 '21 13:12 mayuce

addOnCanceledListener is still not triggered. Not sure when this issue will be addressed.

chowdarym05 avatar Sep 23 '22 15:09 chowdarym05

5 years and still have this issue..

TareqAmenahDev avatar Feb 16 '23 08:02 TareqAmenahDev