package f.a.p;

import f.a.f;
import f.a.g;
import f.a.h;
import f.a.i;
import f.a.l.e;
import f.a.m.b;
import f.a.m.c;
import f.a.m.d;
import java.util.concurrent.Callable;

/* JADX INFO: compiled from: RxJavaPlugins.java */
/* JADX INFO: loaded from: classes.dex */
public final class a {
    static volatile c<? super Throwable> a;
    static volatile d<? super Runnable, ? extends Runnable> b;

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

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

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

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    static volatile d<? super f.a.d, ? extends f.a.d> f939i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    static volatile d<? super h, ? extends h> f940j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    static volatile b<? super f.a.d, ? super f, ? extends f> f941k;
    static volatile b<? super h, ? super i, ? extends i> l;

    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 f.a.n.h.b.a(th);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    static <T, R> R b(d<T, R> dVar, T t) {
        try {
            dVar.apply(t);
            return t;
        } catch (Throwable th) {
            throw f.a.n.h.b.a(th);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    static g c(d<? super Callable<g>, ? extends g> dVar, Callable<g> callable) {
        b(dVar, callable);
        f.a.n.b.b.d(callable, "Scheduler Callable result can't be null");
        return (g) callable;
    }

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

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

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

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

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

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

    public static <T> f.a.d<T> j(f.a.d<T> dVar) {
        d<? super f.a.d, ? extends f.a.d> dVar2 = f939i;
        if (dVar2 == null) {
            return dVar;
        }
        b(dVar2, dVar);
        return dVar;
    }

    public static <T> h<T> k(h<T> hVar) {
        d<? super h, ? extends h> dVar = f940j;
        if (dVar == null) {
            return hVar;
        }
        b(dVar, hVar);
        return hVar;
    }

    public static g l(g gVar) {
        d<? super g, ? extends g> dVar = f937g;
        if (dVar == null) {
            return gVar;
        }
        b(dVar, gVar);
        return gVar;
    }

    public static void m(Throwable th) {
        c<? super Throwable> cVar = a;
        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 e(th);
        }
        if (cVar != null) {
            try {
                cVar.accept(th);
                return;
            } catch (Throwable th2) {
                th2.printStackTrace();
                r(th2);
            }
        }
        th.printStackTrace();
        r(th);
    }

    public static g n(g gVar) {
        d<? super g, ? extends g> dVar = f938h;
        if (dVar == null) {
            return gVar;
        }
        b(dVar, gVar);
        return gVar;
    }

    public static Runnable o(Runnable runnable) {
        d<? super Runnable, ? extends Runnable> dVar = b;
        if (dVar == null) {
            return runnable;
        }
        b(dVar, runnable);
        return runnable;
    }

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

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

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