package f9;

import android.util.Log;
import ca.canadapost.core.services.models.EpostOAuthLoginResponse;
import com.google.android.gms.tasks.Task;
import com.google.firebase.Firebase;
import com.google.firebase.appcheck.AppCheckToken;
import com.google.firebase.appcheck.FirebaseAppCheckKt;
import dn.p;
import g9.g;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import p9.h;
import rm.n0;
import rm.y;
import tp.j;
import tp.m0;
import tp.w0;
import uq.a0;
import uq.b0;
import uq.d0;
import uq.e0;
import uq.w;
import uq.x;

/* loaded from: classes.dex */
public final class a implements w {

    /* renamed from: j, reason: collision with root package name */
    public static final C0392a f17952j = new C0392a(null);

    /* renamed from: k, reason: collision with root package name */
    private static final x f17953k = x.f37620e.b("application/json");

    /* renamed from: a, reason: collision with root package name */
    private final h f17954a;

    /* renamed from: b, reason: collision with root package name */
    private final g f17955b;

    /* renamed from: c, reason: collision with root package name */
    private final AtomicReference f17956c;

    /* renamed from: d, reason: collision with root package name */
    private final AtomicReference f17957d;

    /* renamed from: e, reason: collision with root package name */
    private final AtomicInteger f17958e;

    /* renamed from: f, reason: collision with root package name */
    private final dq.a f17959f;

    /* renamed from: g, reason: collision with root package name */
    private final AtomicLong f17960g;

    /* renamed from: h, reason: collision with root package name */
    private final long f17961h;

    /* renamed from: i, reason: collision with root package name */
    private final dq.a f17962i;

