package up;

import android.os.Handler;
import android.os.Looper;
import dn.l;
import java.util.concurrent.CancellationException;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import rm.n0;
import tp.a1;
import tp.o;
import tp.y1;
import vm.g;

/* loaded from: classes3.dex */
public final class c extends d {
    private volatile c _immediate;

    /* renamed from: r, reason: collision with root package name */
    private final Handler f37361r;

    /* renamed from: s, reason: collision with root package name */
    private final String f37362s;

    /* renamed from: t, reason: collision with root package name */
    private final boolean f37363t;

    /* renamed from: u, reason: collision with root package name */
    private final c f37364u;

    /* loaded from: classes3.dex */
    public static final class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ o f37365p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ c f37366q;

        public a(o oVar, c cVar) {
            this.f37365p = oVar;
            this.f37366q = cVar;
        }

        @Override // java.lang.Runnable
        public final void run() {
            this.f37365p.C(this.f37366q, n0.f34904a);
        }
    }

    /* loaded from: classes3.dex */
    static final class b extends v implements l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Runnable f37368q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(Runnable runnable) {
            super(1);
            this.f37368q = runnable;
        }

        public final void a(Throwable th2) {
            c.this.f37361r.removeCallbacks(this.f37368q);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Throwable) obj);
            return n0.f34904a;
        }
    }

    private c(Handler handler, String str, boolean z10) {
        super(null);
        this.f37361r = handler;
        this.f37362s = str;
        this.f37363t = z10;
        this._immediate = z10 ? this : null;
        c cVar = this._immediate;
        if (cVar == null) {
            cVar = new c(handler, str, true);
            this._immediate = cVar;
        }
        this.f37364u = cVar;
    }

    private final void g0(g gVar, Runnable runnable) {
        y1.d(gVar, new CancellationException("The task was rejected, the handler underlying the dispatcher '" + this + "' was closed"));
        a1.b().C(gVar, runnable);
    }

    @Override // tp.i0
    public void C(g gVar, Runnable runnable) {
        if (this.f37361r.post(runnable)) {
            return;
        }
        g0(gVar, runnable);
    }

    @Override // tp.i0
    public boolean L(g gVar) {
        return (this.f37363t && t.b(Looper.myLooper(), this.f37361r.getLooper())) ? false : true;
    }

    public boolean equals(Object obj) {
        return (obj instanceof c) && ((c) obj).f37361r == this.f37361r;
    }

    @Override // tp.v0
    public void g(long j10, o oVar) {
        long h10;
        a aVar = new a(oVar, this);
        Handler handler = this.f37361r;
        h10 = jn.o.h(j10, 4611686018427387903L);
        if (handler.postDelayed(aVar, h10)) {
            oVar.x(new b(aVar));
        } else {
            g0(oVar.getContext(), aVar);
        }
    }

    public int hashCode() {
        return System.identityHashCode(this.f37361r);
    }

    @Override // up.d
    /* renamed from: j0, reason: merged with bridge method [inline-methods] and merged with bridge method [inline-methods] */
    public c a0() {
        return this.f37364u;
    }

    @Override // tp.i0
    public String toString() {
        String Y = Y();
        if (Y != null) {
            return Y;
        }
        String str = this.f37362s;
        if (str == null) {
            str = this.f37361r.toString();
        }
        if (!this.f37363t) {
            return str;
        }
        return str + ".immediate";
    }

    public /* synthetic */ c(Handler handler, String str, int i10, k kVar) {
        this(handler, (i10 & 2) != 0 ? null : str);
    }

    public c(Handler handler, String str) {
        this(handler, str, false);
    }
}
