package defpackage;

import com.google.common.util.concurrent.ListenableFuture;
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.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import java.util.logging.Level;
import java.util.logging.Logger;

/* JADX INFO: renamed from: ᵽˀᵥ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC5343 implements ListenableFuture {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public static final Object f20153;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public static final boolean f20154;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static final C4899 f20155;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public static final ᵣˉ f20156;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public volatile Object f20157;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public volatile C3110 f20158;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public volatile C0798 f20159;

    static {
        boolean z;
        Throwable th;
        ᵣˉ c1821;
        try {
            z = Boolean.parseBoolean(System.getProperty("guava.concurrent.generate_cancellation_cause", "false"));
        } catch (SecurityException unused) {
            z = false;
        }
        f20154 = z;
        f20155 = new C4899(0, AbstractC5343.class);
        Throwable th2 = null;
        try {
            c1821 = new C2332();
            th = null;
        } catch (Error | Exception e) {
            th = e;
            try {
                c1821 = new C5043(AtomicReferenceFieldUpdater.newUpdater(C3110.class, Thread.class, "ᵲᵶᵳˈ"), AtomicReferenceFieldUpdater.newUpdater(C3110.class, C3110.class, "ʽˈˋ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC5343.class, C3110.class, "ᵔᵖᵹᵫ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC5343.class, C0798.class, "ᵜᵪʾ"), AtomicReferenceFieldUpdater.newUpdater(AbstractC5343.class, Object.class, "ˌᴵ"));
            } catch (Error | Exception e2) {
                th2 = e2;
                c1821 = new C1821();
            }
        }
        f20156 = c1821;
        if (th2 != null) {
            C4899 c4899 = f20155;
            Logger loggerM10179 = c4899.m10179();
            Level level = Level.SEVERE;
            loggerM10179.log(level, "UnsafeAtomicHelper is broken!", th);
            c4899.m10179().log(level, "SafeAtomicHelper is broken!", th2);
        }
        f20153 = new Object();
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static Object m10923(Object obj) throws ExecutionException {
        if (obj instanceof C4074) {
            Throwable th = ((C4074) obj).f15654;
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(th);
            throw cancellationException;
        }
        if (obj instanceof C2578) {
            throw new ExecutionException(((C2578) obj).f9970);
        }
        if (obj == f20153) {
            return null;
        }
        return obj;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static void m10924(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (Exception e) {
            f20155.m10179().log(Level.SEVERE, "RuntimeException while executing runnable " + runnable + " with executor " + executor, (Throwable) e);
        }
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public static Object m10925(ListenableFuture listenableFuture) {
        Object obj;
        Throwable thM10930;
        if (listenableFuture instanceof InterfaceC4285) {
            Object c4074 = ((AbstractC5343) listenableFuture).f20157;
            if (c4074 instanceof C4074) {
                C4074 c40742 = (C4074) c4074;
                if (c40742.f15655) {
                    c4074 = c40742.f15654 != null ? new C4074(c40742.f15654, false) : C4074.f15653;
                }
            }
            Objects.requireNonNull(c4074);
            return c4074;
        }
        if ((listenableFuture instanceof AbstractC5343) && (thM10930 = ((AbstractC5343) listenableFuture).m10930()) != null) {
            return new C2578(thM10930);
        }
        boolean zIsCancelled = listenableFuture.isCancelled();
        boolean z = true;
        if ((!f20154) && zIsCancelled) {
            C4074 c40743 = C4074.f15653;
            Objects.requireNonNull(c40743);
            return c40743;
        }
        boolean z2 = false;
        while (true) {
            try {
                try {
                    try {
                        obj = listenableFuture.get();
                        break;
                    } catch (Error e) {
                        e = e;
                        return new C2578(e);
                    }
                } catch (InterruptedException unused) {
                    z2 = z;
                } catch (Throwable th) {
                    if (z2) {
                        Thread.currentThread().interrupt();
                    }
                    throw th;
                }
            } catch (Error | Exception e2) {
                e = e2;
                return new C2578(e);
            } catch (CancellationException e3) {
                if (zIsCancelled) {
                    return new C4074(e3, false);
                }
                return new C2578(new IllegalArgumentException("get() threw CancellationException, despite reporting isCancelled() == false: " + listenableFuture, e3));
            } catch (ExecutionException e4) {
                if (!zIsCancelled) {
                    return new C2578(e4.getCause());
                }
                return new C4074(new IllegalArgumentException("get() did not throw CancellationException, despite reporting isCancelled() == true: " + listenableFuture, e4), false);
            }
        }
        if (z2) {
            Thread.currentThread().interrupt();
        }
        if (!zIsCancelled) {
            return obj == null ? f20153 : obj;
        }
        return new C4074(new IllegalArgumentException("get() did not throw CancellationException, despite reporting isCancelled() == true: " + listenableFuture), false);
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static void m10926(AbstractC5343 abstractC5343, boolean z) {
        C0798 c0798 = null;
        while (true) {
            for (C3110 c3110 = f20156.ᵱʡˏ(abstractC5343); c3110 != null; c3110 = c3110.f11890) {
                Thread thread = c3110.f11891;
                if (thread != null) {
                    c3110.f11891 = null;
                    LockSupport.unpark(thread);
                }
            }
            if (z) {
                abstractC5343.mo4321();
                z = false;
            }
            abstractC5343.mo1686();
            C0798 c07982 = c0798;
            C0798 c07983 = f20156.ᵟᵹᵙ(abstractC5343);
            C0798 c07984 = c07982;
            while (c07983 != null) {
                C0798 c07985 = c07983.f3578;
                c07983.f3578 = c07984;
                c07984 = c07983;
                c07983 = c07985;
            }
            while (c07984 != null) {
                c0798 = c07984.f3578;
                Runnable runnable = c07984.f3579;
                Objects.requireNonNull(runnable);
                if (runnable instanceof RunnableC4237) {
                    RunnableC4237 runnableC4237 = (RunnableC4237) runnable;
                    abstractC5343 = runnableC4237.f16157;
                    if (abstractC5343.f20157 == runnableC4237) {
                        if (f20156.ˊᵫᵗ(abstractC5343, runnableC4237, m10925(runnableC4237.f16158))) {
                            break;
                        }
                    } else {
                        continue;
                    }
                } else {
                    Executor executor = c07984.f3577;
                    Objects.requireNonNull(executor);
                    m10924(runnable, executor);
                }
                c07984 = c0798;
            }
            return;
        }
    }

    @Override // java.util.concurrent.Future
    public boolean cancel(boolean z) {
        C4074 c4074;
        Object obj = this.f20157;
        if (!(obj == null) && !(obj instanceof RunnableC4237)) {
            return false;
        }
        if (f20154) {
            c4074 = new C4074(new CancellationException("Future.cancel() was called."), z);
        } else {
            c4074 = z ? C4074.f15652 : C4074.f15653;
            Objects.requireNonNull(c4074);
        }
        boolean z2 = false;
        while (true) {
            if (f20156.ˊᵫᵗ(this, obj, c4074)) {
                m10926(this, z);
                if (!(obj instanceof RunnableC4237)) {
                    break;
                }
                ListenableFuture listenableFuture = ((RunnableC4237) obj).f16158;
                if (!(listenableFuture instanceof InterfaceC4285)) {
                    listenableFuture.cancel(z);
                    break;
                }
                this = (AbstractC5343) listenableFuture;
                obj = this.f20157;
                if (!(obj == null) && !(obj instanceof RunnableC4237)) {
                    break;
                }
                z2 = true;
            } else {
                obj = this.f20157;
                if (!(obj instanceof RunnableC4237)) {
                    return z2;
                }
            }
        }
        return true;
    }

    @Override // java.util.concurrent.Future
    public Object get() throws InterruptedException {
        Object obj;
        C3110 c3110 = C3110.f11889;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj2 = this.f20157;
        if ((obj2 != null) && (!(obj2 instanceof RunnableC4237))) {
            return m10923(obj2);
        }
        C3110 c31102 = this.f20158;
        if (c31102 != c3110) {
            C3110 c31103 = new C3110();
            do {
                ᵣˉ r5 = f20156;
                r5.ᵸˆˁ(c31103, c31102);
                if (r5.ᵻʽᵯ(this, c31102, c31103)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m10933(c31103);
                            throw new InterruptedException();
                        }
                        obj = this.f20157;
                    } while (!((obj != null) & (!(obj instanceof RunnableC4237))));
                    return m10923(obj);
                }
                c31102 = this.f20158;
            } while (c31102 != c3110);
        }
        Object obj3 = this.f20157;
        Objects.requireNonNull(obj3);
        return m10923(obj3);
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x00ac  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x00d3  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:60:0x00c6 -> B:37:0x0083). Please report as a decompilation issue!!! */
    @Override // java.util.concurrent.Future
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object get(long j, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        boolean z;
        long j2;
        long jNanoTime;
        C3110 c3110 = C3110.f11889;
        long nanos = timeUnit.toNanos(j);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj = this.f20157;
        if ((obj != null) && (!(obj instanceof RunnableC4237))) {
            return m10923(obj);
        }
        long j3 = 0;
        long jNanoTime2 = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C3110 c31102 = this.f20158;
            if (c31102 != c3110) {
                C3110 c31103 = new C3110();
                z = true;
                while (true) {
                    ᵣˉ r9 = f20156;
                    r9.ᵸˆˁ(c31103, c31102);
                    if (r9.ᵻʽᵯ(this, c31102, c31103)) {
                        j2 = j3;
                        while (true) {
                            LockSupport.parkNanos(this, Math.min(nanos, 2147483647999999999L));
                            if (Thread.interrupted()) {
                                m10933(c31103);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f20157;
                            if ((obj2 != null) && (!(obj2 instanceof RunnableC4237))) {
                                return m10923(obj2);
                            }
                            jNanoTime = jNanoTime2 - System.nanoTime();
                            if (jNanoTime < 1000) {
                                m10933(c31103);
                                break;
                            }
                            nanos = jNanoTime;
                        }
                    } else {
                        long j4 = j3;
                        c31102 = this.f20158;
                        if (c31102 == c3110) {
                            break;
                        }
                        j3 = j4;
                    }
                }
            }
            Object obj3 = this.f20157;
            Objects.requireNonNull(obj3);
            return m10923(obj3);
        }
        z = true;
        j2 = 0;
        if (nanos <= j2) {
            String string = toString();
            String string2 = timeUnit.toString();
            Locale locale = Locale.ROOT;
            String lowerCase = string2.toLowerCase(locale);
            StringBuilder sbM8220 = AbstractC3653.m8220(j, "Waited ", " ");
            sbM8220.append(timeUnit.toString().toLowerCase(locale));
            String string3 = sbM8220.toString();
            if (nanos + 1000 < j2) {
                String strConcat = string3.concat(" (plus ");
                long j5 = -nanos;
                long jConvert = timeUnit.convert(j5, TimeUnit.NANOSECONDS);
                long nanos2 = j5 - timeUnit.toNanos(jConvert);
                boolean z2 = (jConvert == j2 || nanos2 > 1000) ? z : false;
                if (jConvert > j2) {
                    String strConcat2 = strConcat + jConvert + " " + lowerCase;
                    if (z2) {
                        strConcat2 = strConcat2.concat(",");
                    }
                    strConcat = strConcat2.concat(" ");
                }
                if (z2) {
                    strConcat = strConcat + nanos2 + " nanoseconds ";
                }
                string3 = strConcat.concat("delay)");
            }
            if (isDone()) {
                throw new TimeoutException(string3.concat(" but future completed as timeout expired"));
            }
            throw new TimeoutException(AbstractC3653.m8223(string3, " for ", string));
        }
        Object obj4 = this.f20157;
        if ((obj4 != null ? z : false) && (!(obj4 instanceof RunnableC4237))) {
            return m10923(obj4);
        }
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        jNanoTime = jNanoTime2 - System.nanoTime();
        nanos = jNanoTime;
        if (nanos <= j2) {
        }
    }

    @Override // java.util.concurrent.Future
    public boolean isCancelled() {
        return this.f20157 instanceof C4074;
    }

    @Override // java.util.concurrent.Future
    public boolean isDone() {
        return (!(r2 instanceof RunnableC4237)) & (this.f20157 != null);
    }

    public String toString() {
        String strMo1685;
        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 (isCancelled()) {
            sb.append("CANCELLED");
        } else if (isDone()) {
            m10928(sb);
        } else {
            int length = sb.length();
            sb.append("PENDING");
            Object obj = this.f20157;
            if (obj instanceof RunnableC4237) {
                sb.append(", setFuture=[");
                ListenableFuture listenableFuture = ((RunnableC4237) obj).f16158;
                try {
                    if (listenableFuture == this) {
                        sb.append("this future");
                    } else {
                        sb.append(listenableFuture);
                    }
                } catch (Exception e) {
                    e = e;
                    sb.append("Exception thrown from implementation: ");
                    sb.append(e.getClass());
                } catch (StackOverflowError e2) {
                    e = e2;
                    sb.append("Exception thrown from implementation: ");
                    sb.append(e.getClass());
                }
                sb.append("]");
            } else {
                try {
                    strMo1685 = mo1685();
                    if (ˀᵳˎᵹ.ᵨᵼⁱ(strMo1685)) {
                        strMo1685 = null;
                    }
                } catch (Exception | StackOverflowError e3) {
                    strMo1685 = "Exception thrown from implementation: " + e3.getClass();
                }
                if (strMo1685 != null) {
                    sb.append(", info=[");
                    sb.append(strMo1685);
                    sb.append("]");
                }
            }
            if (isDone()) {
                sb.delete(length, sb.length());
                m10928(sb);
            }
        }
        sb.append("]");
        return sb.toString();
    }

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public boolean m10927(Throwable th) {
        th.getClass();
        if (!f20156.ˊᵫᵗ(this, (Object) null, new C2578(th))) {
            return false;
        }
        m10926(this, false);
        return true;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m10928(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=[");
        m10931(sb, obj);
        sb.append("]");
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public boolean m10929(Object obj) {
        if (obj == null) {
            obj = f20153;
        }
        if (!f20156.ˊᵫᵗ(this, (Object) null, obj)) {
            return false;
        }
        m10926(this, false);
        return true;
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final Throwable m10930() {
        if (!(this instanceof InterfaceC4285)) {
            return null;
        }
        Object obj = this.f20157;
        if (obj instanceof C2578) {
            return ((C2578) obj).f9970;
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final void m10931(StringBuilder sb, Object obj) {
        if (obj == null) {
            sb.append("null");
        } else {
            if (obj == this) {
                sb.append("this future");
                return;
            }
            sb.append(obj.getClass().getName());
            sb.append("@");
            sb.append(Integer.toHexString(System.identityHashCode(obj)));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x0048  */
    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean m10932(ListenableFuture listenableFuture) {
        C2578 c2578;
        listenableFuture.getClass();
        Object obj = this.f20157;
        if (obj != null) {
            if (obj instanceof C4074) {
                listenableFuture.cancel(((C4074) obj).f15655);
            }
        } else if (listenableFuture.isDone()) {
            if (f20156.ˊᵫᵗ(this, (Object) null, m10925(listenableFuture))) {
                m10926(this, false);
                return true;
            }
        } else {
            RunnableC4237 runnableC4237 = new RunnableC4237(this, listenableFuture);
            if (f20156.ˊᵫᵗ(this, (Object) null, runnableC4237)) {
                try {
                    listenableFuture.mo834(runnableC4237, EnumC2921.f11255);
                    return true;
                } catch (Throwable th) {
                    try {
                        c2578 = new C2578(th);
                    } catch (Error | Exception unused) {
                        c2578 = C2578.f9969;
                    }
                    f20156.ˊᵫᵗ(this, runnableC4237, c2578);
                    return true;
                }
            }
            obj = this.f20157;
            if (obj instanceof C4074) {
            }
        }
        return false;
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final void m10933(C3110 c3110) {
        c3110.f11891 = null;
        while (true) {
            C3110 c31102 = this.f20158;
            if (c31102 == C3110.f11889) {
                return;
            }
            C3110 c31103 = null;
            while (c31102 != null) {
                C3110 c31104 = c31102.f11890;
                if (c31102.f11891 != null) {
                    c31103 = c31102;
                } else if (c31103 != null) {
                    c31103.f11890 = c31104;
                    if (c31103.f11891 == null) {
                        break;
                    }
                } else if (!f20156.ᵻʽᵯ(this, c31102, c31104)) {
                    break;
                }
                c31102 = c31104;
            }
            return;
        }
    }

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public final boolean m10934() {
        Object obj = this.f20157;
        return (obj instanceof C4074) && ((C4074) obj).f15655;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public void mo4321() {
    }

    @Override // com.google.common.util.concurrent.ListenableFuture
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public void mo834(Runnable runnable, Executor executor) {
        C0798 c0798;
        C0798 c07982 = C0798.f3576;
        ᵻᵪ.ᵱʡˏ(executor, "Executor was null.");
        if (!isDone() && (c0798 = this.f20159) != c07982) {
            C0798 c07983 = new C0798(runnable, executor);
            do {
                c07983.f3578 = c0798;
                if (f20156.ᵵᵽ(this, c0798, c07983)) {
                    return;
                } else {
                    c0798 = this.f20159;
                }
            } while (c0798 != c07982);
        }
        m10924(runnable, executor);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: ᵶᵥᵝ */
    public String mo1685() {
        if (!(this instanceof ScheduledFuture)) {
            return null;
        }
        return "remaining delay=[" + ((ScheduledFuture) this).getDelay(TimeUnit.MILLISECONDS) + " ms]";
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public void mo1686() {
    }
}
