package a4; import android.util.Log; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.internal.p002firebaseauthapi.zzaas; import com.google.android.gms.tasks.Continuation; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; import com.google.android.recaptcha.RecaptchaAction; import com.google.firebase.auth.FirebaseAuth; /* loaded from: classes2.dex */ public abstract class z { static /* synthetic */ Task c(RecaptchaAction recaptchaAction, FirebaseAuth firebaseAuth, String str, Continuation continuation, Task task) { if (task.isSuccessful()) { return Tasks.forResult(task.getResult()); } Exception exc = (Exception) Preconditions.checkNotNull(task.getException()); int i10 = zzaas.zzb; if ((exc instanceof com.google.firebase.auth.k) && ((com.google.firebase.auth.k) exc).a().endsWith("MISSING_RECAPTCHA_TOKEN")) { if (Log.isLoggable("RecaptchaCallWrapper", 4)) { Log.i("RecaptchaCallWrapper", "Falling back to recaptcha enterprise flow for action ".concat(String.valueOf(recaptchaAction))); } if (firebaseAuth.i() == null) { firebaseAuth.r(new f0(firebaseAuth.b(), firebaseAuth)); } return d(firebaseAuth.i(), recaptchaAction, str, continuation); } Log.e("RecaptchaCallWrapper", "Initial task failed for action " + String.valueOf(recaptchaAction) + "with exception - " + exc.getMessage()); return Tasks.forException(exc); } private static Task d(f0 f0Var, RecaptchaAction recaptchaAction, String str, Continuation continuation) { Task a10 = f0Var.a(str, Boolean.FALSE, recaptchaAction); return a10.continueWithTask(continuation).continueWithTask(new y(str, f0Var, recaptchaAction, continuation)); } public abstract Task a(String str); public final Task b(final FirebaseAuth firebaseAuth, final String str, final RecaptchaAction recaptchaAction) { final Continuation continuation = new Continuation() { // from class: a4.w @Override // com.google.android.gms.tasks.Continuation public final Object then(Task task) { z zVar = z.this; if (task.isSuccessful()) { return zVar.a((String) task.getResult()); } Log.e("RecaptchaCallWrapper", "Failed to get Recaptcha token, error - " + ((Exception) Preconditions.checkNotNull(task.getException())).getMessage() + "\n\n Failing open with a fake token."); return zVar.a("NO_RECAPTCHA"); } }; f0 i10 = firebaseAuth.i(); return (i10 == null || !i10.e()) ? a(null).continueWithTask(new Continuation() { // from class: a4.x @Override // com.google.android.gms.tasks.Continuation public final Object then(Task task) { return z.c(RecaptchaAction.this, firebaseAuth, str, continuation, task); } }) : d(i10, recaptchaAction, str, continuation); } }