package kotlinx.coroutines;

import java.util.concurrent.CancellationException;

/* JADX INFO: compiled from: CoroutineScope.kt */
/* JADX INFO: loaded from: classes.dex */
public final class o0 {
    public static final n0 a(h.u.g gVar) {
        if (gVar.b(s1.f1166d) == null) {
            gVar = gVar.j(x1.b(null, 1, null));
        }
        return new kotlinx.coroutines.o2.d(gVar);
    }

    public static final void b(n0 n0Var, CancellationException cancellationException) {
        s1 s1Var = (s1) n0Var.f().b(s1.f1166d);
        if (s1Var == null) {
            throw new IllegalStateException(h.x.d.k.i("Scope cannot be cancelled because it does not have a job: ", n0Var).toString());
        }
        s1Var.u(cancellationException);
    }

    public static /* synthetic */ void c(n0 n0Var, CancellationException cancellationException, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            cancellationException = null;
        }
        b(n0Var, cancellationException);
    }

    public static final boolean d(n0 n0Var) {
        s1 s1Var = (s1) n0Var.f().b(s1.f1166d);
        if (s1Var == null) {
            return true;
        }
        return s1Var.isActive();
    }
}
