content: package androidx.core.os;
  
  import android.os.Build;
  import android.os.Handler;
  import android.os.Looper;
  import android.os.Message;
  import android.util.Log;
  import java.lang.reflect.InvocationTargetException;
  
  public final class HandlerCompat {
      private static final String TAG = "HandlerCompat";
  
      private static class Api28Impl {
          private Api28Impl() {
          }
  
          public static Handler createAsync(Looper looper) {
              return Handler.createAsync(looper);
          }
  
          public static Handler createAsync(Looper looper, Handler.Callback callback) {
              return Handler.createAsync(looper, callback);
          }
  
          public static boolean postDelayed(Handler handler, Runnable r, Object token, long delayMillis) {
              return handler.postDelayed(r, token, delayMillis);
          }
      }
  
      private static class Api29Impl {
          private Api29Impl() {
          }
  
          public static boolean hasCallbacks(Handler handler, Runnable r) {
              return handler.hasCallbacks(r);
          }
      }
  
      private HandlerCompat() {
      }
  
      public static Handler createAsync(Looper looper) {
          if (Build.VERSION.SDK_INT >= 28) {
              return Api28Impl.createAsync(looper);
          }
          if (Build.VERSION.SDK_INT >= 17) {
              Class<Handler> cls = Handler.class;
              try {
                  return cls.getDeclaredConstructor(new Class[]{Looper.class, Handler.Callback.class, Boolean.TYPE}).newInstance(new Object[]{looper, null, true});
              } catch (IllegalAccessException | InstantiationException | NoSuchMethodException e) {
                  Log.w(TAG, "Unable to invoke Handler(Looper, Callback, boolean) constructor", e);
              } catch (InvocationTargetException e2) {
                  Throwable cause = e2.getCause();
                  if (cause instanceof RuntimeException) {
                      throw ((RuntimeException) cause);
                  } else if (cause instanceof Error) {
                      throw ((Error) cause);
                  } else {
                      throw new RuntimeException(cause);
                  }
              }
          }
          return new Handler(looper);
      }
  
      public static Handler createAsync(Looper looper, Handler.Callback callback) {
          if (Build.VERSION.SDK_INT >= 28) {
              return Api28Impl.createAsync(looper, callback);
          }
          if (Build.VERSION.SDK_INT >= 17) {
              Class<Handler> cls = Handler.class;
              try {
                  return cls.getDeclaredConstructor(new Class[]{Looper.class, Handler.Callback.class, Boolean.TYPE}).newInstance(new Object[]{looper, callback, true});
              } catch (IllegalAccessException | InstantiationException | NoSuchMethodException e) {
                  Log.w(TAG, "Unable to invoke Handler(Looper, Callback, boolean) constructor", e);
              } catch (InvocationTargetException e2) {
                  Throwable cause = e2.getCause();
                  if (cause instanceof RuntimeException) {
                      throw ((RuntimeException) cause);
                  } else if (cause instanceof Error) {
                      throw ((Error) cause);
                  } else {
                      throw new RuntimeException(cause);
                  }
              }
          }
          return new Handler(looper, callback);
      }
  
      public static boolean hasCallbacks(Handler handler, Runnable r) {
          NullPointerException nullPointerException = null;
          if (Build.VERSION.SDK_INT >= 29) {
              return Api29Impl.hasCallbacks(handler, r);
          }
          if (Build.VERSION.SDK_INT >= 16) {
              try {
                  return ((Boolean) Handler.class.getMethod("hasCallbacks", new Class[]{Runnable.class}).invoke(handler, new Object[]{r})).booleanValue();
              } catch (InvocationTargetException e) {
                  Throwable cause = e.getCause();
                  if (cause instanceof RuntimeException) {
                      throw ((RuntimeException) cause);
                  } else if (cause instanceof Error) {
                      throw ((Error) cause);
                  } else {
                      throw new RuntimeException(cause);
                  }
              } catch (IllegalAccessException e2) {
                  nullPointerException = e2;
              } catch (NoSuchMethodException e3) {
                  nullPointerException = e3;
              } catch (NullPointerException e4) {
                  nullPointerException = e4;
              }
          }
          throw new UnsupportedOperationException("Failed to call Handler.hasCallbacks(), but there is no safe failure mode for this method. Raising exception.", nullPointerException);
      }
  
      public static boolean postDelayed(Handler handler, Runnable r, Object token, long delayMillis) {
          if (Build.VERSION.SDK_INT >= 28) {
              return Api28Impl.postDelayed(handler, r, token, delayMillis);
          }
          Message obtain = Message.obtain(handler, r);
          obtain.obj = token;
          return handler.sendMessageDelayed(obtain, delayMillis);
      }
  }
  