package com.google.common.util.concurrent;

import com.google.android.gms.internal.ads.cv1;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.v1;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;

/* JADX INFO: loaded from: classes2.dex */
public abstract class m extends o {
    public static final cv1 Q = new cv1(1, m.class);

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public ImmutableCollection f23801l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final boolean f23802m;

    public m(ImmutableList immutableList, boolean z10) {
        int size = immutableList.size();
        this.f23807h = null;
        this.f23808i = size;
        this.f23801l = immutableList;
        this.f23802m = z10;
    }

    @Override // com.google.common.util.concurrent.l
    public final void c() {
        ImmutableCollection immutableCollection = this.f23801l;
        q qVar = (q) this;
        qVar.f23801l = null;
        qVar.R = null;
        boolean z10 = false;
        if ((this.f23798a instanceof a) && (immutableCollection != null)) {
            Object obj = this.f23798a;
            if ((obj instanceof a) && ((a) obj).f23767a) {
                z10 = true;
            }
            v1 it = immutableCollection.iterator();
            while (it.hasNext()) {
                ((Future) it.next()).cancel(z10);
            }
        }
    }

    @Override // com.google.common.util.concurrent.l
    public final String l() {
        ImmutableCollection immutableCollection = this.f23801l;
        if (immutableCollection == null) {
            return super.l();
        }
        return "futures=" + immutableCollection;
    }

    public final void p(Set set) {
        set.getClass();
        if (this.f23798a instanceof a) {
            return;
        }
        Throwable thA = a();
        Objects.requireNonNull(thA);
        while (thA != null && set.add(thA)) {
            thA = thA.getCause();
        }
    }

    public final void q(ImmutableCollection immutableCollection) {
        int iF = o.f23805j.f(this);
        com.google.common.base.h.i(iF >= 0, "Less than 0 remaining futures");
        if (iF == 0) {
            if (immutableCollection != null) {
                v1 it = immutableCollection.iterator();
                while (it.hasNext()) {
                    Future future = (Future) it.next();
                    if (!future.isCancelled()) {
                        try {
                            c0.k(future);
                        } catch (ExecutionException e10) {
                            r(e10.getCause());
                        } catch (Throwable th) {
                            r(th);
                        }
                    }
                }
            }
            this.f23807h = null;
            q qVar = (q) this;
            CombinedFuture$CombinedFutureInterruptibleTask combinedFuture$CombinedFutureInterruptibleTask = qVar.R;
            if (combinedFuture$CombinedFutureInterruptibleTask != null) {
                combinedFuture$CombinedFutureInterruptibleTask.h();
            }
            qVar.f23801l = null;
        }
    }

    public final void r(Throwable th) {
        th.getClass();
        if (this.f23802m && !o(th)) {
            Set set = this.f23807h;
            if (set == null) {
                Set setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap());
                p(setNewSetFromMap);
                o.f23805j.e(this, setNewSetFromMap);
                set = this.f23807h;
                Objects.requireNonNull(set);
            }
            for (Throwable cause = th; cause != null; cause = cause.getCause()) {
                if (set.add(cause)) {
                }
            }
            Q.a().log(Level.SEVERE, th instanceof Error ? "Input Future failed with Error" : "Got more than one input Future failure. Logging failures after the first", th);
            return;
        }
        boolean z10 = th instanceof Error;
        if (z10) {
            Q.a().log(Level.SEVERE, z10 ? "Input Future failed with Error" : "Got more than one input Future failure. Logging failures after the first", th);
        }
    }

    public final void s(int i10, w wVar) {
        try {
            if (wVar.isCancelled()) {
                this.f23801l = null;
                cancel(false);
            } else {
                try {
                    c0.k(wVar);
                } catch (ExecutionException e10) {
                    r(e10.getCause());
                } catch (Throwable th) {
                    r(th);
                }
            }
        } finally {
            q(null);
        }
    }
}