    /* renamed from: f9.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0392a {
        private C0392a() {
        }

        public /* synthetic */ C0392a(k kVar) {
            this();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class b extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f17963p;

        /* renamed from: q, reason: collision with root package name */
        Object f17964q;

        /* renamed from: r, reason: collision with root package name */
        int f17965r;

        /* renamed from: s, reason: collision with root package name */
        int f17966s;

        /* renamed from: t, reason: collision with root package name */
        int f17967t;

        /* renamed from: u, reason: collision with root package name */
        long f17968u;

        /* renamed from: v, reason: collision with root package name */
        /* synthetic */ Object f17969v;

        /* renamed from: x, reason: collision with root package name */
        int f17971x;

        b(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f17969v = obj;
            this.f17971x |= Integer.MIN_VALUE;
            return a.this.d(0, 0L, this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class c extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f17972p;

        /* renamed from: q, reason: collision with root package name */
        Object f17973q;

        /* renamed from: r, reason: collision with root package name */
        long f17974r;

        /* renamed from: s, reason: collision with root package name */
        /* synthetic */ Object f17975s;

        /* renamed from: u, reason: collision with root package name */
        int f17977u;

        c(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f17975s = obj;
            this.f17977u |= Integer.MIN_VALUE;
            return a.this.f(this);
        }
    }

    /* loaded from: classes.dex */
    static final class d extends l implements p {

        /* renamed from: p, reason: collision with root package name */
        int f17978p;

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

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ a f17980r;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(boolean z10, a aVar, vm.d dVar) {
            super(2, dVar);
            this.f17979q = z10;
            this.f17980r = aVar;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new d(this.f17979q, this.f17980r, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f17978p;
            if (i10 == 0) {
                y.b(obj);
                if (!this.f17979q) {
                    return null;
                }
                a aVar = this.f17980r;
                this.f17978p = 1;
                obj = a.e(aVar, 0, 0L, this, 3, null);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            return (String) obj;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((d) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    /* loaded from: classes.dex */
    static final class e extends l implements p {

        /* renamed from: p, reason: collision with root package name */
        int f17981p;

        e(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new e(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f17981p;
            if (i10 == 0) {
                y.b(obj);
                a aVar = a.this;
                this.f17981p = 1;
                obj = aVar.f(this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            return obj;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((e) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    public a(h featureFlagRepository, g jwtTokenRepository) {
        t.g(featureFlagRepository, "featureFlagRepository");
        t.g(jwtTokenRepository, "jwtTokenRepository");
        this.f17954a = featureFlagRepository;
        this.f17955b = jwtTokenRepository;
        this.f17956c = new AtomicReference(null);
        this.f17957d = new AtomicReference(0L);
        this.f17958e = new AtomicInteger(0);
        this.f17959f = dq.c.b(false, 1, null);
        this.f17960g = new AtomicLong(0L);
        this.f17961h = 10000L;
        this.f17962i = dq.c.b(false, 1, null);
    }

    private final d0 c(b0 b0Var, String str) {
        Log.d("AppCheckInterceptor", str);
        return new d0.a().e(401).o(a0.HTTP_1_1).q(b0Var).l(str).b(e0.f37448q.a("{\"error\":\"app_check_failure\",\"message\":\"No valid token available\"}", f17953k)).c();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Can't wrap try/catch for region: R(12:1|(2:3|(9:5|6|(1:(1:(1:(11:11|12|13|14|15|(3:30|31|(1:33)(4:34|35|36|(7:38|(4:40|20|21|22)|41|(4:43|44|45|(1:47))|14|15|(6:17|18|19|20|21|22)(0))(2:50|51)))(0)|25|26|27|28|29)(2:66|67))(7:68|69|70|71|35|36|(0)(0)))(1:77))(2:92|(2:94|95)(2:96|(1:98)(1:99)))|78|79|80|81|82|(5:84|19|20|21|22)(7:86|(0)(0)|25|26|27|28|29)))|100|6|(0)(0)|78|79|80|81|82|(0)(0)|(1:(0))) */
    /* JADX WARN: Code restructure failed: missing block: B:87:0x01ca, code lost:
    
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:0x01cb, code lost:
    
        r13 = r1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:90:0x01ce, code lost:
    
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:91:0x01cf, code lost:
    
        r13 = r1;
     */
    /* JADX WARN: Removed duplicated region for block: B:17:0x019d A[Catch: all -> 0x01c6, TRY_ENTER, TRY_LEAVE, TryCatch #2 {all -> 0x01c6, blocks: (B:31:0x00dd, B:17:0x019d), top: B:30:0x00dd }] */
    /* JADX WARN: Removed duplicated region for block: B:30:0x00dd A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x011a A[Catch: all -> 0x0140, Exception -> 0x0145, TryCatch #0 {all -> 0x0140, blocks: (B:36:0x0105, B:38:0x011a, B:40:0x0120, B:50:0x0138, B:51:0x013f, B:56:0x014e), top: B:55:0x014e }] */
    /* JADX WARN: Removed duplicated region for block: B:43:0x0178  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0138 A[Catch: all -> 0x0140, Exception -> 0x0145, TryCatch #0 {all -> 0x0140, blocks: (B:36:0x0105, B:38:0x011a, B:40:0x0120, B:50:0x0138, B:51:0x013f, B:56:0x014e), top: B:55:0x014e }] */
    /* JADX WARN: Removed duplicated region for block: B:84:0x00cd A[Catch: all -> 0x01ca, TRY_LEAVE, TryCatch #5 {all -> 0x01ca, blocks: (B:82:0x00c7, B:84:0x00cd), top: B:81:0x00c7 }] */
    /* JADX WARN: Removed duplicated region for block: B:86:0x00d6  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x002d  */
    /* JADX WARN: Removed duplicated region for block: B:92:0x0088  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:42:0x0176 -> B:14:0x0190). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:46:0x018d -> B:14:0x0190). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object d(int i10, long j10, vm.d dVar) {
        b bVar;
        Object f10;
        int i11;
        dq.a aVar;
        long j11;
        a aVar2;
        int i12;
        dq.a aVar3;
        int i13;
        dq.a aVar4;
        int i14;
        a aVar5;
        long j12;
        Object obj;
        dq.a aVar6;
        int i15;
        int i16;
        Exception e10;
        int i17;
        int i18;
        long j13;
        int i19;
        a aVar7;
        String token;
        boolean C;
        if (dVar instanceof b) {
            bVar = (b) dVar;
            int i20 = bVar.f17971x;
            if ((i20 & Integer.MIN_VALUE) != 0) {
                bVar.f17971x = i20 - Integer.MIN_VALUE;
                Object obj2 = bVar.f17969v;
                f10 = wm.d.f();
                i11 = bVar.f17971x;
                boolean z10 = false;
                if (i11 != 0) {
                    y.b(obj2);
                    if (System.currentTimeMillis() - this.f17960g.get() < this.f17961h) {
                        Log.w("AppCheckInterceptor", "App Check throttled — skipping token fetch due to recent failure.");
                        return null;
                    }
                    aVar = this.f17959f;
                    bVar.f17963p = this;
                    bVar.f17964q = aVar;
                    bVar.f17965r = i10;
                    j11 = j10;
                    bVar.f17968u = j11;
                    bVar.f17971x = 1;
                    if (aVar.a(null, bVar) == f10) {
                        return f10;
                    }
                    aVar2 = this;
                    i12 = i10;
                } else if (i11 == 1) {
                    j11 = bVar.f17968u;
                    i12 = bVar.f17965r;
                    dq.a aVar8 = (dq.a) bVar.f17964q;
                    aVar2 = (a) bVar.f17963p;
                    y.b(obj2);
                    aVar = aVar8;
                } else {
                    if (i11 != 2) {
                        if (i11 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        i18 = bVar.f17966s;
                        j13 = bVar.f17968u;
                        i19 = bVar.f17965r;
                        aVar3 = (dq.a) bVar.f17964q;
                        aVar7 = (a) bVar.f17963p;
                        try {
                            y.b(obj2);
                            aVar4 = aVar3;
                            aVar5 = aVar7;
                            i13 = i19;
                            j12 = j13;
                            i14 = i18 + 1;
                            z10 = false;
                            if (i14 >= i13) {
                                try {
                                    try {
                                    } catch (Throwable th2) {
                                        th = th2;
                                        aVar3 = aVar4;
                                    }
                                } catch (Exception e11) {
                                    try {
                                        e10 = e11;
                                        i16 = i14;
                                        i15 = i16;
                                        aVar6 = aVar4;
                                        Log.w("AppCheckInterceptor", "App Check attempt " + r1 + " failed: " + e10.getMessage());
                                        i17 = i16;
                                        i18 = i15;
                                        j13 = j12;
                                        i19 = i13;
                                        aVar3 = aVar6;
                                        aVar7 = aVar5;
                                        if (i17 < i19 - 1) {
                                        }
                                        aVar4 = aVar3;
                                        aVar5 = aVar7;
                                        i13 = i19;
                                        j12 = j13;
                                        i14 = i18 + 1;
                                        z10 = false;
                                        if (i14 >= i13) {
                                        }
                                        th = th2;
                                        aVar3 = aVar4;
                                    } catch (Throwable th3) {
                                        th = th3;
                                        aVar3 = aVar6;
                                    }
                                    int i21 = i16 + 1;
                                    obj = null;
                                    aVar3.d(obj);
                                    throw th;
                                }
                                Task<AppCheckToken> appCheckToken = FirebaseAppCheckKt.getAppCheck(Firebase.INSTANCE).getAppCheckToken(z10);
                                t.f(appCheckToken, "getAppCheckToken(...)");
                                bVar.f17963p = aVar5;
                                bVar.f17964q = aVar4;
                                bVar.f17965r = i13;
                                bVar.f17968u = j12;
                                bVar.f17966s = i14;
                                bVar.f17967t = i14;
                                bVar.f17971x = 2;
                                Object a10 = eq.b.a(appCheckToken, bVar);
                                if (a10 == f10) {
                                    return f10;
                                }
                                i15 = i14;
                                aVar6 = aVar4;
                                obj2 = a10;
                                i17 = i15;
                                try {
                                } catch (Exception e12) {
                                    e10 = e12;
                                    i16 = i17;
                                    int i212 = i16 + 1;
                                    Log.w("AppCheckInterceptor", "App Check attempt " + i212 + " failed: " + e10.getMessage());
                                    i17 = i16;
                                    i18 = i15;
                                    j13 = j12;
                                    i19 = i13;
                                    aVar3 = aVar6;
                                    aVar7 = aVar5;
                                    if (i17 < i19 - 1) {
                                    }
                                    aVar4 = aVar3;
                                    aVar5 = aVar7;
                                    i13 = i19;
                                    j12 = j13;
                                    i14 = i18 + 1;
                                    z10 = false;
                                    if (i14 >= i13) {
                                    }
                                    th = th2;
                                    aVar3 = aVar4;
                                    obj = null;
                                    aVar3.d(obj);
                                    throw th;
                                }
                                token = ((AppCheckToken) obj2).getToken();
                                t.f(token, "getToken(...)");
                                if (!aVar5.f17954a.d(p9.a.SIMULATE_FAILED_APP_CHECK)) {
                                    throw new Exception("Simulated App Check failure");
                                }
                                C = kotlin.text.y.C(token);
                                if (!C) {
                                    Log.d("AppCheckInterceptor", "App Check token acquired on attempt " + (i17 + 1));
                                    aVar = aVar6;
                                    aVar.d(null);
                                    return token;
                                }
                                i18 = i15;
                                j13 = j12;
                                i19 = i13;
                                aVar3 = aVar6;
                                aVar7 = aVar5;
                                if (i17 < i19 - 1) {
                                    long j14 = (1 << i17) * j13;
                                    try {
                                        bVar.f17963p = aVar7;
                                        bVar.f17964q = aVar3;
                                        bVar.f17965r = i19;
                                        bVar.f17968u = j13;
                                        bVar.f17966s = i18;
                                        bVar.f17971x = 3;
                                        if (w0.a(j14, bVar) == f10) {
                                            return f10;
                                        }
                                    } catch (Throwable th4) {
                                        th = th4;
                                    }
                                }
                                aVar4 = aVar3;
                                aVar5 = aVar7;
                                i13 = i19;
                                j12 = j13;
                                i14 = i18 + 1;
                                z10 = false;
                                if (i14 >= i13) {
                                    aVar5.f17960g.set(System.currentTimeMillis());
                                    Log.e("AppCheckInterceptor", "App Check token retrieval failed after " + i13 + " attempts.");
                                    aVar = aVar4;
                                    token = null;
                                    aVar.d(null);
                                    return token;
                                }
                            }
                            th = th2;
                            aVar3 = aVar4;
                        } catch (Throwable th5) {
                            th = th5;
                            obj = null;
                            aVar3.d(obj);
                            throw th;
                        }
                        obj = null;
                        aVar3.d(obj);
                        throw th;
                    }
                    i16 = bVar.f17967t;
                    i15 = bVar.f17966s;
                    j12 = bVar.f17968u;
                    i13 = bVar.f17965r;
                    aVar6 = (dq.a) bVar.f17964q;
                    a aVar9 = (a) bVar.f17963p;
                    try {
                        y.b(obj2);
                        i17 = i16;
                        aVar5 = aVar9;
                    } catch (Exception e13) {
                        e10 = e13;
                        aVar5 = aVar9;
                        int i2122 = i16 + 1;
                        Log.w("AppCheckInterceptor", "App Check attempt " + i2122 + " failed: " + e10.getMessage());
                        i17 = i16;
                        i18 = i15;
                        j13 = j12;
                        i19 = i13;
                        aVar3 = aVar6;
                        aVar7 = aVar5;
                        if (i17 < i19 - 1) {
                        }
                        aVar4 = aVar3;
                        aVar5 = aVar7;
                        i13 = i19;
                        j12 = j13;
                        i14 = i18 + 1;
                        z10 = false;
                        if (i14 >= i13) {
                        }
                        th = th2;
                        aVar3 = aVar4;
                        obj = null;
                        aVar3.d(obj);
                        throw th;
                    } catch (Throwable th6) {
                        th = th6;
                        obj = null;
                        aVar3 = aVar6;
                    }
                    token = ((AppCheckToken) obj2).getToken();
                    t.f(token, "getToken(...)");
                    if (!aVar5.f17954a.d(p9.a.SIMULATE_FAILED_APP_CHECK)) {
                    }
                }
                if (System.currentTimeMillis() - aVar2.f17960g.get() >= aVar2.f17961h) {
                    Log.w("AppCheckInterceptor", "App Check throttled inside lock — skipping token fetch.");
                    token = null;
                    aVar.d(null);
                    return token;
                }
                i13 = i12;
                aVar4 = aVar;
                i14 = 0;
                aVar5 = aVar2;
                j12 = j11;
                if (i14 >= i13) {
                }
                th = th2;
                aVar3 = aVar4;
                obj = null;
                aVar3.d(obj);
                throw th;
            }
        }
        bVar = new b(dVar);
        Object obj22 = bVar.f17969v;
        f10 = wm.d.f();
        i11 = bVar.f17971x;
        boolean z102 = false;
        if (i11 != 0) {
        }
        if (System.currentTimeMillis() - aVar2.f17960g.get() >= aVar2.f17961h) {
        }
    }

    static /* synthetic */ Object e(a aVar, int i10, long j10, vm.d dVar, int i11, Object obj) {
        if ((i11 & 1) != 0) {
            i10 = 3;
        }
        if ((i11 & 2) != 0) {
            j10 = 3000;
        }
        return aVar.d(i10, j10, dVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:15:0x011b A[Catch: all -> 0x0039, TryCatch #1 {all -> 0x0039, blocks: (B:12:0x0034, B:13:0x0117, B:15:0x011b, B:17:0x0123, B:21:0x012e, B:23:0x0134, B:24:0x013f, B:26:0x0143, B:27:0x0149, B:31:0x0162), top: B:11:0x0034 }] */
    /* JADX WARN: Removed duplicated region for block: B:20:0x012c  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x0162 A[Catch: all -> 0x0039, TRY_LEAVE, TryCatch #1 {all -> 0x0039, blocks: (B:12:0x0034, B:13:0x0117, B:15:0x011b, B:17:0x0123, B:21:0x012e, B:23:0x0134, B:24:0x013f, B:26:0x0143, B:27:0x0149, B:31:0x0162), top: B:11:0x0034 }] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x0168  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0120  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00b9 A[Catch: all -> 0x0175, TryCatch #0 {all -> 0x0175, blocks: (B:48:0x009b, B:50:0x00ad, B:55:0x00b9, B:57:0x00c4, B:58:0x00cb, B:62:0x00eb, B:67:0x00f8, B:70:0x0104, B:75:0x016b), top: B:47:0x009b }] */
    /* JADX WARN: Removed duplicated region for block: B:60:0x00e6  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00eb A[Catch: all -> 0x0175, TryCatch #0 {all -> 0x0175, blocks: (B:48:0x009b, B:50:0x00ad, B:55:0x00b9, B:57:0x00c4, B:58:0x00cb, B:62:0x00eb, B:67:0x00f8, B:70:0x0104, B:75:0x016b), top: B:47:0x009b }] */
    /* JADX WARN: Removed duplicated region for block: B:76:0x00e8  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0054  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0028  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object f(vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        long currentTimeMillis;
        dq.a aVar;
        Throwable th2;
        dq.a aVar2;
        String str;
        boolean z10;
        String c10;
        a aVar3;
        EpostOAuthLoginResponse epostOAuthLoginResponse;
        String id_token;
        Integer expiresIn;
        try {
            if (dVar instanceof c) {
                cVar = (c) dVar;
                int i11 = cVar.f17977u;
                if ((i11 & Integer.MIN_VALUE) != 0) {
                    cVar.f17977u = i11 - Integer.MIN_VALUE;
                    Object obj = cVar.f17975s;
                    f10 = wm.d.f();
                    i10 = cVar.f17977u;
                    if (i10 != 0) {
                        y.b(obj);
                        currentTimeMillis = System.currentTimeMillis();
                        String str2 = (String) this.f17956c.get();
                        Long l10 = (Long) this.f17957d.get();
                        if (!(str2 == null || str2.length() == 0)) {
                            t.d(l10);
                            if (currentTimeMillis < l10.longValue()) {
                                Log.d("AppCheckInterceptor", "Using cached fallback JWT token (outside lock).");
                                return str2;
                            }
                        }
                        aVar = this.f17962i;
                        cVar.f17972p = this;
                        cVar.f17973q = aVar;
                        cVar.f17974r = currentTimeMillis;
                        cVar.f17977u = 1;
                        if (aVar.a(null, cVar) == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            if (i10 != 2) {
                                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                            }
                            aVar2 = (dq.a) cVar.f17973q;
                            aVar3 = (a) cVar.f17972p;
                            try {
                                y.b(obj);
                                epostOAuthLoginResponse = (EpostOAuthLoginResponse) obj;
                                id_token = epostOAuthLoginResponse == null ? epostOAuthLoginResponse.getId_token() : null;
                                if (!(id_token != null || id_token.length() == 0)) {
                                    int intValue = (epostOAuthLoginResponse == null || (expiresIn = epostOAuthLoginResponse.getExpiresIn()) == null) ? 1800000 : (expiresIn.intValue() * 1000) / 2;
                                    aVar3.f17956c.set(epostOAuthLoginResponse != null ? epostOAuthLoginResponse.getId_token() : null);
                                    aVar3.f17957d.set(kotlin.coroutines.jvm.internal.b.d(System.currentTimeMillis() + intValue));
                                    Log.d("AppCheckInterceptor", "New fallback JWT token generated and cached. (inside lock)");
                                }
                                if (epostOAuthLoginResponse == null) {
                                    str = epostOAuthLoginResponse.getId_token();
                                    aVar = aVar2;
                                    aVar.d(null);
                                    return str;
                                }
                                aVar = aVar2;
                                str = null;
                                aVar.d(null);
                                return str;
                            } catch (Throwable th3) {
                                th2 = th3;
                                aVar2.d(null);
                                throw th2;
                            }
                        }
                        currentTimeMillis = cVar.f17974r;
                        dq.a aVar4 = (dq.a) cVar.f17973q;
                        a aVar5 = (a) cVar.f17972p;
                        y.b(obj);
                        aVar = aVar4;
                        this = aVar5;
                    }
                    str = (String) this.f17956c.get();
                    Long l11 = (Long) this.f17957d.get();
                    if (str != null && str.length() != 0) {
                        z10 = false;
                        if (!z10) {
                            t.d(l11);
                            if (currentTimeMillis < l11.longValue()) {
                                Log.d("AppCheckInterceptor", "Using cached fallback JWT token (inside lock).");
                                aVar.d(null);
                                return str;
                            }
                        }
                        Log.d("AppCheckInterceptor", "Cached fallback JWT token expired or missing :, generating new one... (inside lock)");
                        c10 = this.f17954a.c(p9.a.APP_CHECK_FAILED_ID);
                        String c11 = this.f17954a.c(p9.a.APP_CHECK_FAILED_KEY);
                        if (!(c10.length() != 0)) {
                            if (!(c11.length() == 0)) {
                                if (this.f17954a.d(p9.a.SIMULATE_FAILED_JWT_TOKEN)) {
                                    str = null;
                                    aVar.d(null);
                                    return str;
                                }
                                g gVar = this.f17955b;
                                cVar.f17972p = this;
                                cVar.f17973q = aVar;
                                cVar.f17977u = 2;
                                Object a10 = gVar.a(c10, c11, cVar);
                                if (a10 == f10) {
                                    return f10;
                                }
                                aVar3 = this;
                                aVar2 = aVar;
                                obj = a10;
                                epostOAuthLoginResponse = (EpostOAuthLoginResponse) obj;
                                if (epostOAuthLoginResponse == null) {
                                }
                                if (!(id_token != null || id_token.length() == 0)) {
                                }
                                if (epostOAuthLoginResponse == null) {
                                }
                            }
                        }
                        Log.e("AppCheckInterceptor", "Fallback credentials are missing from remote config. (inside lock)");
                        str = null;
                        aVar.d(null);
                        return str;
                    }
                    z10 = true;
                    if (!z10) {
                    }
                    Log.d("AppCheckInterceptor", "Cached fallback JWT token expired or missing :, generating new one... (inside lock)");
                    c10 = this.f17954a.c(p9.a.APP_CHECK_FAILED_ID);
                    String c112 = this.f17954a.c(p9.a.APP_CHECK_FAILED_KEY);
                    if (!(c10.length() != 0)) {
                    }
                    Log.e("AppCheckInterceptor", "Fallback credentials are missing from remote config. (inside lock)");
                    str = null;
                    aVar.d(null);
                    return str;
                }
            }
            str = (String) this.f17956c.get();
            Long l112 = (Long) this.f17957d.get();
            if (str != null) {
                z10 = false;
                if (!z10) {
                }
                Log.d("AppCheckInterceptor", "Cached fallback JWT token expired or missing :, generating new one... (inside lock)");
                c10 = this.f17954a.c(p9.a.APP_CHECK_FAILED_ID);
                String c1122 = this.f17954a.c(p9.a.APP_CHECK_FAILED_KEY);
                if (!(c10.length() != 0)) {
                }
                Log.e("AppCheckInterceptor", "Fallback credentials are missing from remote config. (inside lock)");
                str = null;
                aVar.d(null);
                return str;
            }
            z10 = true;
            if (!z10) {
            }
            Log.d("AppCheckInterceptor", "Cached fallback JWT token expired or missing :, generating new one... (inside lock)");
            c10 = this.f17954a.c(p9.a.APP_CHECK_FAILED_ID);
            String c11222 = this.f17954a.c(p9.a.APP_CHECK_FAILED_KEY);
            if (!(c10.length() != 0)) {
            }
            Log.e("AppCheckInterceptor", "Fallback credentials are missing from remote config. (inside lock)");
            str = null;
            aVar.d(null);
            return str;
        } catch (Throwable th4) {
            dq.a aVar6 = aVar;
            th2 = th4;
            aVar2 = aVar6;
            aVar2.d(null);
            throw th2;
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f17975s;
        f10 = wm.d.f();
        i10 = cVar.f17977u;
        if (i10 != 0) {
        }
    }

    @Override // uq.w
    public d0 intercept(w.a chain) {
        Object b10;
        Object b11;
        t.g(chain, "chain");
        int incrementAndGet = this.f17958e.incrementAndGet();
        Thread currentThread = Thread.currentThread();
        Log.d("AppCheckInterceptor", "counter: " + incrementAndGet + " | Thread ID: " + currentThread.getId() + ", Name: " + currentThread.getName());
        b0 g10 = chain.g();
        boolean d10 = this.f17954a.d(p9.a.FIREBASE_APP_CHECK);
        b0.a a10 = g10.h().a("X-Platform", "android");
        d dVar = new d(d10, this, null);
        boolean z10 = true;
        b10 = j.b(null, dVar, 1, null);
        String str = (String) b10;
        if (t.b(str, "0")) {
            return c(g10, "App Check request dropped due to concurrent access.");
        }
        if (!(str == null || str.length() == 0)) {
            Log.d("AppCheckInterceptor", "App Check token added to request.");
            return chain.b(a10.a("X-Firebase-AppCheck", str).b());
        }
        b11 = j.b(null, new e(null), 1, null);
        String str2 = (String) b11;
        if (str2 != null && str2.length() != 0) {
            z10 = false;
        }
        return !z10 ? chain.b(a10.a("X-Platform-JWTToken", str2).b()) : chain.b(a10.b());
    }
}
