package k9; import java.util.concurrent.CancellationException; import s8.n; /* loaded from: classes2.dex */ public abstract class x0 extends kotlinx.coroutines.scheduling.h { /* renamed from: c, reason: collision with root package name */ public int f11403c; public x0(int i10) { this.f11403c = i10; } public abstract void c(Object obj, Throwable th); public abstract v8.d d(); public Throwable i(Object obj) { a0 a0Var = obj instanceof a0 ? (a0) obj : null; if (a0Var == null) { return null; } return a0Var.f11296a; } public Object j(Object obj) { return obj; } public final void k(Throwable th, Throwable th2) { if (th == null && th2 == null) { return; } if (th != null && th2 != null) { s8.b.a(th, th2); } if (th == null) { th = th2; } d9.j.b(th); j0.a(d().getContext(), new n0("Fatal exception in coroutines machinery for " + this + ". Please read KDoc to 'handleFatalException' method and report this incident to maintainers", th)); } public abstract Object l(); @Override // java.lang.Runnable public final void run() { Object b10; Object b11; kotlinx.coroutines.scheduling.i iVar = this.f11527b; try { kotlinx.coroutines.internal.f fVar = (kotlinx.coroutines.internal.f) d(); v8.d dVar = fVar.f11448e; Object obj = fVar.f11450g; v8.g context = dVar.getContext(); Object c10 = kotlinx.coroutines.internal.c0.c(context, obj); a3 g10 = c10 != kotlinx.coroutines.internal.c0.f11436a ? f0.g(dVar, context, c10) : null; try { v8.g context2 = dVar.getContext(); Object l10 = l(); Throwable i10 = i(l10); u1 u1Var = (i10 == null && y0.b(this.f11403c)) ? (u1) context2.get(u1.T) : null; if (u1Var != null && !u1Var.c()) { CancellationException S = u1Var.S(); c(l10, S); n.a aVar = s8.n.f14096b; dVar.resumeWith(s8.n.b(s8.o.a(S))); } else if (i10 != null) { n.a aVar2 = s8.n.f14096b; dVar.resumeWith(s8.n.b(s8.o.a(i10))); } else { dVar.resumeWith(s8.n.b(j(l10))); } s8.v vVar = s8.v.f14109a; try { iVar.a(); b11 = s8.n.b(s8.v.f14109a); } catch (Throwable th) { n.a aVar3 = s8.n.f14096b; b11 = s8.n.b(s8.o.a(th)); } k(null, s8.n.d(b11)); } finally { if (g10 == null || g10.L0()) { kotlinx.coroutines.internal.c0.a(context, c10); } } } catch (Throwable th2) { try { n.a aVar4 = s8.n.f14096b; iVar.a(); b10 = s8.n.b(s8.v.f14109a); } catch (Throwable th3) { n.a aVar5 = s8.n.f14096b; b10 = s8.n.b(s8.o.a(th3)); } k(th2, s8.n.d(b10)); } } }