package kotlinx.coroutines;

import java.lang.reflect.Method;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public final class s0 extends r0 implements d0 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Executor f29532c;

    public s0(Executor executor) {
        Method method;
        this.f29532c = executor;
        Method method2 = kotlinx.coroutines.internal.c.f29455a;
        try {
            ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = executor instanceof ScheduledThreadPoolExecutor ? (ScheduledThreadPoolExecutor) executor : null;
            if (scheduledThreadPoolExecutor != null && (method = kotlinx.coroutines.internal.c.f29455a) != null) {
                method.invoke(scheduledThreadPoolExecutor, Boolean.TRUE);
            }
        } catch (Throwable unused) {
        }
    }

    @Override // kotlinx.coroutines.t
    public final void L(kotlin.coroutines.h hVar, Runnable runnable) {
        try {
            this.f29532c.execute(runnable);
        } catch (RejectedExecutionException e10) {
            CancellationException cancellationException = new CancellationException("The task was rejected");
            cancellationException.initCause(e10);
            y.d(hVar, cancellationException);
            h0.f29441b.L(hVar, runnable);
        }
    }

    @Override // kotlinx.coroutines.r0
    public final Executor O() {
        return this.f29532c;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        Executor executor = this.f29532c;
        ExecutorService executorService = executor instanceof ExecutorService ? (ExecutorService) executor : null;
        if (executorService != null) {
            executorService.shutdown();
        }
    }

    public final boolean equals(Object obj) {
        return (obj instanceof s0) && ((s0) obj).f29532c == this.f29532c;
    }

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

    @Override // kotlinx.coroutines.d0
    public final j0 k(long j10, r1 r1Var, kotlin.coroutines.h hVar) {
        Executor executor = this.f29532c;
        ScheduledFuture<?> scheduledFutureSchedule = null;
        ScheduledExecutorService scheduledExecutorService = executor instanceof ScheduledExecutorService ? (ScheduledExecutorService) executor : null;
        if (scheduledExecutorService != null) {
            try {
                scheduledFutureSchedule = scheduledExecutorService.schedule(r1Var, j10, TimeUnit.MILLISECONDS);
            } catch (RejectedExecutionException e10) {
                CancellationException cancellationException = new CancellationException("The task was rejected");
                cancellationException.initCause(e10);
                y.d(hVar, cancellationException);
            }
        }
        return scheduledFutureSchedule != null ? new i0(scheduledFutureSchedule) : z.f29593j.k(j10, r1Var, hVar);
    }

    @Override // kotlinx.coroutines.t
    public final String toString() {
        return this.f29532c.toString();
    }
}
