package n5;

import android.content.Context;
import androidx.room.x;
import com.google.android.gms.internal.ads.bv;
import com.google.android.gms.internal.ads.id1;
import com.google.android.gms.internal.ads.j02;
import com.google.android.gms.internal.ads.md1;
import com.google.android.gms.internal.ads.zu1;
import java.security.GeneralSecurityException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import ma.c0;
import ma.e0;
import ma.g0;
import xyz.stream.api.y;
import z3.w;

/* JADX INFO: loaded from: classes.dex */
public final class s implements l6.f, zu1 {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static volatile s f30878d;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f30880b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f30881c;

    public s(Context context, int i10) {
        if (i10 == 5) {
            ExecutorService executorService = q7.b.f32218b;
            this.f30881c = executorService;
            executorService.execute(new bv(this, context, 8));
        } else {
            this.f30881c = new HashSet();
            fe.h hVar = new fe.h(this, context, 9, 0);
            y yVar = new y();
            yVar.f36034b = hVar;
            this.f30880b = new x(yVar, new o(this));
        }
    }

    public static s c(Context context) {
        if (f30878d == null) {
            synchronized (s.class) {
                try {
                    if (f30878d == null) {
                        f30878d = new s(context.getApplicationContext(), 0);
                    }
                } finally {
                }
            }
        }
        return f30878d;
    }

    @Override // l6.f
    public final void a(ArrayList arrayList, boolean z10) {
        ((m6.f) this.f30881c).f30420n = z10;
        int size = arrayList.size();
        Object obj = this.f30881c;
        l6.h hVar = ((m6.f) obj).f30409c;
        boolean z11 = this.f30879a || ((m6.f) obj).f30419m > ((m6.f) this.f30881c).f30418l;
        if (z10) {
            boolean z12 = ((m6.f) this.f30881c).f30415i.get() > 0;
            ((m6.f) this.f30881c).f30415i.set(0);
            m6.f fVar = (m6.f) this.f30881c;
            fVar.getClass();
            if (!arrayList.isEmpty()) {
                synchronized (fVar.f30412f) {
                    for (int i10 = 0; i10 < arrayList.size(); i10++) {
                        try {
                            fVar.f30412f.add(((l6.b) arrayList.get(i10)).ajl());
                        } catch (Throwable th) {
                            throw th;
                        }
                    }
                }
                m6.d dVar = fVar.f30408b;
                if (!dVar.f30401e.hasMessages(1003, fVar)) {
                    dVar.f30401e.sendMessageDelayed(dVar.f30401e.obtainMessage(1003, fVar), dVar.f30398b.wsy());
                }
            }
            Object obj2 = this.f30881c;
            ((m6.f) obj2).f30408b.e((m6.f) obj2, z11, true, z12);
        } else {
            ((m6.f) this.f30881c).f30415i.getAndAdd(1);
            m6.f fVar2 = (m6.f) this.f30881c;
            fVar2.getClass();
            if (!arrayList.isEmpty()) {
                synchronized (fVar2.f30413g) {
                    for (int i11 = 0; i11 < arrayList.size(); i11++) {
                        try {
                            fVar2.f30413g.add(((l6.b) arrayList.get(i11)).ajl());
                        } catch (Throwable th2) {
                            throw th2;
                        }
                    }
                }
                m6.d dVar2 = fVar2.f30408b;
                if (!dVar2.f30401e.hasMessages(1004, fVar2)) {
                    dVar2.f30401e.sendMessageDelayed(dVar2.f30401e.obtainMessage(1004, fVar2), dVar2.f30398b.wsy());
                }
            }
            Object obj3 = this.f30881c;
            ((m6.f) obj3).f30408b.e((m6.f) obj3, z11, false, false);
        }
        Object obj4 = this.f30880b;
        if (((l6.f) obj4) != null) {
            ((l6.f) obj4).a(arrayList, z10);
        }
        if (z10) {
            Object obj5 = this.f30881c;
            if (((m6.f) obj5).f30416j != null) {
                ((m6.f) obj5).f30416j.a(2, size);
            }
        }
    }

    public final void b(String str, w wVar) {
        ((List) this.f30881c).add(new p0.d(str, wVar));
    }

    public final void d(c0 c0Var) throws GeneralSecurityException {
        if (c0Var == null) {
            throw new NullPointerException("primitive constructor must be non-null");
        }
        e0 e0Var = new e0(c0Var.f30503a, c0Var.f30504b);
        if (!((Map) this.f30880b).containsKey(e0Var)) {
            ((Map) this.f30880b).put(e0Var, c0Var);
            return;
        }
        c0 c0Var2 = (c0) ((Map) this.f30880b).get(e0Var);
        if (c0Var2.equals(c0Var) && c0Var.equals(c0Var2)) {
            return;
        }
        throw new GeneralSecurityException("Attempt to register non-equal PrimitiveConstructor object for already existing object of type: " + e0Var);
    }

    public final void e(g0 g0Var) throws GeneralSecurityException {
        Class clsB = g0Var.b();
        if (!((Map) this.f30881c).containsKey(clsB)) {
            ((Map) this.f30881c).put(clsB, g0Var);
            return;
        }
        g0 g0Var2 = (g0) ((Map) this.f30881c).get(clsB);
        if (g0Var2.equals(g0Var) && g0Var.equals(g0Var2)) {
            return;
        }
        throw new GeneralSecurityException("Attempt to register non-equal PrimitiveWrapper object or input class object for already existing object of type" + clsB);
    }

    public final void f(w8.r rVar) {
        synchronized (this.f30880b) {
            try {
                if (((Queue) this.f30881c) == null) {
                    this.f30881c = new ArrayDeque();
                }
                ((Queue) this.f30881c).add(rVar);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void g(w8.h hVar) {
        w8.r rVar;
        synchronized (this.f30880b) {
            if (((Queue) this.f30881c) != null && !this.f30879a) {
                this.f30879a = true;
                while (true) {
                    synchronized (this.f30880b) {
                        try {
                            rVar = (w8.r) ((Queue) this.f30881c).poll();
                            if (rVar == null) {
                                this.f30879a = false;
                                return;
                            }
                        } finally {
                        }
                    }
                    rVar.b(hVar);
                }
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.zu1
    public final void zza(Throwable th) {
        id1 id1Var = (id1) this.f30881c;
        if (id1Var.zzb()) {
            md1 md1Var = (md1) this.f30880b;
            id1Var.b(th);
            id1Var.a(false);
            md1Var.a(id1Var);
            if (this.f30879a) {
                md1Var.h();
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.zu1
    /* JADX INFO: renamed from: zzb */
    public final void mo3zzb(Object obj) {
        id1 id1Var = (id1) this.f30881c;
        id1Var.a(true);
        md1 md1Var = (md1) this.f30880b;
        md1Var.a(id1Var);
        if (this.f30879a) {
            md1Var.h();
        }
    }

    public s(int i10) {
        if (i10 == 2) {
            this.f30880b = "appassets.androidplatform.net";
            this.f30881c = new ArrayList();
            return;
        }
        if (i10 == 5) {
            this.f30881c = q7.b.f32218b;
            return;
        }
        if (i10 == 7) {
            this.f30880b = new ArrayList();
            this.f30881c = j02.f12676b;
            this.f30879a = false;
        } else {
            if (i10 == 8) {
                this.f30880b = new Object();
                return;
            }
            if (i10 != 9) {
                this.f30879a = false;
                this.f30880b = new ArrayList();
                this.f30881c = new ArrayList();
            } else {
                this.f30879a = false;
                this.f30880b = new HashMap();
                this.f30881c = new HashMap();
            }
        }
    }
}
