package defpackage;

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;

/* renamed from: ᵼᵶˌ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public class C5305 implements InterfaceFutureC2302 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public static final Object f19852;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final ᵲᵝᵪ f19853;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public volatile C5340 f19856;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public volatile Object f19857;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public volatile C2046 f19858;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public static final boolean f19855 = Boolean.parseBoolean(System.getProperty("guava.concurrent.generate_cancellation_cause", "false"));

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public static final Logger f19854 = Logger.getLogger(C5305.class.getName());

    static {
        ᵲᵝᵪ c5574;
        try {
            c5574 = new C2603(AtomicReferenceFieldUpdater.newUpdater(C2046.class, Thread.class, "ᵥᵯˎ"), AtomicReferenceFieldUpdater.newUpdater(C2046.class, C2046.class, "ᵴᵳ"), AtomicReferenceFieldUpdater.newUpdater(C5305.class, C2046.class, "ᵿʗᵝʽ"), AtomicReferenceFieldUpdater.newUpdater(C5305.class, C5340.class, "ᵢˇᵭ"), AtomicReferenceFieldUpdater.newUpdater(C5305.class, Object.class, "ᵧᵾˀˈ"));
            th = null;
        } catch (Throwable th) {
            th = th;
            c5574 = new C5574();
        }
        Throwable th2 = th;
        f19853 = c5574;
        if (th2 != null) {
            f19854.logp(Level.SEVERE, "com.android.billingclient.util.concurrent.AbstractResolvableFuture", "<clinit>", "SafeAtomicHelper is broken!", th2);
        }
        f19852 = new Object();
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public static void m10957(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (RuntimeException e) {
            f19854.logp(Level.SEVERE, "com.android.billingclient.util.concurrent.AbstractResolvableFuture", "executeListener", AbstractC3915.m8580("RuntimeException while executing runnable ", String.valueOf(runnable), " with executor ", String.valueOf(executor)), (Throwable) e);
        }
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public static final Object m10958(Object obj) throws ExecutionException {
        if (obj instanceof C1712) {
            Throwable th = ((C1712) obj).f6823;
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(th);
            throw cancellationException;
        }
        if (obj instanceof C2682) {
            throw new ExecutionException(((C2682) obj).f10409);
        }
        if (obj == f19852) {
            return null;
        }
        return obj;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public static void m10959(C5305 c5305) {
        C2046 c2046;
        ᵲᵝᵪ r1;
        C5340 c5340;
        C5340 c53402;
        C5340 c53403;
        do {
            c2046 = c5305.f19858;
            r1 = f19853;
        } while (!r1.ᵯᵽ(c5305, c2046, C2046.f8194));
        while (true) {
            c5340 = null;
            if (c2046 == null) {
                break;
            }
            Thread thread = c2046.f8195;
            if (thread != null) {
                c2046.f8195 = null;
                LockSupport.unpark(thread);
            }
            c2046 = c2046.f8196;
        }
        do {
            c53402 = c5305.f19856;
        } while (!r1.ˆʕ(c5305, c53402, C5340.f19996));
        while (true) {
            c53403 = c5340;
            c5340 = c53402;
            if (c5340 == null) {
                break;
            }
            c53402 = c5340.f19997;
            c5340.f19997 = c53403;
        }
        while (c53403 != null) {
            Runnable runnable = c53403.f19998;
            C5340 c53404 = c53403.f19997;
            m10957(runnable, c53403.f19999);
            c53403 = c53404;
        }
    }

    @Override // java.util.concurrent.Future
    public final boolean cancel(boolean z) {
        Object obj = this.f19857;
        if (obj != null) {
            return false;
        }
        if (!f19853.ˎᵶᵹ(this, obj, f19855 ? new C1712(new CancellationException("Future.cancel() was called.")) : z ? C1712.f6822 : C1712.f6821)) {
            return false;
        }
        m10959(this);
        return true;
    }

    @Override // java.util.concurrent.Future
    public final Object get() throws InterruptedException {
        Object obj;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj2 = this.f19857;
        if (obj2 != null) {
            return m10958(obj2);
        }
        C2046 c2046 = this.f19858;
        C2046 c20462 = C2046.f8194;
        if (c2046 != c20462) {
            C2046 c20463 = new C2046();
            do {
                ᵲᵝᵪ r3 = f19853;
                r3.ᵦᵳˎ(c20463, c2046);
                if (r3.ᵯᵽ(this, c2046, c20463)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m10961(c20463);
                            throw new InterruptedException();
                        }
                        obj = this.f19857;
                    } while (obj == null);
                    return m10958(obj);
                }
                c2046 = this.f19858;
            } while (c2046 != c20462);
        }
        return m10958(this.f19857);
    }

    @Override // java.util.concurrent.Future
    public final Object get(long j, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        long nanos = timeUnit.toNanos(j);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Object obj = this.f19857;
        if (obj != null) {
            return m10958(obj);
        }
        long jNanoTime = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C2046 c2046 = this.f19858;
            C2046 c20462 = C2046.f8194;
            if (c2046 != c20462) {
                C2046 c20463 = new C2046();
                do {
                    ᵲᵝᵪ r11 = f19853;
                    r11.ᵦᵳˎ(c20463, c2046);
                    if (r11.ᵯᵽ(this, c2046, c20463)) {
                        do {
                            LockSupport.parkNanos(this, nanos);
                            if (Thread.interrupted()) {
                                m10961(c20463);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f19857;
                            if (obj2 != null) {
                                return m10958(obj2);
                            }
                            nanos = jNanoTime - System.nanoTime();
                        } while (nanos >= 1000);
                        m10961(c20463);
                    } else {
                        c2046 = this.f19858;
                    }
                } while (c2046 != c20462);
            }
            return m10958(this.f19857);
        }
        while (nanos > 0) {
            Object obj3 = this.f19857;
            if (obj3 != null) {
                return m10958(obj3);
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
            nanos = jNanoTime - System.nanoTime();
        }
        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 < 0) {
            String strConcat2 = strConcat.concat(" (plus ");
            long j2 = -nanos;
            long jConvert = timeUnit.convert(j2, TimeUnit.NANOSECONDS);
            long nanos2 = j2 - timeUnit.toNanos(jConvert);
            boolean z = true;
            if (jConvert != 0 && nanos2 <= 1000) {
                z = false;
            }
            if (jConvert > 0) {
                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(AbstractC1327.m4106(strConcat, " for ", string));
    }

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

    @Override // java.util.concurrent.Future
    public final boolean isDone() {
        return this.f19857 != null;
    }

    public final String toString() {
        String strConcat;
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append("[status=");
        if (this.f19857 instanceof C1712) {
            sb.append("CANCELLED");
        } else if (isDone()) {
            m10960(sb);
        } else {
            try {
                strConcat = mo6672();
            } catch (RuntimeException e) {
                strConcat = "Exception thrown from implementation: ".concat(String.valueOf(e.getClass()));
            }
            if (strConcat != null && !strConcat.isEmpty()) {
                sb.append("PENDING, info=[");
                sb.append(strConcat);
                sb.append("]");
            } else if (isDone()) {
                m10960(sb);
            } else {
                sb.append("PENDING");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final void m10960(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 (RuntimeException e) {
                sb.append("UNKNOWN, cause=[");
                sb.append(e.getClass());
                sb.append(" thrown from get()]");
                return;
            } catch (ExecutionException e2) {
                sb.append("FAILURE, cause=[");
                sb.append(e2.getCause());
                sb.append("]");
                return;
            }
        }
        if (z) {
            Thread.currentThread().interrupt();
        }
        sb.append("SUCCESS, result=[");
        sb.append(obj == this ? "this future" : String.valueOf(obj));
        sb.append("]");
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final void m10961(C2046 c2046) {
        c2046.f8195 = null;
        while (true) {
            C2046 c20462 = this.f19858;
            if (c20462 != C2046.f8194) {
                C2046 c20463 = null;
                while (c20462 != null) {
                    C2046 c20464 = c20462.f8196;
                    if (c20462.f8195 != null) {
                        c20463 = c20462;
                    } else if (c20463 != null) {
                        c20463.f8196 = c20464;
                        if (c20463.f8195 == null) {
                            break;
                        }
                    } else if (!f19853.ᵯᵽ(this, c20462, c20464)) {
                        break;
                    }
                    c20462 = c20464;
                }
                return;
            }
            return;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ˏᵙ */
    public String mo6672() {
        if (this instanceof ScheduledFuture) {
            return AbstractC4486.m9547(((ScheduledFuture) this).getDelay(TimeUnit.MILLISECONDS), "remaining delay=[", " ms]");
        }
        return null;
    }

    @Override // defpackage.InterfaceFutureC2302
    /* renamed from: ᵴᵳ */
    public final void mo5509(Runnable runnable, Executor executor) {
        executor.getClass();
        C5340 c5340 = this.f19856;
        C5340 c53402 = C5340.f19996;
        if (c5340 != c53402) {
            C5340 c53403 = new C5340(runnable, executor);
            do {
                c53403.f19997 = c5340;
                if (f19853.ˆʕ(this, c5340, c53403)) {
                    return;
                } else {
                    c5340 = this.f19856;
                }
            } while (c5340 != c53402);
        }
        m10957(runnable, executor);
    }
}
