content: package kotlinx.coroutines.android;
  
  import android.os.Build;
  import java.lang.Thread;
  import java.lang.reflect.Method;
  import java.lang.reflect.Modifier;
  import kotlin.Metadata;
  import kotlin.coroutines.AbstractCoroutineContextElement;
  import kotlin.coroutines.CoroutineContext;
  import kotlinx.coroutines.CoroutineExceptionHandler;
  
  @Metadata(d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0003\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0001\u0018\u00002\u00020\u00012\u00020\u0002B\u0005¢\u0006\u0002\u0010\u0003J\u0018\u0010\u0006\u001a\u00020\u00072\u0006\u0010\b\u001a\u00020\t2\u0006\u0010\n\u001a\u00020\u000bH\u0016J\n\u0010\f\u001a\u0004\u0018\u00010\rH\u0002R\u0010\u0010\u0004\u001a\u0004\u0018\u00010\u0005X\u000e¢\u0006\u0002\n\u0000¨\u0006\u000e"}, d2 = {"Lkotlinx/coroutines/android/AndroidExceptionPreHandler;", "Lkotlin/coroutines/AbstractCoroutineContextElement;", "Lkotlinx/coroutines/CoroutineExceptionHandler;", "()V", "_preHandler", "", "handleException", "", "context", "Lkotlin/coroutines/CoroutineContext;", "exception", "", "preHandler", "Ljava/lang/reflect/Method;", "kotlinx-coroutines-android"}, k = 1, mv = {1, 6, 0}, xi = 48)
  /* compiled from: AndroidExceptionPreHandler.kt */
  public final class AndroidExceptionPreHandler extends AbstractCoroutineContextElement implements CoroutineExceptionHandler {
      private volatile Object _preHandler = this;
  
      public AndroidExceptionPreHandler() {
          super(CoroutineExceptionHandler.Key);
      }
  
      private final Method preHandler() {
          Object obj = this._preHandler;
          if (obj != this) {
              return (Method) obj;
          }
          Method method = null;
          boolean z = false;
          try {
              Method declaredMethod = Thread.class.getDeclaredMethod("getUncaughtExceptionPreHandler", new Class[0]);
              Method method2 = declaredMethod;
              if (Modifier.isPublic(method2.getModifiers()) && Modifier.isStatic(method2.getModifiers())) {
                  z = true;
              }
              if (z) {
                  method = declaredMethod;
              }
          } catch (Throwable th) {
              Method method3 = null;
          }
          this._preHandler = method;
          return method;
      }
  
      public void handleException(CoroutineContext context, Throwable exception) {
          int i = Build.VERSION.SDK_INT;
          if (26 <= i && i < 28) {
              Method preHandler = preHandler();
              Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null;
              Object invoke = preHandler == null ? null : preHandler.invoke((Object) null, new Object[0]);
              if (invoke instanceof Thread.UncaughtExceptionHandler) {
                  uncaughtExceptionHandler = (Thread.UncaughtExceptionHandler) invoke;
              }
              if (uncaughtExceptionHandler != null) {
                  uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), exception);
              }
          }
      }
  }
  