package p137;

import bolts.AggregateException;
import bolts.ExecutorException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: renamed from: ފ.ރ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2742<TResult> {

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public static final ExecutorService f8454;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final Executor f8455;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final Executor f8456;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static C2742<?> f8457;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public static C2742<Boolean> f8458;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public static C2742<Boolean> f8459;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public static C2742<?> f8460;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public boolean f8462;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean f8463;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public TResult f8464;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public Exception f8465;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean f8466;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public C2755 f8467;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Object f8461 = new Object();

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public List<InterfaceC2741<TResult, Void>> f8468 = new ArrayList();

    /* JADX INFO: renamed from: ފ.ރ$֏, reason: contains not printable characters */
    public class C2743 implements InterfaceC2741<TResult, Void> {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final /* synthetic */ C2754 f8469;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final /* synthetic */ InterfaceC2741 f8470;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final /* synthetic */ Executor f8471;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final /* synthetic */ C2739 f8472 = null;

        public C2743(C2742 c2742, C2754 c2754, InterfaceC2741 interfaceC2741, Executor executor) {
            this.f8469 = c2754;
            this.f8470 = interfaceC2741;
            this.f8471 = executor;
        }

        @Override // p137.InterfaceC2741
        public Void then(C2742 c2742) {
            C2754 c2754 = this.f8469;
            InterfaceC2741 interfaceC2741 = this.f8470;
            try {
                this.f8471.execute(new RunnableC2750(c2754, interfaceC2741, c2742));
                return null;
            } catch (Exception e) {
                c2754.m4826((Exception) new ExecutorException(e));
                return null;
            }
        }
    }

    /* JADX INFO: renamed from: ފ.ރ$ؠ, reason: contains not printable characters */
    public class C2744 implements InterfaceC2741<TResult, Void> {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final /* synthetic */ C2754 f8473;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final /* synthetic */ InterfaceC2741 f8474;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final /* synthetic */ Executor f8475;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final /* synthetic */ C2739 f8476 = null;

        public C2744(C2742 c2742, C2754 c2754, InterfaceC2741 interfaceC2741, Executor executor) {
            this.f8473 = c2754;
            this.f8474 = interfaceC2741;
            this.f8475 = executor;
        }

        @Override // p137.InterfaceC2741
        public Void then(C2742 c2742) {
            C2754 c2754 = this.f8473;
            InterfaceC2741 interfaceC2741 = this.f8474;
            try {
                this.f8475.execute(new RunnableC2751(c2754, interfaceC2741, c2742));
                return null;
            } catch (Exception e) {
                c2754.m4826((Exception) new ExecutorException(e));
                return null;
            }
        }
    }

    /* JADX INFO: renamed from: ފ.ރ$ހ, reason: contains not printable characters */
    public class C2745 implements InterfaceC2741<TResult, C2742<Void>> {
        public C2745(C2742 c2742) {
        }

        @Override // p137.InterfaceC2741
        public C2742<Void> then(C2742 c2742) {
            return c2742.m4818() ? C2742.f8460 : c2742.m4820() ? C2742.m4804(c2742.m4806()) : C2742.m4805((Object) null);
        }
    }

    /* JADX INFO: renamed from: ފ.ރ$ށ, reason: contains not printable characters */
    public static class RunnableC2746 implements Runnable {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final /* synthetic */ C2739 f8477 = null;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final /* synthetic */ C2754 f8478;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final /* synthetic */ Callable f8479;

        public RunnableC2746(C2754 c2754, Callable callable) {
            this.f8478 = c2754;
            this.f8479 = callable;
        }

        /* JADX WARN: Multi-variable type inference failed */
        @Override // java.lang.Runnable
        public void run() {
            try {
                this.f8478.m4827(this.f8479.call());
            } catch (CancellationException unused) {
                this.f8478.m4825();
            } catch (Exception e) {
                this.f8478.m4826(e);
            }
        }
    }

    /* JADX INFO: renamed from: ފ.ރ$ނ, reason: contains not printable characters */
    public static class C2747 implements InterfaceC2741<Object, Void> {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final /* synthetic */ Object f8480;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final /* synthetic */ ArrayList f8481;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final /* synthetic */ AtomicBoolean f8482;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final /* synthetic */ AtomicInteger f8483;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final /* synthetic */ C2754 f8484;

        public C2747(Object obj, ArrayList arrayList, AtomicBoolean atomicBoolean, AtomicInteger atomicInteger, C2754 c2754) {
            this.f8480 = obj;
            this.f8481 = arrayList;
            this.f8482 = atomicBoolean;
            this.f8483 = atomicInteger;
            this.f8484 = c2754;
        }

        @Override // p137.InterfaceC2741
        public /* bridge */ /* synthetic */ Void then(C2742<Object> c2742) {
            then(c2742);
            return null;
        }

        @Override // p137.InterfaceC2741
        public Void then(C2742<Object> c2742) {
            if (c2742.m4820()) {
                synchronized (this.f8480) {
                    this.f8481.add(c2742.m4806());
                }
            }
            if (c2742.m4818()) {
                this.f8482.set(true);
            }
            if (this.f8483.decrementAndGet() == 0) {
                if (this.f8481.size() != 0) {
                    if (this.f8481.size() == 1) {
                        this.f8484.m4826((Exception) this.f8481.get(0));
                    } else {
                        this.f8484.m4826((Exception) new AggregateException(String.format("There were %d exceptions.", Integer.valueOf(this.f8481.size())), this.f8481));
                    }
                } else if (this.f8482.get()) {
                    this.f8484.m4825();
                } else {
                    this.f8484.m4827((Object) null);
                }
            }
            return null;
        }
    }

    static {
        C2736 c2736 = C2736.f8449;
        f8454 = c2736.f8450;
        f8455 = c2736.f8451;
        f8456 = C2733.f8444.f8448;
        f8457 = new C2742<>((Object) null);
        f8458 = new C2742<>(true);
        f8459 = new C2742<>(false);
        f8460 = new C2742<>(true);
    }

    public C2742() {
    }

    public C2742(TResult tresult) {
        m4811(tresult);
    }

    public C2742(boolean z) {
        if (z) {
            m4823();
        } else {
            m4811((Object) null);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C2742<Void> m4801(Collection<? extends C2742<?>> collection) {
        if (collection.size() == 0) {
            return m4805((Object) null);
        }
        C2754 c2754 = new C2754();
        ArrayList arrayList = new ArrayList();
        Object obj = new Object();
        AtomicInteger atomicInteger = new AtomicInteger(collection.size());
        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        Iterator<? extends C2742<?>> it = collection.iterator();
        while (it.hasNext()) {
            it.next().m4809(new C2747(obj, arrayList, atomicBoolean, atomicInteger, c2754), f8455, (C2739) null);
        }
        return c2754.f8503;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static <TResult> C2742<TResult> m4802(Callable<TResult> callable, Executor executor) {
        return m4803(callable, executor, (C2739) null);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static <TResult> C2742<TResult> m4803(Callable<TResult> callable, Executor executor, C2739 c2739) {
        C2754 c2754 = new C2754();
        try {
            executor.execute(new RunnableC2746(c2754, callable));
        } catch (Exception e) {
            c2754.m4826((Exception) new ExecutorException(e));
        }
        return c2754.f8503;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static <TResult> C2742<TResult> m4804(Exception exc) {
        C2742<TResult> c2742 = new C2742<>();
        if (c2742.m4810(exc)) {
            return c2742;
        }
        throw new IllegalStateException("Cannot set the error on a completed task.");
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static <TResult> C2742<TResult> m4805(TResult tresult) {
        if (tresult == 0) {
            return (C2742<TResult>) f8457;
        }
        if (tresult instanceof Boolean) {
            return ((Boolean) tresult).booleanValue() ? (C2742<TResult>) f8458 : (C2742<TResult>) f8459;
        }
        C2742<TResult> c2742 = new C2742<>();
        if (c2742.m4811(tresult)) {
            return c2742;
        }
        throw new IllegalStateException("Cannot set the result of a completed task.");
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public Exception m4806() {
        Exception exc;
        synchronized (this.f8461) {
            if (this.f8465 != null) {
                this.f8466 = true;
                if (this.f8467 != null) {
                    this.f8467.f8504 = null;
                    this.f8467 = null;
                }
            }
            exc = this.f8465;
        }
        return exc;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4807(InterfaceC2741<TResult, TContinuationResult> interfaceC2741) {
        return m4809(interfaceC2741, f8455, (C2739) null);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4808(InterfaceC2741<TResult, C2742<TContinuationResult>> interfaceC2741, Executor executor) {
        return m4815(interfaceC2741, executor, null);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4809(InterfaceC2741<TResult, TContinuationResult> interfaceC2741, Executor executor, C2739 c2739) {
        boolean zM4819;
        C2754 c2754 = new C2754();
        synchronized (this.f8461) {
            zM4819 = m4819();
            if (!zM4819) {
                this.f8468.add(new C2743(this, c2754, interfaceC2741, executor));
            }
        }
        if (zM4819) {
            try {
                executor.execute(new RunnableC2750(c2754, interfaceC2741, this));
            } catch (Exception e) {
                c2754.m4826((Exception) new ExecutorException(e));
            }
        }
        return c2754.f8503;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public boolean m4810(Exception exc) {
        synchronized (this.f8461) {
            if (this.f8462) {
                return false;
            }
            this.f8462 = true;
            this.f8465 = exc;
            this.f8466 = false;
            this.f8461.notifyAll();
            m4822();
            return true;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public boolean m4811(TResult tresult) {
        synchronized (this.f8461) {
            if (this.f8462) {
                return false;
            }
            this.f8462 = true;
            this.f8464 = tresult;
            this.f8461.notifyAll();
            m4822();
            return true;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public TResult m4812() {
        TResult tresult;
        synchronized (this.f8461) {
            tresult = this.f8464;
        }
        return tresult;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4813(InterfaceC2741<TResult, C2742<TContinuationResult>> interfaceC2741) {
        return m4815(interfaceC2741, f8455, null);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4814(InterfaceC2741<TResult, TContinuationResult> interfaceC2741, Executor executor) {
        return m4815(new C2748(this, interfaceC2741), executor, null);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4815(InterfaceC2741<TResult, C2742<TContinuationResult>> interfaceC2741, Executor executor, C2739 c2739) {
        boolean zM4819;
        C2754 c2754 = new C2754();
        synchronized (this.f8461) {
            zM4819 = m4819();
            if (!zM4819) {
                this.f8468.add(new C2744(this, c2754, interfaceC2741, executor));
            }
        }
        if (zM4819) {
            try {
                executor.execute(new RunnableC2751(c2754, interfaceC2741, this));
            } catch (Exception e) {
                c2754.m4826((Exception) new ExecutorException(e));
            }
        }
        return c2754.f8503;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4816(InterfaceC2741<TResult, TContinuationResult> interfaceC2741) {
        return m4815(new C2748(this, interfaceC2741), f8455, null);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public <TContinuationResult> C2742<TContinuationResult> m4817(InterfaceC2741<TResult, C2742<TContinuationResult>> interfaceC2741, Executor executor) {
        return m4815(new C2749(this, interfaceC2741), executor, null);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean m4818() {
        boolean z;
        synchronized (this.f8461) {
            z = this.f8463;
        }
        return z;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public boolean m4819() {
        boolean z;
        synchronized (this.f8461) {
            z = this.f8462;
        }
        return z;
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public boolean m4820() {
        boolean z;
        synchronized (this.f8461) {
            z = m4806() != null;
        }
        return z;
    }

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public C2742<Void> m4821() {
        return m4815(new C2745(this), f8455, null);
    }

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final void m4822() {
        synchronized (this.f8461) {
            Iterator<InterfaceC2741<TResult, Void>> it = this.f8468.iterator();
            while (it.hasNext()) {
                try {
                    it.next().then(this);
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e2) {
                    throw new RuntimeException(e2);
                }
            }
            this.f8468 = null;
        }
    }

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean m4823() {
        synchronized (this.f8461) {
            if (this.f8462) {
                return false;
            }
            this.f8462 = true;
            this.f8463 = true;
            this.f8461.notifyAll();
            m4822();
            return true;
        }
    }

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public void m4824() {
        synchronized (this.f8461) {
            if (!m4819()) {
                this.f8461.wait();
            }
        }
    }
}
