package com.google.android.gms.internal.ads;

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes2.dex */
public final class gs0 {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final long f11852d;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Context f11854f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final WeakReference f11855g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final lq0 f11856h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final Executor f11857i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Executor f11858j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final ScheduledExecutorService f11859k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final jr0 f11860l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final q7.a f11861m;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final lj0 f11863o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final nd1 f11864p;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f11849a = false;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f11850b = false;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f11851c = false;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final e30 f11853e = new e30();

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final ConcurrentHashMap f11862n = new ConcurrentHashMap();

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public boolean f11865q = true;

    public gs0(Executor executor, Context context, WeakReference weakReference, a30 a30Var, lq0 lq0Var, ScheduledExecutorService scheduledExecutorService, jr0 jr0Var, q7.a aVar, lj0 lj0Var, nd1 nd1Var) {
        this.f11856h = lq0Var;
        this.f11854f = context;
        this.f11855g = weakReference;
        this.f11857i = a30Var;
        this.f11859k = scheduledExecutorService;
        this.f11858j = executor;
        this.f11860l = jr0Var;
        this.f11861m = aVar;
        this.f11863o = lj0Var;
        this.f11864p = nd1Var;
        m7.n.C.f30472k.getClass();
        this.f11852d = SystemClock.elapsedRealtime();
        d("com.google.android.gms.ads.MobileAds", 0, "", false);
    }

