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

import android.os.Handler;
import android.os.Looper;
import androidx.annotation.CheckResult;
import androidx.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.concurrent.CopyOnWriteArraySet;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Thread f13858a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayDeque f13860c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Object f13862e;

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

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

    @Nullable
    private final sq0 zzb;

    @Nullable
    private final mr0 zzc;

    public lt0(Looper looper, sl0 sl0Var, @Nullable mr0 mr0Var) {
        this(new CopyOnWriteArraySet(), looper, looper.getThread(), sl0Var, mr0Var, true);
    }

    public final void a(Object obj) {
        obj.getClass();
        synchronized (this.f13862e) {
            try {
                if (this.f13863f) {
                    return;
                }
                this.f13859b.add(new cs0(obj));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void b(Object obj) {
        g();
        CopyOnWriteArraySet<cs0> copyOnWriteArraySet = this.f13859b;
        for (cs0 cs0Var : copyOnWriteArraySet) {
            if (cs0Var.f10064a.equals(obj)) {
                mr0 mr0Var = this.zzc;
                cs0Var.f10067d = true;
                if (mr0Var != null && cs0Var.f10066c) {
                    cs0Var.f10066c = false;
                    mr0Var.a(cs0Var.f10064a, cs0Var.f10065b.f());
                }
                copyOnWriteArraySet.remove(cs0Var);
            }
        }
    }

    public final void c(int i10, dr0 dr0Var) {
        g();
        this.f13861d.add(new ms0(new CopyOnWriteArraySet(this.f13859b), i10, dr0Var, 0));
    }

    public final void d() {
        g();
        ArrayDeque arrayDeque = this.f13861d;
        if (arrayDeque.isEmpty()) {
            return;
        }
        if (this.zzc != null) {
            sq0 sq0Var = this.zzb;
            sq0Var.getClass();
            Handler handler = ((h81) sq0Var).f12056a;
            if (!handler.hasMessages(1)) {
                u71 u71VarE = h81.e();
                u71VarE.b(handler.obtainMessage(1));
                u71VarE.c(handler);
            }
        }
        ArrayDeque arrayDeque2 = this.f13860c;
        boolean zIsEmpty = true ^ arrayDeque2.isEmpty();
        arrayDeque2.addAll(arrayDeque);
        arrayDeque.clear();
        if (zIsEmpty) {
            return;
        }
        while (!arrayDeque2.isEmpty()) {
            ((Runnable) arrayDeque2.peekFirst()).run();
            arrayDeque2.removeFirst();
        }
    }

    public final void e() {
        g();
        synchronized (this.f13862e) {
            this.f13863f = true;
        }
        CopyOnWriteArraySet<cs0> copyOnWriteArraySet = this.f13859b;
        for (cs0 cs0Var : copyOnWriteArraySet) {
            mr0 mr0Var = this.zzc;
            cs0Var.f10067d = true;
            if (mr0Var != null && cs0Var.f10066c) {
                cs0Var.f10066c = false;
                mr0Var.a(cs0Var.f10064a, cs0Var.f10065b.f());
            }
        }
        copyOnWriteArraySet.clear();
    }

    public final void f() {
        mr0 mr0Var = this.zzc;
        mr0Var.getClass();
        for (cs0 cs0Var : this.f13859b) {
            if (!cs0Var.f10067d && cs0Var.f10066c) {
                wl2 wl2VarF = cs0Var.f10065b.f();
                cs0Var.f10065b = new e.t0(5);
                cs0Var.f10066c = false;
                mr0Var.a(cs0Var.f10064a, wl2VarF);
            }
            sq0 sq0Var = this.zzb;
            sq0Var.getClass();
            if (((h81) sq0Var).f12056a.hasMessages(1)) {
                return;
            }
        }
    }

    public final void g() {
        if (this.f13864g) {
            ih1.b1(Thread.currentThread() == this.f13858a);
        }
    }

    @CheckResult
    public final lt0 zza(Looper looper, @Nullable sl0 sl0Var, @Nullable mr0 mr0Var) {
        return new lt0(this.f13859b, looper, looper.getThread(), sl0Var, mr0Var, this.f13864g);
    }

    public lt0(Thread thread) {
        this(new CopyOnWriteArraySet(), null, thread, null, null, true);
    }

    private lt0(CopyOnWriteArraySet copyOnWriteArraySet, @Nullable Looper looper, Thread thread, @Nullable sl0 sl0Var, @Nullable mr0 mr0Var, boolean z10) {
        sq0 sq0VarZzd;
        this.f13858a = thread;
        this.f13859b = copyOnWriteArraySet;
        this.zzc = mr0Var;
        this.f13862e = new Object();
        this.f13860c = new ArrayDeque();
        this.f13861d = new ArrayDeque();
        if (looper == null || sl0Var == null || mr0Var == null) {
            sq0VarZzd = null;
        } else {
            sq0VarZzd = ((h71) sl0Var).zzd(looper, new ys0(this, 0));
        }
        this.zzb = sq0VarZzd;
        this.f13864g = z10;
    }
}
