package c.a.r;

import c.a.d;
import c.a.g;
import c.a.h;
import c.a.j;
import c.a.o.c;
import c.a.p.b;
import c.a.p.e;
import c.a.p.f;
import java.util.concurrent.Callable;

/* JADX INFO: compiled from: RxJavaPlugins.java */
/* JADX INFO: loaded from: classes.dex */
public final class a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    static volatile e<? super Throwable> f1901a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    static volatile f<? super Runnable, ? extends Runnable> f1902b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    static volatile f<? super Callable<g>, ? extends g> f1903c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    static volatile f<? super Callable<g>, ? extends g> f1904d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    static volatile f<? super Callable<g>, ? extends g> f1905e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static volatile f<? super Callable<g>, ? extends g> f1906f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    static volatile f<? super g, ? extends g> f1907g;
    static volatile f<? super g, ? extends g> h;
    static volatile f<? super d, ? extends d> i;
    static volatile f<? super h, ? extends h> j;
    static volatile b<? super d, ? super c.a.f, ? extends c.a.f> k;
    static volatile b<? super h, ? super j, ? extends j> l;
    static volatile c.a.p.d m;
    static volatile boolean n;

    static <T, U, R> R a(b<T, U, R> bVar, T t, U u) {
        try {
            return bVar.apply(t, u);
        } catch (Throwable th) {
            throw c.a.q.h.b.a(th);
        }
    }

    static <T, R> R b(f<T, R> fVar, T t) {
        try {
            return fVar.apply(t);
        } catch (Throwable th) {
            throw c.a.q.h.b.a(th);
        }
    }

    static g c(f<? super Callable<g>, ? extends g> fVar, Callable<g> callable) {
        return (g) c.a.q.b.b.c(b(fVar, callable), "Scheduler Callable result can't be null");
    }

    static g d(Callable<g> callable) {
        try {
            return (g) c.a.q.b.b.c(callable.call(), "Scheduler Callable result can't be null");
        } catch (Throwable th) {
            throw c.a.q.h.b.a(th);
        }
    }

    public static g e(Callable<g> callable) {
        c.a.q.b.b.c(callable, "Scheduler Callable can't be null");
        f<? super Callable<g>, ? extends g> fVar = f1903c;
        return fVar == null ? d(callable) : c(fVar, callable);
    }

    public static g f(Callable<g> callable) {
        c.a.q.b.b.c(callable, "Scheduler Callable can't be null");
        f<? super Callable<g>, ? extends g> fVar = f1905e;
        return fVar == null ? d(callable) : c(fVar, callable);
    }

    public static g g(Callable<g> callable) {
        c.a.q.b.b.c(callable, "Scheduler Callable can't be null");
        f<? super Callable<g>, ? extends g> fVar = f1906f;
        return fVar == null ? d(callable) : c(fVar, callable);
    }

    public static g h(Callable<g> callable) {
        c.a.q.b.b.c(callable, "Scheduler Callable can't be null");
        f<? super Callable<g>, ? extends g> fVar = f1904d;
        return fVar == null ? d(callable) : c(fVar, callable);
    }

    static boolean i(Throwable th) {
        return (th instanceof c) || (th instanceof IllegalStateException) || (th instanceof NullPointerException) || (th instanceof IllegalArgumentException) || (th instanceof c.a.o.a);
    }

    public static boolean j() {
        return n;
    }

    public static <T> d<T> k(d<T> dVar) {
        f<? super d, ? extends d> fVar = i;
        return fVar != null ? (d) b(fVar, dVar) : dVar;
    }

    public static <T> h<T> l(h<T> hVar) {
        f<? super h, ? extends h> fVar = j;
        return fVar != null ? (h) b(fVar, hVar) : hVar;
    }

    public static boolean m() {
        c.a.p.d dVar = m;
        if (dVar == null) {
            return false;
        }
        try {
            return dVar.a();
        } catch (Throwable th) {
            throw c.a.q.h.b.a(th);
        }
    }

    public static g n(g gVar) {
        f<? super g, ? extends g> fVar = f1907g;
        return fVar == null ? gVar : (g) b(fVar, gVar);
    }

    public static void o(Throwable th) {
        e<? super Throwable> eVar = f1901a;
        if (th == null) {
            th = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
        } else if (!i(th)) {
            th = new c.a.o.e(th);
        }
        if (eVar != null) {
            try {
                eVar.accept(th);
                return;
            } catch (Throwable th2) {
                th2.printStackTrace();
                t(th2);
            }
        }
        th.printStackTrace();
        t(th);
    }

    public static g p(g gVar) {
        f<? super g, ? extends g> fVar = h;
        return fVar == null ? gVar : (g) b(fVar, gVar);
    }

    public static Runnable q(Runnable runnable) {
        f<? super Runnable, ? extends Runnable> fVar = f1902b;
        return fVar == null ? runnable : (Runnable) b(fVar, runnable);
    }

    public static <T> c.a.f<? super T> r(d<T> dVar, c.a.f<? super T> fVar) {
        b<? super d, ? super c.a.f, ? extends c.a.f> bVar = k;
        return bVar != null ? (c.a.f) a(bVar, dVar, fVar) : fVar;
    }

    public static <T> j<? super T> s(h<T> hVar, j<? super T> jVar) {
        b<? super h, ? super j, ? extends j> bVar = l;
        return bVar != null ? (j) a(bVar, hVar, jVar) : jVar;
    }

    static void t(Throwable th) {
        Thread threadCurrentThread = Thread.currentThread();
        threadCurrentThread.getUncaughtExceptionHandler().uncaughtException(threadCurrentThread, th);
    }
}
