package f.a.j.b;

import android.os.Handler;
import android.os.Message;
import f.a.g;
import f.a.k.c;
import java.util.concurrent.TimeUnit;

/* JADX INFO: compiled from: HandlerScheduler.java */
/* JADX INFO: loaded from: classes.dex */
final class b extends g {
    private final Handler b;

    /* JADX INFO: compiled from: HandlerScheduler.java */
    private static final class a extends g.c {
        private final Handler b;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private volatile boolean f820e;

        a(Handler handler) {
            this.b = handler;
        }

        @Override // f.a.g.c
        public f.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit) {
            if (runnable == null) {
                throw new NullPointerException("run == null");
            }
            if (timeUnit == null) {
                throw new NullPointerException("unit == null");
            }
            if (this.f820e) {
                return c.a();
            }
            RunnableC0049b runnableC0049b = new RunnableC0049b(this.b, f.a.p.a.o(runnable));
            Message messageObtain = Message.obtain(this.b, runnableC0049b);
            messageObtain.obj = this;
            this.b.sendMessageDelayed(messageObtain, Math.max(0L, timeUnit.toMillis(j2)));
            if (!this.f820e) {
                return runnableC0049b;
            }
            this.b.removeCallbacks(runnableC0049b);
            return c.a();
        }

        @Override // f.a.k.b
        public void dispose() {
            this.f820e = true;
            this.b.removeCallbacksAndMessages(this);
        }
    }

    /* JADX INFO: renamed from: f.a.j.b.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: HandlerScheduler.java */
    private static final class RunnableC0049b implements Runnable, f.a.k.b {
        private final Handler b;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final Runnable f821e;

        RunnableC0049b(Handler handler, Runnable runnable) {
            this.b = handler;
            this.f821e = runnable;
        }

        @Override // f.a.k.b
        public void dispose() {
            this.b.removeCallbacks(this);
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                this.f821e.run();
            } catch (Throwable th) {
                IllegalStateException illegalStateException = new IllegalStateException("Fatal Exception thrown on Scheduler.", th);
                f.a.p.a.m(illegalStateException);
                Thread threadCurrentThread = Thread.currentThread();
                threadCurrentThread.getUncaughtExceptionHandler().uncaughtException(threadCurrentThread, illegalStateException);
            }
        }
    }

    b(Handler handler) {
        this.b = handler;
    }

    @Override // f.a.g
    public g.c a() {
        return new a(this.b);
    }

    @Override // f.a.g
    public f.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit) {
        if (runnable == null) {
            throw new NullPointerException("run == null");
        }
        if (timeUnit == null) {
            throw new NullPointerException("unit == null");
        }
        RunnableC0049b runnableC0049b = new RunnableC0049b(this.b, f.a.p.a.o(runnable));
        this.b.postDelayed(runnableC0049b, Math.max(0L, timeUnit.toMillis(j2)));
        return runnableC0049b;
    }
}