    public final void a() {
        final int i10 = 0;
        final int i11 = 1;
        if (!((Boolean) up.f17360a.j()).booleanValue()) {
            int i12 = this.f11861m.f32214c;
            tn tnVar = ao.f8929k2;
            n7.y yVar = n7.y.f31093e;
            if (i12 >= ((Integer) yVar.f31096c.b(tnVar)).intValue() && this.f11865q) {
                if (this.f11849a) {
                    return;
                }
                synchronized (this) {
                    try {
                        if (this.f11849a) {
                            return;
                        }
                        this.f11860l.d();
                        this.f11863o.zze();
                        e30 e30Var = this.f11853e;
                        Runnable runnable = new Runnable(this) { // from class: com.google.android.gms.internal.ads.es0

                            /* JADX INFO: renamed from: b, reason: collision with root package name */
                            public final /* synthetic */ gs0 f10914b;

                            {
                                this.f10914b = this;
                            }

                            @Override // java.lang.Runnable
                            public final void run() {
                                switch (i10) {
                                    case 0:
                                        gs0 gs0Var = this.f10914b;
                                        jr0 jr0Var = gs0Var.f11860l;
                                        synchronized (jr0Var) {
                                            try {
                                                if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9129w2)).booleanValue() && !jr0Var.f12996d) {
                                                    HashMap mapE = jr0Var.e();
                                                    mapE.put("action", "init_finished");
                                                    ArrayList arrayList = jr0Var.f12994b;
                                                    arrayList.add(mapE);
                                                    Iterator it = arrayList.iterator();
                                                    while (it.hasNext()) {
                                                        jr0Var.f12998f.a(false, (Map) it.next());
                                                    }
                                                    jr0Var.f12996d = true;
                                                }
                                            } catch (Throwable th) {
                                                throw th;
                                            }
                                        }
                                        gs0Var.f11863o.zzf();
                                        gs0Var.f11850b = true;
                                        return;
                                    default:
                                        gs0 gs0Var2 = this.f10914b;
                                        synchronized (gs0Var2) {
                                            try {
                                                if (gs0Var2.f11851c) {
                                                    return;
                                                }
                                                m7.n.C.f30472k.getClass();
                                                gs0Var2.d("com.google.android.gms.ads.MobileAds", (int) (SystemClock.elapsedRealtime() - gs0Var2.f11852d), "Timeout.", false);
                                                gs0Var2.f11860l.c("com.google.android.gms.ads.MobileAds", "timeout");
                                                gs0Var2.f11863o.a("com.google.android.gms.ads.MobileAds", "timeout");
                                                gs0Var2.f11853e.a(new Exception());
                                                return;
                                            } finally {
                                            }
                                        }
                                }
                            }
                        };
                        Executor executor = this.f11857i;
                        e30Var.g(runnable, executor);
                        this.f11849a = true;
                        com.google.common.util.concurrent.w wVarC = c();
                        this.f11859k.schedule(new Runnable(this) { // from class: com.google.android.gms.internal.ads.es0

                            /* JADX INFO: renamed from: b, reason: collision with root package name */
                            public final /* synthetic */ gs0 f10914b;

                            {
                                this.f10914b = this;
                            }

                            @Override // java.lang.Runnable
                            public final void run() {
                                switch (i11) {
                                    case 0:
                                        gs0 gs0Var = this.f10914b;
                                        jr0 jr0Var = gs0Var.f11860l;
                                        synchronized (jr0Var) {
                                            try {
                                                if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9129w2)).booleanValue() && !jr0Var.f12996d) {
                                                    HashMap mapE = jr0Var.e();
                                                    mapE.put("action", "init_finished");
                                                    ArrayList arrayList = jr0Var.f12994b;
                                                    arrayList.add(mapE);
                                                    Iterator it = arrayList.iterator();
                                                    while (it.hasNext()) {
                                                        jr0Var.f12998f.a(false, (Map) it.next());
                                                    }
                                                    jr0Var.f12996d = true;
                                                }
                                            } catch (Throwable th) {
                                                throw th;
                                            }
                                        }
                                        gs0Var.f11863o.zzf();
                                        gs0Var.f11850b = true;
                                        return;
                                    default:
                                        gs0 gs0Var2 = this.f10914b;
                                        synchronized (gs0Var2) {
                                            try {
                                                if (gs0Var2.f11851c) {
                                                    return;
                                                }
                                                m7.n.C.f30472k.getClass();
                                                gs0Var2.d("com.google.android.gms.ads.MobileAds", (int) (SystemClock.elapsedRealtime() - gs0Var2.f11852d), "Timeout.", false);
                                                gs0Var2.f11860l.c("com.google.android.gms.ads.MobileAds", "timeout");
                                                gs0Var2.f11863o.a("com.google.android.gms.ads.MobileAds", "timeout");
                                                gs0Var2.f11853e.a(new Exception());
                                                return;
                                            } finally {
                                            }
                                        }
                                }
                            }
                        }, ((Long) yVar.f31096c.b(ao.f8962m2)).longValue(), TimeUnit.SECONDS);
                        ih1.z1(wVarC, new dh0(this), executor);
                        return;
                    } catch (Throwable th) {
                        throw th;
                    }
                }
            }
        }
        if (this.f11849a) {
            return;
        }
        d("com.google.android.gms.ads.MobileAds", 0, "", true);
        this.f11853e.zzc(Boolean.FALSE);
        this.f11849a = true;
        this.f11850b = true;
    }

    public final ArrayList b() {
        ArrayList arrayList = new ArrayList();
        ConcurrentHashMap concurrentHashMap = this.f11862n;
        for (String str : concurrentHashMap.keySet()) {
            zt ztVar = (zt) concurrentHashMap.get(str);
            arrayList.add(new zt(str, ztVar.f19387c, ztVar.f19388d, ztVar.f19386b));
        }
        return arrayList;
    }

    public final synchronized com.google.common.util.concurrent.w c() {
        m7.n nVar = m7.n.C;
        String str = nVar.f30469h.g().t().f15240e;
        if (!TextUtils.isEmpty(str)) {
            return ih1.k(str);
        }
        e30 e30Var = new e30();
        p7.o0 o0VarG = nVar.f30469h.g();
        o0VarG.f31728c.add(new bv(this, e30Var, 27));
        return e30Var;
    }

    public final void d(String str, int i10, String str2, boolean z10) {
        this.f11862n.put(str, new zt(str, i10, str2, z10));
    }
}
