59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
package kotlinx.coroutines.android;
|
|
|
|
import android.os.Build;
|
|
import androidx.annotation.Keep;
|
|
import d0.w.a;
|
|
import java.lang.Thread;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Modifier;
|
|
import kotlin.coroutines.CoroutineContext;
|
|
import kotlinx.coroutines.CoroutineExceptionHandler;
|
|
/* compiled from: AndroidExceptionPreHandler.kt */
|
|
@Keep
|
|
public final class AndroidExceptionPreHandler extends a implements CoroutineExceptionHandler {
|
|
private volatile Object _preHandler = this;
|
|
|
|
public AndroidExceptionPreHandler() {
|
|
super(CoroutineExceptionHandler.a.a);
|
|
}
|
|
|
|
private final Method preHandler() {
|
|
Object obj = this._preHandler;
|
|
if (obj != this) {
|
|
return (Method) obj;
|
|
}
|
|
Method method = null;
|
|
boolean z2 = false;
|
|
try {
|
|
Method declaredMethod = Thread.class.getDeclaredMethod("getUncaughtExceptionPreHandler", new Class[0]);
|
|
if (Modifier.isPublic(declaredMethod.getModifiers()) && Modifier.isStatic(declaredMethod.getModifiers())) {
|
|
z2 = true;
|
|
}
|
|
if (z2) {
|
|
method = declaredMethod;
|
|
}
|
|
} catch (Throwable unused) {
|
|
}
|
|
this._preHandler = method;
|
|
return method;
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CoroutineExceptionHandler
|
|
public void handleException(CoroutineContext coroutineContext, Throwable th) {
|
|
Thread currentThread = Thread.currentThread();
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, th);
|
|
return;
|
|
}
|
|
Method preHandler = preHandler();
|
|
Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null;
|
|
Object invoke = preHandler != null ? preHandler.invoke(null, new Object[0]) : null;
|
|
if (invoke instanceof Thread.UncaughtExceptionHandler) {
|
|
uncaughtExceptionHandler = invoke;
|
|
}
|
|
Thread.UncaughtExceptionHandler uncaughtExceptionHandler2 = uncaughtExceptionHandler;
|
|
if (uncaughtExceptionHandler2 != null) {
|
|
uncaughtExceptionHandler2.uncaughtException(currentThread, th);
|
|
}
|
|
}
|
|
}
|