package i.a.j.b;

import android.os.Handler;
import android.os.Message;
import i.a.h;
import i.a.k.c;
import java.util.concurrent.TimeUnit;

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

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

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

        @Override // i.a.h.c
        public i.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.d) {
                return c.a();
            }
            RunnableC0074b runnableC0074b = new RunnableC0074b(this.b, i.a.p.a.o(runnable));
            Message messageObtain = Message.obtain(this.b, runnableC0074b);
            messageObtain.obj = this;
            this.b.sendMessageDelayed(messageObtain, Math.max(0L, timeUnit.toMillis(j2)));
            if (!this.d) {
                return runnableC0074b;
            }
            this.b.removeCallbacks(runnableC0074b);
            return c.a();
        }

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

        @Override // i.a.k.b
        public boolean isDisposed() {
            return this.d;
        }
    }

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

        RunnableC0074b(Handler handler, Runnable runnable) {
            this.b = handler;
            this.d = runnable;
        }

        @Override // i.a.k.b
        public void dispose() {
            this.e = true;
            this.b.removeCallbacks(this);
        }

        @Override // i.a.k.b
        public boolean isDisposed() {
            return this.e;
        }

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

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

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

    @Override // i.a.h
    public i.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");
        }
        RunnableC0074b runnableC0074b = new RunnableC0074b(this.b, i.a.p.a.o(runnable));
        this.b.postDelayed(runnableC0074b, Math.max(0L, timeUnit.toMillis(j2)));
        return runnableC0074b;
    }
}
