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;

/* JADX INFO: renamed from: ᵾᵎᵖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public class C5431 implements InterfaceFutureC1876 {

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

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public static final boolean f20608 = Boolean.parseBoolean(System.getProperty("guava.concurrent.generate_cancellation_cause", "false"));

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static final Logger f20609 = Logger.getLogger(C5431.class.getName());

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

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

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

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

    static {
        ᵝˉː c1509;
        try {
            c1509 = new C2370(AtomicReferenceFieldUpdater.newUpdater(C1273.class, Thread.class, "ᵲᵶᵳˈ"), AtomicReferenceFieldUpdater.newUpdater(C1273.class, C1273.class, "ʽˈˋ"), AtomicReferenceFieldUpdater.newUpdater(C5431.class, C1273.class, "ᵔᵖᵹᵫ"), AtomicReferenceFieldUpdater.newUpdater(C5431.class, C0629.class, "ᵜᵪʾ"), AtomicReferenceFieldUpdater.newUpdater(C5431.class, Object.class, "ˌᴵ"));
            th = null;
        } catch (Throwable th) {
            th = th;
            c1509 = new C1509();
        }
        Throwable th2 = th;
        f20610 = c1509;
        if (th2 != null) {
            f20609.logp(Level.SEVERE, "com.android.billingclient.util.concurrent.AbstractResolvableFuture", "<clinit>", "SafeAtomicHelper is broken!", th2);
        }
        f20607 = new Object();
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static final Object m11046(Object obj) throws ExecutionException {
        if (obj instanceof C5068) {
            Throwable th = ((C5068) obj).f19124;
            CancellationException cancellationException = new CancellationException("Task was cancelled.");
            cancellationException.initCause(th);
            throw cancellationException;
        }
        if (obj instanceof C0392) {
            throw new ExecutionException(((C0392) obj).f2237);
        }
        if (obj == f20607) {
            return null;
        }
        return obj;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static void m11047(C5431 c5431) {
        C1273 c1273;
        ᵝˉː r1;
        C0629 c0629;
        C0629 c06292;
        C0629 c06293;
        do {
            c1273 = c5431.f20612;
            r1 = f20610;
        } while (!r1.ᵡᵶ(c5431, c1273, C1273.f5337));
        while (true) {
            c0629 = null;
            if (c1273 == null) {
                break;
            }
            Thread thread = c1273.f5339;
            if (thread != null) {
                c1273.f5339 = null;
                LockSupport.unpark(thread);
            }
            c1273 = c1273.f5338;
        }
        do {
            c06292 = c5431.f20613;
        } while (!r1.ˏᵩʨ(c5431, c06292, C0629.f2980));
        while (true) {
            c06293 = c0629;
            c0629 = c06292;
            if (c0629 == null) {
                break;
            }
            c06292 = c0629.f2982;
            c0629.f2982 = c06293;
        }
        while (c06293 != null) {
            Runnable runnable = c06293.f2983;
            C0629 c06294 = c06293.f2982;
            m11048(runnable, c06293.f2981);
            c06293 = c06294;
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static void m11048(Runnable runnable, Executor executor) {
        try {
            executor.execute(runnable);
        } catch (RuntimeException e) {
            f20609.logp(Level.SEVERE, "com.android.billingclient.util.concurrent.AbstractResolvableFuture", "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) {
        Object obj = this.f20611;
        if (obj != null) {
            return false;
        }
        if (!f20610.ʿᵿʽᵞ(this, obj, f20608 ? new C5068(new CancellationException("Future.cancel() was called.")) : z ? C5068.f19122 : C5068.f19123)) {
            return false;
        }
        m11047(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.f20611;
        if (obj2 != null) {
            return m11046(obj2);
        }
        C1273 c1273 = this.f20612;
        C1273 c12732 = C1273.f5337;
        if (c1273 != c12732) {
            C1273 c12733 = new C1273();
            do {
                ᵝˉː r3 = f20610;
                r3.ᵞᵛᵘ(c12733, c1273);
                if (r3.ᵡᵶ(this, c1273, c12733)) {
                    do {
                        LockSupport.park(this);
                        if (Thread.interrupted()) {
                            m11050(c12733);
                            throw new InterruptedException();
                        }
                        obj = this.f20611;
                    } while (obj == null);
                    return m11046(obj);
                }
                c1273 = this.f20612;
            } while (c1273 != c12732);
        }
        return m11046(this.f20611);
    }

    @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.f20611;
        if (obj != null) {
            return m11046(obj);
        }
        long jNanoTime = nanos > 0 ? System.nanoTime() + nanos : 0L;
        if (nanos >= 1000) {
            C1273 c1273 = this.f20612;
            C1273 c12732 = C1273.f5337;
            if (c1273 != c12732) {
                C1273 c12733 = new C1273();
                do {
                    ᵝˉː r11 = f20610;
                    r11.ᵞᵛᵘ(c12733, c1273);
                    if (r11.ᵡᵶ(this, c1273, c12733)) {
                        do {
                            LockSupport.parkNanos(this, nanos);
                            if (Thread.interrupted()) {
                                m11050(c12733);
                                throw new InterruptedException();
                            }
                            Object obj2 = this.f20611;
                            if (obj2 != null) {
                                return m11046(obj2);
                            }
                            nanos = jNanoTime - System.nanoTime();
                        } while (nanos >= 1000);
                        m11050(c12733);
                    } else {
                        c1273 = this.f20612;
                    }
                } while (c1273 != c12732);
            }
            return m11046(this.f20611);
        }
        while (nanos > 0) {
            Object obj3 = this.f20611;
            if (obj3 != null) {
                return m11046(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(AbstractC3653.m8223(strConcat, " for ", string));
    }

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

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

    public final String toString() {
        String strConcat;
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append("[status=");
        if (this.f20611 instanceof C5068) {
            sb.append("CANCELLED");
        } else if (isDone()) {
            m11049(sb);
        } else {
            try {
                strConcat = mo7058();
            } 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()) {
                m11049(sb);
            } else {
                sb.append("PENDING");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    @Override // defpackage.InterfaceFutureC1876
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo3844(Runnable runnable, Executor executor) {
        executor.getClass();
        C0629 c0629 = this.f20613;
        C0629 c06292 = C0629.f2980;
        if (c0629 != c06292) {
            C0629 c06293 = new C0629(runnable, executor);
            do {
                c06293.f2982 = c0629;
                if (f20610.ˏᵩʨ(this, c0629, c06293)) {
                    return;
                } else {
                    c0629 = this.f20613;
                }
            } while (c0629 != c06292);
        }
        m11048(runnable, executor);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public String mo7058() {
        if (this instanceof ScheduledFuture) {
            return AbstractC3589.m8118(((ScheduledFuture) this).getDelay(TimeUnit.MILLISECONDS), "remaining delay=[", " ms]");
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final void m11049(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("]");
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final void m11050(C1273 c1273) {
        c1273.f5339 = null;
        while (true) {
            C1273 c12732 = this.f20612;
            if (c12732 != C1273.f5337) {
                C1273 c12733 = null;
                while (c12732 != null) {
                    C1273 c12734 = c12732.f5338;
                    if (c12732.f5339 != null) {
                        c12733 = c12732;
                    } else if (c12733 != null) {
                        c12733.f5338 = c12734;
                        if (c12733.f5339 == null) {
                            break;
                        }
                    } else if (!f20610.ᵡᵶ(this, c12732, c12734)) {
                        break;
                    }
                    c12732 = c12734;
                }
                return;
            }
            return;
        }
    }
}
