package defpackage;

import j$.util.Objects;
import java.util.Locale;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.LockSupport;
import java.util.logging.Level;

/* JADX INFO: renamed from: ᵘᵾᵠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2609 extends AbstractC2315 implements InterfaceFutureC1876 {

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public InterfaceFutureC1876 f10120;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public ScheduledFuture f10121;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static Object m6326(InterfaceFutureC1876 interfaceFutureC1876) {
        Object obj;
        Throwable thMo5958;
        if (interfaceFutureC1876 instanceof C2609) {
            Object c5202 = ((C2609) interfaceFutureC1876).f9106;
            if (c5202 instanceof C5202) {
                C5202 c52022 = (C5202) c5202;
                if (c52022.f19607) {
                    Throwable th = c52022.f19606;
                    c5202 = th != null ? new C5202(th, false) : C5202.f19605;
                }
            }
            Objects.requireNonNull(c5202);
            return c5202;
        }
        if ((interfaceFutureC1876 instanceof AbstractC2315) && (thMo5958 = ((AbstractC2315) interfaceFutureC1876).mo5958()) != null) {
            return new C0267(thMo5958);
        }
        boolean zIsCancelled = interfaceFutureC1876.isCancelled();
        boolean z = true;
        if ((!AbstractC2315.f9105) && zIsCancelled) {
            C5202 c52023 = C5202.f19605;
            Objects.requireNonNull(c52023);
            return c52023;
        }
        boolean z2 = false;
        while (true) {
            try {
                try {
                    try {
                        obj = interfaceFutureC1876.get();
                        break;
                    } catch (Error e) {
                        e = e;
                        return new C0267(e);
                    }
                } catch (InterruptedException unused) {
                    z2 = z;
                } catch (Throwable th2) {
                    if (z2) {
                        Thread.currentThread().interrupt();
                    }
                    throw th2;
                }
            } catch (Error | Exception e2) {
                e = e2;
                return new C0267(e);
            } catch (CancellationException e3) {
                return !zIsCancelled ? new C0267(new IllegalArgumentException("get() threw CancellationException, despite reporting isCancelled() == false: ".concat(String.valueOf(interfaceFutureC1876)), e3)) : new C5202(e3, false);
            } catch (ExecutionException e4) {
                return zIsCancelled ? new C5202(new IllegalArgumentException("get() did not throw CancellationException, despite reporting isCancelled() == true: ".concat(String.valueOf(interfaceFutureC1876)), e4), false) : new C0267(e4.getCause());
            }
        }
        if (z2) {
            Thread.currentThread().interrupt();
        }
        return zIsCancelled ? new C5202(new IllegalArgumentException("get() did not throw CancellationException, despite reporting isCancelled() == true: ".concat(String.valueOf(interfaceFutureC1876))), false) : obj == null ? AbstractC2315.f9103 : obj;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static Object m6327(Object obj) throws ExecutionException {
        if (obj instanceof C5202) {
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(((C5202) obj).f19606);
            throw cancellationException;
        }
        if (obj instanceof C0267) {
            throw new ExecutionException(((C0267) obj).f1882);
        }
        if (obj == AbstractC2315.f9103) {
            return null;
        }
        return obj;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public static void m6328(C2609 c2609) {
        C1684 c1684;
        C1684 c16842 = null;
        while (true) {
            c2609.getClass();
            for (C5207 c5207 = AbstractC2315.f9102.ᵜᵤ(c2609); c5207 != null; c5207 = c5207.f19621) {
                Thread thread = c5207.f19622;
                if (thread != null) {
                    c5207.f19622 = null;
                    LockSupport.unpark(thread);
                }
            }
            InterfaceFutureC1876 interfaceFutureC1876 = c2609.f10120;
            if ((c2609.f9106 instanceof C5202) & (interfaceFutureC1876 != null)) {
                Object obj = c2609.f9106;
                interfaceFutureC1876.cancel((obj instanceof C5202) && ((C5202) obj).f19607);
            }
            ScheduledFuture scheduledFuture = c2609.f10121;
            if (scheduledFuture != null) {
                scheduledFuture.cancel(false);
            }
            c2609.f10120 = null;
            c2609.f10121 = null;
            C1684 c16843 = c16842;
            C1684 c16844 = AbstractC2315.f9102.ˋᵯᵩ(c2609);
            C1684 c16845 = c16843;
            while (c16844 != null) {
                C1684 c16846 = c16844.f6643;
                c16844.f6643 = c16845;
                c16845 = c16844;
                c16844 = c16846;
            }
            while (c16845 != null) {
                Runnable runnable = c16845.f6644;
                c1684 = c16845.f6643;
                Objects.requireNonNull(runnable);
                if (runnable instanceof RunnableC4664) {
                    RunnableC4664 runnableC4664 = (RunnableC4664) runnable;
                    c2609 = runnableC4664.f17711;
                    if (c2609.f9106 == runnableC4664) {
                        if (AbstractC2315.f9102.ᵵᵸᵕᵸ(c2609, runnableC4664, m6326(runnableC4664.f17712))) {
                            break;
                        }
                    } else {
                        continue;
                    }
                } else {
                    Executor executor = c16845.f6642;
                    Objects.requireNonNull(executor);
                    m6330(runnable, executor);
                }
                c16845 = c1684;
            }
            return;
            c16842 = c1684;
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static boolean m6329(Object obj) {
        return !(obj instanceof RunnableC4664);
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public static void m6330(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (Exception e) {
            AbstractC2315.f9104.m10178().logp(Level.SEVERE, "com.google.common.util.concurrent.AbstractFuture", "executeListener", AbstractC0793.m2874("RuntimeException while executing runnable ", String.valueOf(runnable), " with executor ", String.valueOf(executor)), (Throwable) e);
        }
    }

    @Override // java.util.concurrent.Future
    public final boolean cancel(boolean z) {
        C5202 c5202;
        Object obj = this.f9106;
        if (!(obj instanceof RunnableC4664) && !(obj == null)) {
            return false;
        }
        if (AbstractC2315.f9105) {
            c5202 = new C5202(new CancellationException("Future.cancel() was called."), z);
        } else {
            c5202 = z ? C5202.f19604 : C5202.f19605;
            Objects.requireNonNull(c5202);
        }
        boolean z2 = false;
        while (true) {
            if (AbstractC2315.f9102.ᵵᵸᵕᵸ(this, obj, c5202)) {
                m6328(this);
                if (!(obj instanceof RunnableC4664)) {
                    break;
                }
                InterfaceFutureC1876 interfaceFutureC1876 = ((RunnableC4664) obj).f17712;
                if (!(interfaceFutureC1876 instanceof C2609)) {
                    interfaceFutureC1876.cancel(z);
                    break;
                }
                this = (C2609) interfaceFutureC1876;
                obj = this.f9106;
                if (!(obj == null) && !(obj instanceof RunnableC4664)) {
                    break;
                }
                z2 = true;
            } else {
                obj = this.f9106;
                if (m6329(obj)) {
                    return z2;
                }
            }
        }
        return true;
    }

    @Override // java.util.concurrent.Future
    public final Object get() throws InterruptedException {
        Object obj;
        C5207 c5207 = C5207.f19620;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj2 = this.f9106;
        if ((obj2 != null) && m6329(obj2)) {
            return m6327(obj2);
        }
        C5207 c52072 = this.f9107;
        if (c52072 != c5207) {
            C5207 c52073 = new C5207();
            do {
                ᵥˈᵛ r5 = AbstractC2315.f9102;
                r5.ːᵝٴᵶ(c52073, c52072);
                if (r5.ᵬᵦˋ(this, c52072, c52073)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m5957(c52073);
                            throw new InterruptedException();
                        }
                        obj = this.f9106;
                    } while (!((obj != null) & m6329(obj)));
                    return m6327(obj);
                }
                c52072 = this.f9107;
            } while (c52072 != c5207);
        }
        Object obj3 = this.f9106;
        Objects.requireNonNull(obj3);
        return m6327(obj3);
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00a7  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x00cd  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:60:0x00c0 -> B:37:0x0080). Please report as a decompilation issue!!! */
    @Override // java.util.concurrent.Future
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object get(long j, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        long j2;
        long jNanoTime;
        C5207 c5207 = C5207.f19620;
        long nanos = timeUnit.toNanos(j);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj = this.f9106;
        if ((obj != null) && m6329(obj)) {
            return m6327(obj);
        }
        long j3 = 0;
        long jNanoTime2 = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C5207 c52072 = this.f9107;
            if (c52072 != c5207) {
                C5207 c52073 = new C5207();
                while (true) {
                    ᵥˈᵛ r9 = AbstractC2315.f9102;
                    r9.ːᵝٴᵶ(c52073, c52072);
                    if (r9.ᵬᵦˋ(this, c52072, c52073)) {
                        j2 = j3;
                        while (true) {
                            LockSupport.parkNanos(this, Math.min(nanos, 2147483647999999999L));
                            if (Thread.interrupted()) {
                                m5957(c52073);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f9106;
                            if ((obj2 != null) && m6329(obj2)) {
                                return m6327(obj2);
                            }
                            jNanoTime = jNanoTime2 - System.nanoTime();
                            if (jNanoTime < 1000) {
                                m5957(c52073);
                                break;
                            }
                            nanos = jNanoTime;
                        }
                    } else {
                        long j4 = j3;
                        c52072 = this.f9107;
                        if (c52072 == c5207) {
                            break;
                        }
                        j3 = j4;
                    }
                }
            }
            Object obj3 = this.f9106;
            Objects.requireNonNull(obj3);
            return m6327(obj3);
        }
        j2 = 0;
        if (nanos <= j2) {
            String string = toString();
            String string2 = timeUnit.toString();
            Locale locale = Locale.ROOT;
            String lowerCase = string2.toLowerCase(locale);
            String strConcat = "Waited " + j + " " + timeUnit.toString().toLowerCase(locale);
            if (nanos + 1000 < j2) {
                String strConcat2 = strConcat.concat(" (plus ");
                long j5 = -nanos;
                long jConvert = timeUnit.convert(j5, TimeUnit.NANOSECONDS);
                long nanos2 = j5 - timeUnit.toNanos(jConvert);
                boolean z = jConvert == j2 || nanos2 > 1000;
                if (jConvert > j2) {
                    String strConcat3 = strConcat2 + jConvert + " " + lowerCase;
                    if (z) {
                        strConcat3 = strConcat3.concat(",");
                    }
                    strConcat2 = strConcat3.concat(" ");
                }
                if (z) {
                    strConcat2 = strConcat2 + nanos2 + " nanoseconds ";
                }
                strConcat = strConcat2.concat("delay)");
            }
            if (isDone()) {
                throw new TimeoutException(strConcat.concat(" but future completed as timeout expired"));
            }
            throw new TimeoutException(AbstractC3653.m8223(strConcat, " for ", string));
        }
        Object obj4 = this.f9106;
        if ((obj4 != null) && m6329(obj4)) {
            return m6327(obj4);
        }
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        jNanoTime = jNanoTime2 - System.nanoTime();
        nanos = jNanoTime;
        if (nanos <= j2) {
        }
    }

    @Override // java.util.concurrent.Future
    public final boolean isCancelled() {
        return this.f9106 instanceof C5202;
    }

    @Override // java.util.concurrent.Future
    public final boolean isDone() {
        Object obj = this.f9106;
        return (obj != null) & m6329(obj);
    }

    /* JADX WARN: Removed duplicated region for block: B:38:0x00ae  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String toString() {
        String strConcat;
        StringBuilder sb = new StringBuilder();
        if (getClass().getName().startsWith("com.google.common.util.concurrent.")) {
            sb.append(getClass().getSimpleName());
        } else {
            sb.append(getClass().getName());
        }
        sb.append('@');
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        sb.append("[status=");
        if (this.f9106 instanceof C5202) {
            sb.append("CANCELLED");
        } else if (isDone()) {
            m6331(sb);
        } else {
            int length = sb.length();
            sb.append("PENDING");
            Object obj = this.f9106;
            if (obj instanceof RunnableC4664) {
                sb.append(", setFuture=[");
                InterfaceFutureC1876 interfaceFutureC1876 = ((RunnableC4664) obj).f17712;
                try {
                    if (interfaceFutureC1876 == this) {
                        sb.append("this future");
                    } else {
                        sb.append(interfaceFutureC1876);
                    }
                } catch (Throwable th) {
                    if ((th instanceof Error) && !(th instanceof StackOverflowError)) {
                        throw th;
                    }
                    sb.append("Exception thrown from implementation: ");
                    sb.append(th.getClass());
                }
                sb.append("]");
            } else {
                try {
                    strConcat = m6332();
                } catch (Throwable th2) {
                    if ((th2 instanceof Error) && !(th2 instanceof StackOverflowError)) {
                        throw th2;
                    }
                    strConcat = "Exception thrown from implementation: ".concat(String.valueOf(th2.getClass()));
                }
                if (strConcat != null) {
                    boolean z = strConcat.isEmpty();
                    if (z) {
                        strConcat = null;
                    }
                    if (strConcat != null) {
                        sb.append(", info=[");
                        sb.append(strConcat);
                        sb.append("]");
                    }
                }
            }
            if (isDone()) {
                sb.delete(length, sb.length());
                m6331(sb);
            }
        }
        sb.append("]");
        return sb.toString();
    }

    @Override // defpackage.InterfaceFutureC1876
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo3844(Runnable runnable, Executor executor) {
        C1684 c1684;
        C1684 c16842 = C1684.f6641;
        if (executor == null) {
            C4935.m10233("Executor was null.");
            return;
        }
        if (!isDone() && (c1684 = this.f9108) != c16842) {
            C1684 c16843 = new C1684(runnable, executor);
            do {
                c16843.f6643 = c1684;
                if (AbstractC2315.f9102.ᵫˈᵹ(this, c1684, c16843)) {
                    return;
                } else {
                    c1684 = this.f9108;
                }
            } while (c1684 != c16842);
        }
        m6330(runnable, executor);
    }

    @Override // defpackage.AbstractC2315
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final Throwable mo5958() {
        if (!(this instanceof C2609)) {
            return null;
        }
        Object obj = this.f9106;
        if (obj instanceof C0267) {
            return ((C0267) obj).f1882;
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final void m6331(StringBuilder sb) {
        Object obj;
        boolean z = false;
        while (true) {
            try {
                try {
                    obj = get();
                    break;
                } catch (InterruptedException unused) {
                    z = true;
                } catch (Throwable th) {
                    if (z) {
                        Thread.currentThread().interrupt();
                    }
                    throw th;
                }
            } catch (CancellationException unused2) {
                sb.append("CANCELLED");
                return;
            } catch (ExecutionException e) {
                sb.append("FAILURE, cause=[");
                sb.append(e.getCause());
                sb.append("]");
                return;
            } catch (Exception e2) {
                sb.append("UNKNOWN, cause=[");
                sb.append(e2.getClass());
                sb.append(" thrown from get()]");
                return;
            }
        }
        if (z) {
            Thread.currentThread().interrupt();
        }
        sb.append("SUCCESS, result=[");
        if (obj == null) {
            sb.append("null");
        } else if (obj == this) {
            sb.append("this future");
        } else {
            sb.append(obj.getClass().getName());
            sb.append("@");
            sb.append(Integer.toHexString(System.identityHashCode(obj)));
        }
        sb.append("]");
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final String m6332() {
        InterfaceFutureC1876 interfaceFutureC1876 = this.f10120;
        ScheduledFuture scheduledFuture = this.f10121;
        if (interfaceFutureC1876 == null) {
            return null;
        }
        String strM8117 = AbstractC3589.m8117("inputFuture=[", interfaceFutureC1876.toString(), "]");
        if (scheduledFuture != null) {
            long delay = scheduledFuture.getDelay(TimeUnit.MILLISECONDS);
            if (delay > 0) {
                return strM8117 + ", remaining delay=[" + delay + " ms]";
            }
        }
        return strM8117;
    }
}
