content: package androidx.loader.content;
  
  import android.content.Context;
  import android.os.Handler;
  import android.os.SystemClock;
  import androidx.core.os.OperationCanceledException;
  import androidx.core.util.TimeUtils;
  import java.io.FileDescriptor;
  import java.io.PrintWriter;
  import java.util.concurrent.CountDownLatch;
  import java.util.concurrent.Executor;
  
  public abstract class AsyncTaskLoader<D> extends Loader<D> {
      static final boolean DEBUG = false;
      static final String TAG = "AsyncTaskLoader";
      volatile AsyncTaskLoader<D>.LoadTask mCancellingTask;
      private final Executor mExecutor;
      Handler mHandler;
      long mLastLoadCompleteTime;
      volatile AsyncTaskLoader<D>.LoadTask mTask;
      long mUpdateThrottle;
  
      final class LoadTask extends ModernAsyncTask<Void, Void, D> implements Runnable {
          private final CountDownLatch mDone = new CountDownLatch(1);
          boolean waiting;
  
          LoadTask() {
          }
  
          /* access modifiers changed from: protected */
          public D doInBackground(Void... params) {
              try {
                  return AsyncTaskLoader.this.onLoadInBackground();
              } catch (OperationCanceledException e) {
                  if (isCancelled()) {
                      return null;
                  }
                  throw e;
              }
          }
  
          /* access modifiers changed from: protected */
          public void onCancelled(D d) {
              try {
                  AsyncTaskLoader.this.dispatchOnCancelled(this, d);
              } finally {
                  this.mDone.countDown();
              }
          }
  
          /* access modifiers changed from: protected */
          public void onPostExecute(D d) {
              try {
                  AsyncTaskLoader.this.dispatchOnLoadComplete(this, d);
              } finally {
                  this.mDone.countDown();
              }
          }
  
          public void run() {
              this.waiting = false;
              AsyncTaskLoader.this.executePendingTask();
          }
  
          public void waitForLoader() {
              try {
                  this.mDone.await();
              } catch (InterruptedException e) {
              }
          }
      }
  
      public AsyncTaskLoader(Context context) {
          this(context, ModernAsyncTask.THREAD_POOL_EXECUTOR);
      }
  
      private AsyncTaskLoader(Context context, Executor executor) {
          super(context);
          this.mLastLoadCompleteTime = -10000;
          this.mExecutor = executor;
      }
  
      public void cancelLoadInBackground() {
      }
  
      /* access modifiers changed from: package-private */
      public void dispatchOnCancelled(AsyncTaskLoader<D>.LoadTask loadTask, D d) {
          onCanceled(d);
          if (this.mCancellingTask == loadTask) {
              rollbackContentChanged();
              this.mLastLoadCompleteTime = SystemClock.uptimeMillis();
              this.mCancellingTask = null;
              deliverCancellation();
              executePendingTask();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void dispatchOnLoadComplete(AsyncTaskLoader<D>.LoadTask loadTask, D d) {
          if (this.mTask != loadTask) {
              dispatchOnCancelled(loadTask, d);
          } else if (isAbandoned()) {
              onCanceled(d);
          } else {
              commitContentChanged();
              this.mLastLoadCompleteTime = SystemClock.uptimeMillis();
              this.mTask = null;
              deliverResult(d);
          }
      }
  
      @Deprecated
      public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
          super.dump(prefix, fd, writer, args);
          if (this.mTask != null) {
              writer.print(prefix);
              writer.print("mTask=");
              writer.print(this.mTask);
              writer.print(" waiting=");
              writer.println(this.mTask.waiting);
          }
          if (this.mCancellingTask != null) {
              writer.print(prefix);
              writer.print("mCancellingTask=");
              writer.print(this.mCancellingTask);
              writer.print(" waiting=");
              writer.println(this.mCancellingTask.waiting);
          }
          if (this.mUpdateThrottle != 0) {
              writer.print(prefix);
              writer.print("mUpdateThrottle=");
              TimeUtils.formatDuration(this.mUpdateThrottle, writer);
              writer.print(" mLastLoadCompleteTime=");
              TimeUtils.formatDuration(this.mLastLoadCompleteTime, SystemClock.uptimeMillis(), writer);
              writer.println();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void executePendingTask() {
          if (this.mCancellingTask == null && this.mTask != null) {
              if (this.mTask.waiting) {
                  this.mTask.waiting = false;
                  this.mHandler.removeCallbacks(this.mTask);
              }
              if (this.mUpdateThrottle <= 0 || SystemClock.uptimeMillis() >= this.mLastLoadCompleteTime + this.mUpdateThrottle) {
                  Void[] voidArr = null;
                  this.mTask.executeOnExecutor(this.mExecutor, (Params[]) null);
                  return;
              }
              this.mTask.waiting = true;
              this.mHandler.postAtTime(this.mTask, this.mLastLoadCompleteTime + this.mUpdateThrottle);
          }
      }
  
      public boolean isLoadInBackgroundCanceled() {
          return this.mCancellingTask != null;
      }
  
      public abstract D loadInBackground();
  
      /* access modifiers changed from: protected */
      public boolean onCancelLoad() {
          if (this.mTask == null) {
              return false;
          }
          if (!this.mStarted) {
              this.mContentChanged = true;
          }
          if (this.mCancellingTask != null) {
              if (this.mTask.waiting) {
                  this.mTask.waiting = false;
                  this.mHandler.removeCallbacks(this.mTask);
              }
              this.mTask = null;
              return false;
          } else if (this.mTask.waiting) {
              this.mTask.waiting = false;
              this.mHandler.removeCallbacks(this.mTask);
              this.mTask = null;
              return false;
          } else {
              boolean cancel = this.mTask.cancel(false);
              if (cancel) {
                  this.mCancellingTask = this.mTask;
                  cancelLoadInBackground();
              }
              this.mTask = null;
              return cancel;
          }
      }
  
      public void onCanceled(D d) {
      }
  
      /* access modifiers changed from: protected */
      public void onForceLoad() {
          super.onForceLoad();
          cancelLoad();
          this.mTask = new LoadTask();
          executePendingTask();
      }
  
      /* access modifiers changed from: protected */
      public D onLoadInBackground() {
          return loadInBackground();
      }
  
      public void setUpdateThrottle(long delayMS) {
          this.mUpdateThrottle = delayMS;
          if (delayMS != 0) {
              this.mHandler = new Handler();
          }
      }
  
      public void waitForLoader() {
          AsyncTaskLoader<D>.LoadTask loadTask = this.mTask;
          if (loadTask != null) {
              loadTask.waitForLoader();
          }
      }
  }
  