package n7;

import android.content.Context;
import android.os.RemoteException;
import androidx.annotation.Nullable;
import com.google.android.gms.ads.AdFormat;
import com.google.android.gms.ads.RequestConfiguration$PublisherPrivacyPersonalizationState;
import com.google.android.gms.ads.initialization.AdapterStatus$State;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.bp;
import com.google.android.gms.internal.ads.hs1;
import com.google.android.gms.internal.ads.mp;
import com.google.android.gms.internal.ads.uv;
import com.google.android.gms.internal.ads.zt;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static b3 f30909g;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f30911b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final g7.t f30915f;

    @Nullable
    private y2 zzb;

    @Nullable
    private d3 zzc;

    @Nullable
    private x2 zzd;

    @Nullable
    private s1 zzl;

    @Nullable
    private g7.m zzm;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f30910a = new Object();

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

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

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

    static {
        new HashSet(Arrays.asList(AdFormat.APP_OPEN_AD, AdFormat.INTERSTITIAL, AdFormat.REWARDED));
    }

    public b3() {
        g7.s sVar = new g7.s();
        this.f30915f = new g7.t(-1, -1, sVar.f26304c, (List) sVar.f26305d, (RequestConfiguration$PublisherPrivacyPersonalizationState) sVar.f26306e);
        this.f30911b = new ArrayList();
    }

    public static hs1 a(List list) {
        HashMap map = new HashMap();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            zt ztVar = (zt) it.next();
            map.put(ztVar.f19385a, new bp(ztVar.f19386b ? AdapterStatus$State.f7881b : AdapterStatus$State.f7880a, ztVar.f19388d, ztVar.f19387c));
        }
        hs1 hs1Var = new hs1();
        hs1Var.f12255a = map;
        return hs1Var;
    }

    public static b3 c() {
        b3 b3Var;
        synchronized (b3.class) {
            try {
                if (f30909g == null) {
                    f30909g = new b3();
                }
                b3Var = f30909g;
            } catch (Throwable th) {
                throw th;
            }
        }
        return b3Var;
    }

    private final void zzE(@Nullable String str) {
        s1 s1Var = this.zzl;
        if (s1Var == null) {
            return;
        }
        try {
            s1Var.zze();
            this.zzl.zzj(null, new k8.b(null));
        } catch (RemoteException unused) {
        }
    }

    public final void b(Context context) {
        if (this.zzl == null) {
            this.zzl = (s1) new r(x.f31085g.f31087b, context).a(context, false);
        }
    }

    public final void d() {
        synchronized (this.f30910a) {
            this.f30913d = false;
            this.f30912c = false;
            this.f30911b.clear();
        }
        synchronized (this.f30914e) {
            try {
                s1 s1Var = this.zzl;
                if (s1Var != null) {
                    s1Var.l();
                }
            } catch (RemoteException unused) {
            }
            this.zzl = null;
            y2 y2Var = this.zzb;
            if (y2Var != null) {
                y2Var.a();
                this.zzb = null;
            }
            d3 d3Var = this.zzc;
            if (d3Var != null) {
                d3Var.a();
                this.zzc = null;
            }
            x2 x2Var = this.zzd;
            if (x2Var != null) {
                x2Var.a();
                this.zzd = null;
            }
        }
    }

    public final l7.a e() {
        synchronized (this.f30914e) {
            com.google.android.gms.common.internal.w.h(this.zzl != null, "MobileAds.initialize() must be called prior to getting initialization status.");
            s1 s1Var = this.zzl;
            if (s1Var == null) {
                return new xyz.stream.api.a0(this, 16);
            }
            try {
                return a(s1Var.zzq());
            } catch (RemoteException unused) {
                q7.j.b("Unable to get Initialization status.");
                return new xyz.stream.api.a0(this, 16);
            }
        }
    }

    public final void f(String str) {
        synchronized (this.f30914e) {
            com.google.android.gms.common.internal.w.h(this.zzl != null, "MobileAds.initialize() must be called prior to setting the plugin.");
            s1 s1Var = this.zzl;
            if (s1Var == null) {
                return;
            }
            try {
                s1Var.w(str);
            } catch (RemoteException unused) {
            }
        }
    }

    public final /* synthetic */ void g() {
        synchronized (this.f30914e) {
            zzE(null);
        }
    }

    public final /* synthetic */ void h() {
        synchronized (this.f30914e) {
            zzE(null);
        }
    }

    @Nullable
    public final v7.b zza(AdFormat adFormat) {
        int iOrdinal = adFormat.ordinal();
        if (iOrdinal == 1) {
            return this.zzb;
        }
        if (iOrdinal == 2) {
            return this.zzc;
        }
        if (iOrdinal != 5) {
            return null;
        }
        return this.zzd;
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x009a A[Catch: all -> 0x004c, TryCatch #0 {all -> 0x004c, blocks: (B:25:0x0032, B:27:0x0039, B:30:0x004f, B:32:0x0056, B:34:0x005a, B:37:0x005f, B:38:0x0067, B:40:0x0078, B:42:0x008a, B:49:0x00cf, B:50:0x00ea, B:43:0x009a, B:45:0x00a8, B:47:0x00ba, B:48:0x00c6), top: B:59:0x0032 }] */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00c6 A[Catch: all -> 0x004c, TryCatch #0 {all -> 0x004c, blocks: (B:25:0x0032, B:27:0x0039, B:30:0x004f, B:32:0x0056, B:34:0x005a, B:37:0x005f, B:38:0x0067, B:40:0x0078, B:42:0x008a, B:49:0x00cf, B:50:0x00ea, B:43:0x009a, B:45:0x00a8, B:47:0x00ba, B:48:0x00c6), top: B:59:0x0032 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void zzc(Context context, @Nullable String str, @Nullable l7.b bVar) {
        s1 s1Var;
        synchronized (this.f30910a) {
            try {
                if (this.f30912c) {
                    if (bVar != null) {
                        this.f30911b.add(bVar);
                    }
                    return;
                }
                if (this.f30913d) {
                    if (bVar != null) {
                        e();
                        bVar.a();
                    }
                    return;
                }
                final int i10 = 1;
                this.f30912c = true;
                if (bVar != null) {
                    this.f30911b.add(bVar);
                }
                if (context == null) {
                    throw new IllegalArgumentException("Context cannot be null.");
                }
                synchronized (this.f30914e) {
                    try {
                        try {
                            b(context);
                            s1 s1Var2 = this.zzl;
                            if (s1Var2 != null) {
                                s1Var2.X0(new a3(this));
                                this.zzl.t2(new uv());
                            }
                            g7.t tVar = this.f30915f;
                            if ((tVar.f26308a != -1 || tVar.f26309b != -1) && (s1Var = this.zzl) != null) {
                                s1Var.K0(new q3(tVar));
                            }
                        } finally {
                        }
                    } catch (RemoteException unused) {
                    }
                    ao.a(context);
                    if (((Boolean) mp.f14325a.j()).booleanValue()) {
                        if (((Boolean) y.f31093e.f31096c.b(ao.f9072sc)).booleanValue()) {
                            q7.j.a("Initializing on bg thread");
                            q7.b.f32217a.execute(new Runnable(this) { // from class: n7.z2

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

                                {
                                    this.f31099b = this;
                                }

                                @Override // java.lang.Runnable
                                public final /* synthetic */ void run() {
                                    int i11 = i10;
                                    b3 b3Var = this.f31099b;
                                    switch (i11) {
                                        case 0:
                                            b3Var.h();
                                            break;
                                        default:
                                            b3Var.g();
                                            break;
                                    }
                                }
                            });
                        } else if (((Boolean) mp.f14326b.j()).booleanValue()) {
                            if (((Boolean) y.f31093e.f31096c.b(ao.f9072sc)).booleanValue()) {
                                final int i11 = 0;
                                q7.b.f32218b.execute(new Runnable(this) { // from class: n7.z2

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

                                    {
                                        this.f31099b = this;
                                    }

                                    @Override // java.lang.Runnable
                                    public final /* synthetic */ void run() {
                                        int i112 = i11;
                                        b3 b3Var = this.f31099b;
                                        switch (i112) {
                                            case 0:
                                                b3Var.h();
                                                break;
                                            default:
                                                b3Var.g();
                                                break;
                                        }
                                    }
                                });
                            } else {
                                q7.j.a("Initializing on calling thread");
                                zzE(null);
                            }
                        }
                    }
                    this.zzb = new y2(context, AdFormat.INTERSTITIAL);
                    this.zzc = new d3(context, AdFormat.REWARDED);
                    this.zzd = new x2(context, AdFormat.APP_OPEN_AD);
                }
            } finally {
            }
        }
    }
}
