content: package androidx.loader.content;
  
  import android.os.Binder;
  import android.os.Handler;
  import android.os.Looper;
  import android.os.Message;
  import android.os.Process;
  import android.util.Log;
  import java.util.concurrent.BlockingQueue;
  import java.util.concurrent.Callable;
  import java.util.concurrent.CancellationException;
  import java.util.concurrent.ExecutionException;
  import java.util.concurrent.Executor;
  import java.util.concurrent.FutureTask;
  import java.util.concurrent.LinkedBlockingQueue;
  import java.util.concurrent.ThreadFactory;
  import java.util.concurrent.ThreadPoolExecutor;
  import java.util.concurrent.TimeUnit;
  import java.util.concurrent.TimeoutException;
  import java.util.concurrent.atomic.AtomicBoolean;
  import java.util.concurrent.atomic.AtomicInteger;
  
  abstract class ModernAsyncTask<Params, Progress, Result> {
      private static final int CORE_POOL_SIZE = 5;
      private static final int KEEP_ALIVE = 1;
      private static final String LOG_TAG = "AsyncTask";
      private static final int MAXIMUM_POOL_SIZE = 128;
      private static final int MESSAGE_POST_PROGRESS = 2;
      private static final int MESSAGE_POST_RESULT = 1;
      public static final Executor THREAD_POOL_EXECUTOR;
      private static volatile Executor sDefaultExecutor;
      private static InternalHandler sHandler;
      private static final BlockingQueue<Runnable> sPoolWorkQueue;
      private static final ThreadFactory sThreadFactory;
      final AtomicBoolean mCancelled = new AtomicBoolean();
      private final FutureTask<Result> mFuture;
      private volatile Status mStatus = Status.PENDING;
      final AtomicBoolean mTaskInvoked = new AtomicBoolean();
      private final WorkerRunnable<Params, Result> mWorker;
  
      /* renamed from: androidx.loader.content.ModernAsyncTask$4  reason: invalid class name */
      static /* synthetic */ class AnonymousClass4 {
          static final /* synthetic */ int[] $SwitchMap$androidx$loader$content$ModernAsyncTask$Status;
  
          static {
              int[] iArr = new int[Status.values().length];
              $SwitchMap$androidx$loader$content$ModernAsyncTask$Status = iArr;
              try {
                  iArr[Status.RUNNING.ordinal()] = 1;
              } catch (NoSuchFieldError e) {
              }
              try {
                  $SwitchMap$androidx$loader$content$ModernAsyncTask$Status[Status.FINISHED.ordinal()] = 2;
              } catch (NoSuchFieldError e2) {
              }
          }
      }
  
      private static class AsyncTaskResult<Data> {
          final Data[] mData;
          final ModernAsyncTask mTask;
  
          AsyncTaskResult(ModernAsyncTask task, Data... dataArr) {
              this.mTask = task;
              this.mData = dataArr;
          }
      }
  
      private static class InternalHandler extends Handler {
          InternalHandler() {
              super(Looper.getMainLooper());
          }
  
          public void handleMessage(Message msg) {
              AsyncTaskResult asyncTaskResult = (AsyncTaskResult) msg.obj;
              switch (msg.what) {
                  case 1:
                      asyncTaskResult.mTask.finish(asyncTaskResult.mData[0]);
                      return;
                  case 2:
                      asyncTaskResult.mTask.onProgressUpdate(asyncTaskResult.mData);
                      return;
                  default:
                      return;
              }
          }
      }
  
      public enum Status {
          PENDING,
          RUNNING,
          FINISHED
      }
  
      private static abstract class WorkerRunnable<Params, Result> implements Callable<Result> {
          Params[] mParams;
  
          WorkerRunnable() {
          }
      }
  
      static {
          AnonymousClass1 r7 = new ThreadFactory() {
              private final AtomicInteger mCount = new AtomicInteger(1);
  
              public Thread newThread(Runnable r) {
                  return new Thread(r, "ModernAsyncTask #" + this.mCount.getAndIncrement());
              }
          };
          sThreadFactory = r7;
          LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue(10);
          sPoolWorkQueue = linkedBlockingQueue;
          ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 128, 1, TimeUnit.SECONDS, linkedBlockingQueue, r7);
          THREAD_POOL_EXECUTOR = threadPoolExecutor;
          sDefaultExecutor = threadPoolExecutor;
      }
  
      ModernAsyncTask() {
          AnonymousClass2 r0 = new WorkerRunnable<Params, Result>() {
              public Result call() throws Exception {
                  ModernAsyncTask.this.mTaskInvoked.set(true);
                  Result result = null;
                  try {
                      Process.setThreadPriority(10);
                      result = ModernAsyncTask.this.doInBackground(this.mParams);
                      Binder.flushPendingCommands();
                      ModernAsyncTask.this.postResult(result);
                      return result;
                  } catch (Throwable th) {
                      ModernAsyncTask.this.postResult(result);
                      throw th;
                  }
              }
          };
          this.mWorker = r0;
          this.mFuture = new FutureTask<Result>(r0) {
              /* access modifiers changed from: protected */
              public void done() {
                  try {
                      ModernAsyncTask.this.postResultIfNotInvoked(get());
                  } catch (InterruptedException e) {
                      Log.w(ModernAsyncTask.LOG_TAG, e);
                  } catch (ExecutionException e2) {
                      throw new RuntimeException("An error occurred while executing doInBackground()", e2.getCause());
                  } catch (CancellationException e3) {
                      ModernAsyncTask.this.postResultIfNotInvoked(null);
                  } catch (Throwable th) {
                      throw new RuntimeException("An error occurred while executing doInBackground()", th);
                  }
              }
          };
      }
  
      public static void execute(Runnable runnable) {
          sDefaultExecutor.execute(runnable);
      }
  
      private static Handler getHandler() {
          InternalHandler internalHandler;
          synchronized (ModernAsyncTask.class) {
              if (sHandler == null) {
                  sHandler = new InternalHandler();
              }
              internalHandler = sHandler;
          }
          return internalHandler;
      }
  
      public static void setDefaultExecutor(Executor exec) {
          sDefaultExecutor = exec;
      }
  
      public final boolean cancel(boolean mayInterruptIfRunning) {
          this.mCancelled.set(true);
          return this.mFuture.cancel(mayInterruptIfRunning);
      }
  
      /* access modifiers changed from: protected */
      public abstract Result doInBackground(Params... paramsArr);
  
      public final ModernAsyncTask<Params, Progress, Result> execute(Params... paramsArr) {
          return executeOnExecutor(sDefaultExecutor, paramsArr);
      }
  
      public final ModernAsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec, Params... paramsArr) {
          if (this.mStatus != Status.PENDING) {
              switch (AnonymousClass4.$SwitchMap$androidx$loader$content$ModernAsyncTask$Status[this.mStatus.ordinal()]) {
                  case 1:
                      throw new IllegalStateException("Cannot execute task: the task is already running.");
                  case 2:
                      throw new IllegalStateException("Cannot execute task: the task has already been executed (a task can be executed only once)");
                  default:
                      throw new IllegalStateException("We should never reach this state");
              }
          } else {
              this.mStatus = Status.RUNNING;
              onPreExecute();
              this.mWorker.mParams = paramsArr;
              exec.execute(this.mFuture);
              return this;
          }
      }
  
      /* access modifiers changed from: package-private */
      public void finish(Result result) {
          if (isCancelled()) {
              onCancelled(result);
          } else {
              onPostExecute(result);
          }
          this.mStatus = Status.FINISHED;
      }
  
      public final Result get() throws InterruptedException, ExecutionException {
          return this.mFuture.get();
      }
  
      public final Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
          return this.mFuture.get(timeout, unit);
      }
  
      public final Status getStatus() {
          return this.mStatus;
      }
  
      public final boolean isCancelled() {
          return this.mCancelled.get();
      }
  
      /* access modifiers changed from: protected */
      public void onCancelled() {
      }
  
      /* access modifiers changed from: protected */
      public void onCancelled(Result result) {
          onCancelled();
      }
  
      /* access modifiers changed from: protected */
      public void onPostExecute(Result result) {
      }
  
      /* access modifiers changed from: protected */
      public void onPreExecute() {
      }
  
      /* access modifiers changed from: protected */
      public void onProgressUpdate(Progress... progressArr) {
      }
  
      /* access modifiers changed from: package-private */
      public Result postResult(Result result) {
          getHandler().obtainMessage(1, new AsyncTaskResult(this, result)).sendToTarget();
          return result;
      }
  
      /* access modifiers changed from: package-private */
      public void postResultIfNotInvoked(Result result) {
          if (!this.mTaskInvoked.get()) {
              postResult(result);
          }
      }
  
      /* access modifiers changed from: protected */
      public final void publishProgress(Progress... progressArr) {
          if (!isCancelled()) {
              getHandler().obtainMessage(2, new AsyncTaskResult(this, progressArr)).sendToTarget();
          }
      }
  }
  