package kotlinx.coroutines.android; import android.os.Build; import java.lang.Thread; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import kotlin.coroutines.AbstractCoroutineContextElement; import kotlin.coroutines.CoroutineContext; import kotlinx.coroutines.CoroutineExceptionHandler; /* loaded from: classes5.dex */ public final class AndroidExceptionPreHandler extends AbstractCoroutineContextElement implements CoroutineExceptionHandler { private volatile Object _preHandler; public AndroidExceptionPreHandler() { super(CoroutineExceptionHandler.Key); this._preHandler = this; } public final Method preHandler() { Object obj = this._preHandler; if (obj != this) { return (Method) obj; } Method method = null; try { Method declaredMethod = Thread.class.getDeclaredMethod("getUncaughtExceptionPreHandler", new Class[0]); if (Modifier.isPublic(declaredMethod.getModifiers())) { if (Modifier.isStatic(declaredMethod.getModifiers())) { method = declaredMethod; } } } catch (Throwable unused) { } this._preHandler = method; return method; } @Override // kotlinx.coroutines.CoroutineExceptionHandler public void handleException(CoroutineContext coroutineContext, Throwable th) { if (Build.VERSION.SDK_INT < 28) { Method preHandler = preHandler(); Object invoke = preHandler != null ? preHandler.invoke(null, new Object[0]) : null; Thread.UncaughtExceptionHandler uncaughtExceptionHandler = invoke instanceof Thread.UncaughtExceptionHandler ? (Thread.UncaughtExceptionHandler) invoke : null; if (uncaughtExceptionHandler != null) { uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), th); } } } }