package s;

import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.fragment.app.z;
import androidx.lifecycle.c1;
import androidx.lifecycle.g0;
import com.google.firebase.perf.util.Constants;
import java.lang.ref.WeakReference;
import java.util.concurrent.Executor;
import s.f;

/* loaded from: classes.dex */
public class d extends androidx.fragment.app.f {

    /* renamed from: p, reason: collision with root package name */
    Handler f35118p = new Handler(Looper.getMainLooper());

    /* renamed from: q, reason: collision with root package name */
    s.g f35119q;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ int f35120p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ CharSequence f35121q;

        a(int i10, CharSequence charSequence) {
            this.f35120p = i10;
            this.f35121q = charSequence;
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.f35119q.W().a(this.f35120p, this.f35121q);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.f35119q.W().b();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class c implements g0 {
        c() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(f.b bVar) {
            if (bVar != null) {
                d.this.P(bVar);
                d.this.f35119q.v0(null);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: s.d$d, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public class C0827d implements g0 {
        C0827d() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(s.c cVar) {
            if (cVar != null) {
                d.this.M(cVar.b(), cVar.c());
                d.this.f35119q.s0(null);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class e implements g0 {
        e() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(CharSequence charSequence) {
            if (charSequence != null) {
                d.this.O(charSequence);
                d.this.f35119q.s0(null);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class f implements g0 {
        f() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(Boolean bool) {
            if (bool.booleanValue()) {
                d.this.N();
                d.this.f35119q.t0(false);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class g implements g0 {
        g() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(Boolean bool) {
            if (bool.booleanValue()) {
                if (d.this.I()) {
                    d.this.R();
                } else {
                    d.this.Q();
                }
                d.this.f35119q.I0(false);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class h implements g0 {
        h() {
        }

        @Override // androidx.lifecycle.g0
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void d(Boolean bool) {
            if (bool.booleanValue()) {
                d.this.A(1);
                d.this.dismiss();
                d.this.f35119q.D0(false);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class i implements Runnable {
        i() {
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.f35119q.E0(false);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class j implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ int f35131p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ CharSequence f35132q;

        j(int i10, CharSequence charSequence) {
            this.f35131p = i10;
            this.f35132q = charSequence;
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.S(this.f35131p, this.f35132q);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class k implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ f.b f35134p;

        k(f.b bVar) {
            this.f35134p = bVar;
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.f35119q.W().c(this.f35134p);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class l {
        static Intent a(KeyguardManager keyguardManager, CharSequence charSequence, CharSequence charSequence2) {
            return keyguardManager.createConfirmDeviceCredentialIntent(charSequence, charSequence2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class m {
        static void a(BiometricPrompt biometricPrompt, BiometricPrompt.CryptoObject cryptoObject, CancellationSignal cancellationSignal, Executor executor, BiometricPrompt.AuthenticationCallback authenticationCallback) {
            biometricPrompt.authenticate(cryptoObject, cancellationSignal, executor, authenticationCallback);
        }

        static void b(BiometricPrompt biometricPrompt, CancellationSignal cancellationSignal, Executor executor, BiometricPrompt.AuthenticationCallback authenticationCallback) {
            biometricPrompt.authenticate(cancellationSignal, executor, authenticationCallback);
        }

        static BiometricPrompt c(BiometricPrompt.Builder builder) {
            return builder.build();
        }

        static BiometricPrompt.Builder d(Context context) {
            return new BiometricPrompt.Builder(context);
        }

        static void e(BiometricPrompt.Builder builder, CharSequence charSequence) {
            builder.setDescription(charSequence);
        }

        static void f(BiometricPrompt.Builder builder, CharSequence charSequence, Executor executor, DialogInterface.OnClickListener onClickListener) {
            builder.setNegativeButton(charSequence, executor, onClickListener);
        }

        static void g(BiometricPrompt.Builder builder, CharSequence charSequence) {
            builder.setSubtitle(charSequence);
        }

        static void h(BiometricPrompt.Builder builder, CharSequence charSequence) {
            builder.setTitle(charSequence);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class n {
        static void a(BiometricPrompt.Builder builder, boolean z10) {
            builder.setConfirmationRequired(z10);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class o {
        static void a(BiometricPrompt.Builder builder, int i10) {
            builder.setAllowedAuthenticators(i10);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class p implements Executor {

        /* renamed from: p, reason: collision with root package name */
        private final Handler f35136p = new Handler(Looper.getMainLooper());

        p() {
        }

        @Override // java.util.concurrent.Executor
        public void execute(Runnable runnable) {
            this.f35136p.post(runnable);
        }
    }

    /* loaded from: classes.dex */
    private static class q implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        private final WeakReference f35137p;

        q(d dVar) {
            this.f35137p = new WeakReference(dVar);
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.f35137p.get() != null) {
                ((d) this.f35137p.get()).a0();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class r implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        private final WeakReference f35138p;

        r(s.g gVar) {
            this.f35138p = new WeakReference(gVar);
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.f35138p.get() != null) {
                ((s.g) this.f35138p.get()).C0(false);
            }
        }
    }

    private static int B(androidx.core.hardware.fingerprint.a aVar) {
        if (aVar.f()) {
            return !aVar.e() ? 11 : 0;
        }
        return 12;
    }

    private void C() {
        if (getActivity() == null) {
            return;
        }
        s.g gVar = (s.g) new c1(getActivity()).a(s.g.class);
        this.f35119q = gVar;
        gVar.T().j(this, new c());
        this.f35119q.R().j(this, new C0827d());
        this.f35119q.S().j(this, new e());
        this.f35119q.i0().j(this, new f());
        this.f35119q.q0().j(this, new g());
        this.f35119q.n0().j(this, new h());
    }

    private void D() {
        this.f35119q.L0(false);
        if (isAdded()) {
            z parentFragmentManager = getParentFragmentManager();
            s.l lVar = (s.l) parentFragmentManager.l0("androidx.biometric.FingerprintDialogFragment");
            if (lVar != null) {
                if (lVar.isAdded()) {
                    lVar.dismissAllowingStateLoss();
                } else {
                    parentFragmentManager.p().r(lVar).j();
                }
            }
        }
    }

    private int E() {
        Context context = getContext();
        return (context == null || !s.j.b(context, Build.MODEL)) ? 2000 : 0;
    }

    private void F(int i10) {
        if (i10 == -1) {
            V(new f.b(null, 1));
        } else {
            S(10, getString(s.r.f35226l));
        }
    }

    private boolean G() {
        androidx.fragment.app.k activity = getActivity();
        return (activity == null || this.f35119q.Y() == null || !s.j.c(activity, Build.MANUFACTURER, Build.MODEL)) ? false : true;
    }

    private boolean H() {
        return false;
    }

    private boolean J() {
        return G() || H();
    }

    private void K() {
        androidx.fragment.app.k activity = getActivity();
        if (activity == null) {
            Log.e("BiometricFragment", "Failed to check device credential. Client FragmentActivity not found.");
            return;
        }
        KeyguardManager a10 = s.m.a(activity);
        if (a10 == null) {
            S(12, getString(s.r.f35225k));
            return;
        }
        CharSequence h02 = this.f35119q.h0();
        CharSequence g02 = this.f35119q.g0();
        CharSequence Z = this.f35119q.Z();
        if (g02 == null) {
            g02 = Z;
        }
        Intent a11 = l.a(a10, h02, g02);
        if (a11 == null) {
            S(14, getString(s.r.f35224j));
            return;
        }
        this.f35119q.A0(true);
        if (J()) {
            D();
        }
        a11.setFlags(134742016);
        startActivityForResult(a11, 1);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static d L() {
        return new d();
    }

    private void T(int i10, CharSequence charSequence) {
        if (this.f35119q.l0()) {
            Log.v("BiometricFragment", "Error not sent to client. User is confirming their device credential.");
        } else if (!this.f35119q.j0()) {
            Log.w("BiometricFragment", "Error not sent to client. Client is not awaiting a result.");
        } else {
            this.f35119q.w0(false);
            this.f35119q.X().execute(new a(i10, charSequence));
        }
    }

    private void U() {
        if (this.f35119q.j0()) {
            this.f35119q.X().execute(new b());
        } else {
            Log.w("BiometricFragment", "Failure not sent to client. Client is not awaiting a result.");
        }
    }

    private void V(f.b bVar) {
        W(bVar);
        dismiss();
    }

    private void W(f.b bVar) {
        if (!this.f35119q.j0()) {
            Log.w("BiometricFragment", "Success not sent to client. Client is not awaiting a result.");
        } else {
            this.f35119q.w0(false);
            this.f35119q.X().execute(new k(bVar));
        }
    }

    private void X() {
        BiometricPrompt.Builder d10 = m.d(requireContext().getApplicationContext());
        CharSequence h02 = this.f35119q.h0();
        CharSequence g02 = this.f35119q.g0();
        CharSequence Z = this.f35119q.Z();
        if (h02 != null) {
            m.h(d10, h02);
        }
        if (g02 != null) {
            m.g(d10, g02);
        }
        if (Z != null) {
            m.e(d10, Z);
        }
        CharSequence f02 = this.f35119q.f0();
        if (!TextUtils.isEmpty(f02)) {
            m.f(d10, f02, this.f35119q.X(), this.f35119q.e0());
        }
        n.a(d10, this.f35119q.k0());
        o.a(d10, this.f35119q.P());
        y(m.c(d10), getContext());
    }

    private void Y() {
        Context applicationContext = requireContext().getApplicationContext();
        androidx.core.hardware.fingerprint.a c10 = androidx.core.hardware.fingerprint.a.c(applicationContext);
        int B = B(c10);
        if (B != 0) {
            S(B, s.k.a(applicationContext, B));
            return;
        }
        if (isAdded()) {
            this.f35119q.E0(true);
            if (!s.j.b(applicationContext, Build.MODEL)) {
                this.f35118p.postDelayed(new i(), 500L);
                s.l.C().show(getParentFragmentManager(), "androidx.biometric.FingerprintDialogFragment");
            }
            this.f35119q.x0(0);
            z(c10, applicationContext);
        }
    }

    private void Z(CharSequence charSequence) {
        if (charSequence == null) {
            charSequence = getString(s.r.f35216b);
        }
        this.f35119q.H0(2);
        this.f35119q.F0(charSequence);
    }

    void A(int i10) {
        if (i10 == 3 || !this.f35119q.p0()) {
            if (J()) {
                this.f35119q.x0(i10);
                if (i10 == 1) {
                    T(10, s.k.a(getContext(), 10));
                }
            }
            this.f35119q.V().a();
        }
    }

    boolean I() {
        return false;
    }

    void M(int i10, CharSequence charSequence) {
        if (!s.k.b(i10)) {
            i10 = 8;
        }
        getContext();
        if (!J()) {
            if (charSequence == null) {
                charSequence = getString(s.r.f35216b) + " " + i10;
            }
            S(i10, charSequence);
            return;
        }
        if (charSequence == null) {
            charSequence = s.k.a(getContext(), i10);
        }
        if (i10 == 5) {
            int U = this.f35119q.U();
            if (U == 0 || U == 3) {
                T(i10, charSequence);
            }
            dismiss();
            return;
        }
        if (this.f35119q.o0()) {
            S(i10, charSequence);
        } else {
            Z(charSequence);
            this.f35118p.postDelayed(new j(i10, charSequence), E());
        }
        this.f35119q.E0(true);
    }

    void N() {
        if (J()) {
            Z(getString(s.r.f35223i));
        }
        U();
    }

    void O(CharSequence charSequence) {
        if (J()) {
            Z(charSequence);
        }
    }

    void P(f.b bVar) {
        V(bVar);
    }

    void Q() {
        CharSequence f02 = this.f35119q.f0();
        if (f02 == null) {
            f02 = getString(s.r.f35216b);
        }
        S(13, f02);
        A(2);
    }

    void R() {
        K();
    }

    void S(int i10, CharSequence charSequence) {
        T(i10, charSequence);
        dismiss();
    }

    void a0() {
        if (this.f35119q.r0()) {
            return;
        }
        if (getContext() == null) {
            Log.w("BiometricFragment", "Not showing biometric prompt. Context is null.");
            return;
        }
        this.f35119q.L0(true);
        this.f35119q.w0(true);
        if (J()) {
            Y();
        } else {
            X();
        }
    }

    void dismiss() {
        this.f35119q.L0(false);
        D();
        if (!this.f35119q.l0() && isAdded()) {
            getParentFragmentManager().p().r(this).j();
        }
        Context context = getContext();
        if (context == null || !s.j.a(context, Build.MODEL)) {
            return;
        }
        this.f35119q.C0(true);
        this.f35118p.postDelayed(new r(this.f35119q), 600L);
    }

    @Override // androidx.fragment.app.f
    public void onActivityResult(int i10, int i11, Intent intent) {
        super.onActivityResult(i10, i11, intent);
        if (i10 == 1) {
            this.f35119q.A0(false);
            F(i11);
        }
    }

    @Override // androidx.fragment.app.f
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        C();
    }

    @Override // androidx.fragment.app.f
    public void onStart() {
        super.onStart();
    }

    @Override // androidx.fragment.app.f
    public void onStop() {
        super.onStop();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void x(f.d dVar, f.c cVar) {
        androidx.fragment.app.k activity = getActivity();
        if (activity == null) {
            Log.e("BiometricFragment", "Not launching prompt. Client activity was null.");
            return;
        }
        this.f35119q.K0(dVar);
        s.b.b(dVar, cVar);
        this.f35119q.B0(cVar);
        if (I()) {
            this.f35119q.J0(getString(s.r.f35215a));
        } else {
            this.f35119q.J0(null);
        }
        if (I() && s.e.b(activity).a(Constants.MAX_HOST_LENGTH) != 0) {
            this.f35119q.w0(true);
            K();
        } else if (this.f35119q.m0()) {
            this.f35118p.postDelayed(new q(this), 600L);
        } else {
            a0();
        }
    }

    void y(BiometricPrompt biometricPrompt, Context context) {
        BiometricPrompt.CryptoObject c10 = s.i.c(this.f35119q.Y());
        CancellationSignal b10 = this.f35119q.V().b();
        p pVar = new p();
        BiometricPrompt.AuthenticationCallback a10 = this.f35119q.Q().a();
        try {
            if (c10 == null) {
                m.b(biometricPrompt, b10, pVar, a10);
            } else {
                m.a(biometricPrompt, c10, b10, pVar, a10);
            }
        } catch (NullPointerException e10) {
            Log.e("BiometricFragment", "Got NPE while authenticating with biometric prompt.", e10);
            S(1, context != null ? context.getString(s.r.f35216b) : "");
        }
    }

    void z(androidx.core.hardware.fingerprint.a aVar, Context context) {
        try {
            aVar.b(s.i.d(this.f35119q.Y()), 0, this.f35119q.V().c(), this.f35119q.Q().b(), null);
        } catch (NullPointerException e10) {
            Log.e("BiometricFragment", "Got NPE while authenticating with fingerprint.", e10);
            S(1, s.k.a(context, 1));
        }
    }
}
