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;

/* JADX INFO: renamed from: ˋᵣᵲˋ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1523 extends AbstractC0144 {

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public static final C4899 f6161 = new C4899(0, C1523.class);

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public C5132 f6162;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public final boolean f6163;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public AbstractC5055 f6164;

    public C1523(AbstractC5055 abstractC5055, boolean z) {
        int size = abstractC5055.size();
        this.f1514 = null;
        this.f1515 = size;
        this.f6164 = abstractC5055;
        this.f6163 = z;
    }

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public final void m4317(Throwable th) {
        th.getClass();
        if (this.f6163 && !m10927(th)) {
            Set set = this.f1514;
            if (set == null) {
                Set setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap());
                setNewSetFromMap.getClass();
                if (!(this.f20157 instanceof C4074)) {
                    Throwable thM10930 = m10930();
                    Objects.requireNonNull(thM10930);
                    while (thM10930 != null && setNewSetFromMap.add(thM10930)) {
                        thM10930 = thM10930.getCause();
                    }
                }
                AbstractC0144.f1513.mo6182(this, setNewSetFromMap);
                set = this.f1514;
                Objects.requireNonNull(set);
            }
            for (Throwable cause = th; cause != null; cause = cause.getCause()) {
                if (set.add(cause)) {
                }
            }
            f6161.m10179().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) {
            f6161.m10179().log(Level.SEVERE, "Input Future failed with Error", th);
        }
    }

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public final void m4318(AbstractC5055 abstractC5055) {
        int iMo6181 = AbstractC0144.f1513.mo6181(this);
        ᵻᵪ.ˊᵨᵧ("Less than 0 remaining futures", iMo6181 >= 0);
        if (iMo6181 == 0) {
            if (abstractC5055 != null) {
                AbstractC0228 it = abstractC5055.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) {
                                m4317(e.getCause());
                            } catch (Throwable th2) {
                                m4317(th2);
                            }
                        }
                    }
                }
            }
            this.f1514 = null;
            C5132 c5132 = this.f6162;
            if (c5132 != null) {
                try {
                    c5132.f19299.execute(c5132);
                } catch (RejectedExecutionException e2) {
                    c5132.f19300.m10927(e2);
                }
            }
            this.f6164 = null;
        }
    }

    /* JADX INFO: renamed from: ˊᵨᵧ, reason: contains not printable characters */
    public final void m4319(ListenableFuture listenableFuture) {
        try {
            boolean z = false;
            if (listenableFuture.isCancelled()) {
                this.f6164 = 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) {
                        m4317(e.getCause());
                    } catch (Throwable th2) {
                        m4317(th2);
                    }
                }
                if (z) {
                    Thread.currentThread().interrupt();
                }
            }
        } finally {
            m4318(null);
        }
    }

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public final void m4320() {
        Objects.requireNonNull(this.f6164);
        if (this.f6164.isEmpty()) {
            C5132 c5132 = this.f6162;
            if (c5132 != null) {
                try {
                    c5132.f19299.execute(c5132);
                    return;
                } catch (RejectedExecutionException e) {
                    c5132.f19300.m10927(e);
                    return;
                }
            }
            return;
        }
        boolean z = this.f6163;
        EnumC2921 enumC2921 = EnumC2921.f11255;
        if (!z) {
            RunnableC4076 runnableC4076 = new RunnableC4076(this, 1, (Object) null);
            AbstractC0228 it = this.f6164.iterator();
            while (it.hasNext()) {
                ListenableFuture listenableFuture = (ListenableFuture) it.next();
                if (listenableFuture.isDone()) {
                    m4318(null);
                } else {
                    listenableFuture.mo834(runnableC4076, enumC2921);
                }
            }
            return;
        }
        AbstractC0228 it2 = this.f6164.iterator();
        int i = 0;
        while (it2.hasNext()) {
            ListenableFuture listenableFuture2 = (ListenableFuture) it2.next();
            int i2 = i + 1;
            if (listenableFuture2.isDone()) {
                m4319(listenableFuture2);
            } else {
                listenableFuture2.mo834(new RunnableC4076(this, i, listenableFuture2), enumC2921);
            }
            i = i2;
        }
    }

    @Override // defpackage.AbstractC5343
    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void mo4321() {
        C5132 c5132 = this.f6162;
        if (c5132 != null) {
            c5132.m6483();
        }
    }

    @Override // defpackage.AbstractC5343
    /* JADX INFO: renamed from: ᵶᵥᵝ */
    public final String mo1685() {
        AbstractC5055 abstractC5055 = this.f6164;
        if (abstractC5055 == null) {
            return super.mo1685();
        }
        return "futures=" + abstractC5055;
    }

    @Override // defpackage.AbstractC5343
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final void mo1686() {
        AbstractC5055 abstractC5055 = this.f6164;
        this.f6164 = null;
        this.f6162 = null;
        if ((this.f20157 instanceof C4074) && (abstractC5055 != null)) {
            boolean zM10934 = m10934();
            AbstractC0228 it = abstractC5055.iterator();
            while (it.hasNext()) {
                ((Future) it.next()).cancel(zM10934);
            }
        }
    }
}
