content: package kotlinx.coroutines.android;
  
  import android.os.Build;
  import android.os.Handler;
  import android.os.Looper;
  import android.view.Choreographer;
  import kotlin.Deprecated;
  import kotlin.DeprecationLevel;
  import kotlin.Metadata;
  import kotlin.Result;
  import kotlin.ResultKt;
  import kotlin.coroutines.Continuation;
  import kotlin.coroutines.EmptyCoroutineContext;
  import kotlin.coroutines.intrinsics.IntrinsicsKt;
  import kotlin.coroutines.jvm.internal.DebugProbesKt;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  import kotlinx.coroutines.CancellableContinuation;
  import kotlinx.coroutines.CancellableContinuationImpl;
  import kotlinx.coroutines.Dispatchers;
  
  @Metadata(d1 = {"\u0000@\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\u001a\u0011\u0010\b\u001a\u00020\u0001H@ø\u0001\u0000¢\u0006\u0002\u0010\t\u001a\u001e\u0010\n\u001a\u00020\u000b2\u0006\u0010\u0006\u001a\u00020\u00072\f\u0010\f\u001a\b\u0012\u0004\u0012\u00020\u00010\rH\u0002\u001a\u0016\u0010\u000e\u001a\u00020\u000b2\f\u0010\f\u001a\b\u0012\u0004\u0012\u00020\u00010\rH\u0002\u001a\u001d\u0010\u000f\u001a\u00020\u0003*\u00020\u00102\n\b\u0002\u0010\u0011\u001a\u0004\u0018\u00010\u0012H\u0007¢\u0006\u0002\b\u0013\u001a\u0014\u0010\u0014\u001a\u00020\u0010*\u00020\u00152\u0006\u0010\u0016\u001a\u00020\u0017H\u0001\"\u000e\u0010\u0000\u001a\u00020\u0001XT¢\u0006\u0002\n\u0000\"\u0018\u0010\u0002\u001a\u0004\u0018\u00010\u00038\u0000X\u0004¢\u0006\b\n\u0000\u0012\u0004\b\u0004\u0010\u0005\"\u0010\u0010\u0006\u001a\u0004\u0018\u00010\u0007X\u000e¢\u0006\u0002\n\u0000\u0002\u0004\n\u0002\b\u0019¨\u0006\u0018"}, d2 = {"MAX_DELAY", "", "Main", "Lkotlinx/coroutines/android/HandlerDispatcher;", "getMain$annotations", "()V", "choreographer", "Landroid/view/Choreographer;", "awaitFrame", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "postFrameCallback", "", "cont", "Lkotlinx/coroutines/CancellableContinuation;", "updateChoreographerAndPostFrameCallback", "asCoroutineDispatcher", "Landroid/os/Handler;", "name", "", "from", "asHandler", "Landroid/os/Looper;", "async", "", "kotlinx-coroutines-android"}, k = 2, mv = {1, 6, 0}, xi = 48)
  /* compiled from: HandlerDispatcher.kt */
  public final class HandlerDispatcherKt {
      private static final long MAX_DELAY = 4611686018427387903L;
      public static final HandlerDispatcher Main;
      private static volatile Choreographer choreographer;
  
      static {
          Object obj;
          HandlerDispatcher handlerDispatcher = null;
          try {
              Result.Companion companion = Result.Companion;
              obj = Result.m36constructorimpl(new HandlerContext(asHandler(Looper.getMainLooper(), true), (String) null, 2, (DefaultConstructorMarker) null));
          } catch (Throwable th) {
              Result.Companion companion2 = Result.Companion;
              obj = Result.m36constructorimpl(ResultKt.createFailure(th));
          }
          if (!Result.m42isFailureimpl(obj)) {
              handlerDispatcher = obj;
          }
          Main = handlerDispatcher;
      }
  
      public static final Handler asHandler(Looper $this$asHandler, boolean async) {
          if (!async || Build.VERSION.SDK_INT < 16) {
              return new Handler($this$asHandler);
          }
          if (Build.VERSION.SDK_INT >= 28) {
              Object invoke = Handler.class.getDeclaredMethod("createAsync", new Class[]{Looper.class}).invoke((Object) null, new Object[]{$this$asHandler});
              if (invoke != null) {
                  return (Handler) invoke;
              }
              throw new NullPointerException("null cannot be cast to non-null type android.os.Handler");
          }
          try {
              return Handler.class.getDeclaredConstructor(new Class[]{Looper.class, Handler.Callback.class, Boolean.TYPE}).newInstance(new Object[]{$this$asHandler, null, true});
          } catch (NoSuchMethodException e) {
              return new Handler($this$asHandler);
          }
      }
  
      public static final Object awaitFrame(Continuation<? super Long> $completion) {
          Choreographer choreographer2 = choreographer;
          if (choreographer2 != null) {
              CancellableContinuationImpl cancellableContinuationImpl = new CancellableContinuationImpl(IntrinsicsKt.intercepted($completion), 1);
              cancellableContinuationImpl.initCancellability();
              postFrameCallback(choreographer2, cancellableContinuationImpl);
              Object result = cancellableContinuationImpl.getResult();
              if (result == IntrinsicsKt.getCOROUTINE_SUSPENDED()) {
                  DebugProbesKt.probeCoroutineSuspended($completion);
              }
              return result;
          }
          CancellableContinuationImpl cancellableContinuationImpl2 = new CancellableContinuationImpl(IntrinsicsKt.intercepted($completion), 1);
          cancellableContinuationImpl2.initCancellability();
          Dispatchers.getMain().dispatch(EmptyCoroutineContext.INSTANCE, new HandlerDispatcherKt$awaitFrame$lambda3$$inlined$Runnable$1(cancellableContinuationImpl2));
          Object result2 = cancellableContinuationImpl2.getResult();
          if (result2 == IntrinsicsKt.getCOROUTINE_SUSPENDED()) {
              DebugProbesKt.probeCoroutineSuspended($completion);
          }
          return result2;
      }
  
      public static final HandlerDispatcher from(Handler handler) {
          return from$default(handler, (String) null, 1, (Object) null);
      }
  
      public static final HandlerDispatcher from(Handler $this$asCoroutineDispatcher, String name) {
          return new HandlerContext($this$asCoroutineDispatcher, name);
      }
  
      public static /* synthetic */ HandlerDispatcher from$default(Handler handler, String str, int i, Object obj) {
          if ((i & 1) != 0) {
              str = null;
          }
          return from(handler, str);
      }
  
      @Deprecated(level = DeprecationLevel.HIDDEN, message = "Use Dispatchers.Main instead")
      public static /* synthetic */ void getMain$annotations() {
      }
  
      /* access modifiers changed from: private */
      public static final void postFrameCallback(Choreographer choreographer2, CancellableContinuation<? super Long> cont) {
          choreographer2.postFrameCallback(new HandlerDispatcherKt$$ExternalSyntheticLambda0(cont));
      }
  
      /* access modifiers changed from: private */
      /* renamed from: postFrameCallback$lambda-6  reason: not valid java name */
      public static final void m1521postFrameCallback$lambda6(CancellableContinuation $cont, long nanos) {
          $cont.resumeUndispatched(Dispatchers.getMain(), Long.valueOf(nanos));
      }
  
      /* access modifiers changed from: private */
      public static final void updateChoreographerAndPostFrameCallback(CancellableContinuation<? super Long> cont) {
          Choreographer choreographer2 = choreographer;
          if (choreographer2 == null) {
              choreographer2 = Choreographer.getInstance();
              Intrinsics.checkNotNull(choreographer2);
              choreographer = choreographer2;
          }
          postFrameCallback(choreographer2, cont);
      }
  }
  