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

import android.os.Looper;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArrayList;

/* JADX INFO: loaded from: classes2.dex */
public abstract class fo2 implements ep2 {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashSet f11328b = new HashSet(1);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final hp2 f11329c = new hp2();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final an2 f11330d = new an2();

    @Nullable
    private Looper zze;

    @Nullable
    private mk zzf;

    @Nullable
    private mk2 zzg;

    public void e() {
    }

    public void f() {
    }

    public abstract void g();

    public final void h(mk mkVar) {
        this.zzf = mkVar;
        ArrayList arrayList = this.f11327a;
        int size = arrayList.size();
        for (int i10 = 0; i10 < size; i10++) {
            ((dp2) arrayList.get(i10)).a(this, mkVar);
        }
    }

    public final mk2 i() {
        mk2 mk2Var = this.zzg;
        mk2Var.getClass();
        return mk2Var;
    }

    public final void j(ip2 ip2Var) {
        CopyOnWriteArrayList<fp2> copyOnWriteArrayList = this.f11329c.f12236a;
        for (fp2 fp2Var : copyOnWriteArrayList) {
            if (fp2Var.f11352b == ip2Var) {
                copyOnWriteArrayList.remove(fp2Var);
            }
        }
    }

    public final void k(bn2 bn2Var) {
        CopyOnWriteArrayList<zm2> copyOnWriteArrayList = this.f11330d.f8761a;
        for (zm2 zm2Var : copyOnWriteArrayList) {
            if (zm2Var.f19321a == bn2Var) {
                copyOnWriteArrayList.remove(zm2Var);
            }
        }
    }

    public final void l(dp2 dp2Var) {
        this.zze.getClass();
        HashSet hashSet = this.f11328b;
        boolean zIsEmpty = hashSet.isEmpty();
        hashSet.add(dp2Var);
        if (zIsEmpty) {
            e();
        }
    }

    public final void m(dp2 dp2Var) {
        HashSet hashSet = this.f11328b;
        boolean z10 = !hashSet.isEmpty();
        hashSet.remove(dp2Var);
        if (z10 && hashSet.isEmpty()) {
            f();
        }
    }

    public final void n(dp2 dp2Var) {
        ArrayList arrayList = this.f11327a;
        arrayList.remove(dp2Var);
        if (!arrayList.isEmpty()) {
            m(dp2Var);
            return;
        }
        this.zze = null;
        this.zzf = null;
        this.zzg = null;
        this.f11328b.clear();
        g();
    }

    @Override // com.google.android.gms.internal.ads.ep2
    @Nullable
    public /* bridge */ /* synthetic */ mk zzH() {
        return super.zzH();
    }

    public abstract void zza(@Nullable u92 u92Var);

    public final hp2 zzf(@Nullable cp2 cp2Var) {
        return this.f11329c.zza(0, cp2Var);
    }

    public final hp2 zzg(int i10, @Nullable cp2 cp2Var) {
        return this.f11329c.zza(0, cp2Var);
    }

    public final an2 zzh(@Nullable cp2 cp2Var) {
        return this.f11330d.zza(0, cp2Var);
    }

    public final an2 zzi(int i10, @Nullable cp2 cp2Var) {
        return this.f11330d.zza(0, cp2Var);
    }

    @Override // com.google.android.gms.internal.ads.ep2
    public final void zzp(dp2 dp2Var, @Nullable u92 u92Var, mk2 mk2Var) {
        Looper looperMyLooper = Looper.myLooper();
        Looper looper = this.zze;
        boolean z10 = true;
        if (looper != null && looper != looperMyLooper) {
            z10 = false;
        }
        ih1.x(z10);
        this.zzg = mk2Var;
        mk mkVar = this.zzf;
        this.f11327a.add(dp2Var);
        if (this.zze == null) {
            this.zze = looperMyLooper;
            this.f11328b.add(dp2Var);
            zza(u92Var);
        } else if (mkVar != null) {
            l(dp2Var);
            dp2Var.a(this, mkVar);
        }
    }
}
