package defpackage;

import com.google.common.util.concurrent.ListenableFuture;
import j$.util.Objects;
import j$.util.concurrent.ConcurrentHashMap;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Level;

/* renamed from: ᵫᵙ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3960 extends AbstractC0182 {

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public static final C5081 f14939 = new C5081(0, C3960.class);

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public C3643 f14940;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public AbstractC3821 f14941;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public final boolean f14942;

    public C3960(AbstractC3821 abstractC3821, boolean z) {
        int size = abstractC3821.size();
        this.f1619 = null;
        this.f1618 = size;
        this.f14941 = abstractC3821;
        this.f14942 = z;
    }

    /* renamed from: ˑᵱ, reason: contains not printable characters */
    public final void m8760(ListenableFuture listenableFuture) {
        try {
            boolean z = false;
            if (listenableFuture.isCancelled()) {
                this.f14941 = null;
                cancel(false);
            } else {
                while (true) {
                    try {
                        try {
                            listenableFuture.get();
                            break;
                        } catch (InterruptedException unused) {
                            z = true;
                        } catch (Throwable th) {
                            if (z) {
                                Thread.currentThread().interrupt();
                            }
                            throw th;
                        }
                    } catch (ExecutionException e) {
                        m8761(e.getCause());
                    } catch (Throwable th2) {
                        m8761(th2);
                    }
                }
                if (z) {
                    Thread.currentThread().interrupt();
                }
            }
        } finally {
            m8763(null);
        }
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void m8761(Throwable th) {
        th.getClass();
        if (this.f14942 && !m8217(th)) {
            Set set = this.f1619;
            if (set == null) {
                Set setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap());
                setNewSetFromMap.getClass();
                if (!(this.f13450 instanceof C3361)) {
                    Throwable thM8213 = m8213();
                    Objects.requireNonNull(thM8213);
                    while (thM8213 != null && setNewSetFromMap.add(thM8213)) {
                        thM8213 = thM8213.getCause();
                    }
                }
                AbstractC0182.f1616.ˏˋٴ(this, setNewSetFromMap);
                set = this.f1619;
                Objects.requireNonNull(set);
            }
            for (Throwable cause = th; cause != null; cause = cause.getCause()) {
                if (set.add(cause)) {
                }
            }
            f14939.m10552().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;
        }
        if (th instanceof Error) {
            f14939.m10552().log(Level.SEVERE, "Input Future failed with Error", th);
        }
    }

    /* renamed from: ᵨᵳʝ, reason: contains not printable characters */
    public final void m8762() {
        Objects.requireNonNull(this.f14941);
        if (this.f14941.isEmpty()) {
            C3643 c3643 = this.f14940;
            if (c3643 != null) {
                try {
                    c3643.f13545.execute(c3643);
                    return;
                } catch (RejectedExecutionException e) {
                    c3643.f13544.m8217(e);
                    return;
                }
            }
            return;
        }
        boolean z = this.f14942;
        EnumC2524 enumC2524 = EnumC2524.f9848;
        if (!z) {
            RunnableC0421 runnableC0421 = new RunnableC0421(this, 1, (Object) null);
            AbstractC5447 it = this.f14941.iterator();
            while (it.hasNext()) {
                ListenableFuture listenableFuture = (ListenableFuture) it.next();
                if (listenableFuture.isDone()) {
                    m8763(null);
                } else {
                    listenableFuture.mo833(runnableC0421, enumC2524);
                }
            }
            return;
        }
        AbstractC5447 it2 = this.f14941.iterator();
        int i = 0;
        while (it2.hasNext()) {
            ListenableFuture listenableFuture2 = (ListenableFuture) it2.next();
            int i2 = i + 1;
            if (listenableFuture2.isDone()) {
                m8760(listenableFuture2);
            } else {
                listenableFuture2.mo833(new RunnableC0421(this, i, listenableFuture2), enumC2524);
            }
            i = i2;
        }
    }

    @Override // defpackage.AbstractC3606
    /* renamed from: ᵶᵷᵕ */
    public final void mo8220() {
        C3643 c3643 = this.f14940;
        if (c3643 != null) {
            c3643.m9097();
        }
    }

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final void m8763(AbstractC3821 abstractC3821) {
        int i = AbstractC0182.f1616.ᵶᵷᵕ(this);
        ᵛᵾˏ.ᵢˇᵭ("Less than 0 remaining futures", i >= 0);
        if (i == 0) {
            if (abstractC3821 != null) {
                AbstractC5447 it = abstractC3821.iterator();
                while (it.hasNext()) {
                    Future future = (Future) it.next();
                    if (!future.isCancelled()) {
                        boolean z = false;
                        while (true) {
                            try {
                                future.get();
                                break;
                            } catch (InterruptedException unused) {
                                z = true;
                            } catch (Throwable th) {
                                if (z) {
                                    Thread.currentThread().interrupt();
                                }
                                throw th;
                            }
                        }
                        if (z) {
                            try {
                                Thread.currentThread().interrupt();
                            } catch (ExecutionException e) {
                                m8761(e.getCause());
                            } catch (Throwable th2) {
                                m8761(th2);
                            }
                        }
                    }
                }
            }
            this.f1619 = null;
            C3643 c3643 = this.f14940;
            if (c3643 != null) {
                try {
                    c3643.f13545.execute(c3643);
                } catch (RejectedExecutionException e2) {
                    c3643.f13544.m8217(e2);
                }
            }
            this.f14941 = null;
        }
    }

    @Override // defpackage.AbstractC3606
    /* renamed from: ᵸˑ */
    public final String mo1032() {
        AbstractC3821 abstractC3821 = this.f14941;
        if (abstractC3821 == null) {
            return super.mo1032();
        }
        return "futures=" + abstractC3821;
    }

    @Override // defpackage.AbstractC3606
    /* renamed from: ᵻᵢﹳᵰ */
    public final void mo1033() {
        AbstractC3821 abstractC3821 = this.f14941;
        this.f14941 = null;
        this.f14940 = null;
        if ((this.f13450 instanceof C3361) && (abstractC3821 != null)) {
            boolean zM8216 = m8216();
            AbstractC5447 it = abstractC3821.iterator();
            while (it.hasNext()) {
                ((Future) it.next()).cancel(zM8216);
            }
        }
    }
}
