content: package androidx.loader.app;
  
  import android.os.Bundle;
  import android.os.Looper;
  import android.util.Log;
  import androidx.collection.SparseArrayCompat;
  import androidx.core.util.DebugUtils;
  import androidx.lifecycle.LifecycleOwner;
  import androidx.lifecycle.MutableLiveData;
  import androidx.lifecycle.Observer;
  import androidx.lifecycle.ViewModel;
  import androidx.lifecycle.ViewModelProvider;
  import androidx.lifecycle.ViewModelStore;
  import androidx.loader.app.LoaderManager;
  import androidx.loader.content.Loader;
  import java.io.FileDescriptor;
  import java.io.PrintWriter;
  import java.lang.reflect.Modifier;
  import mt.Log1F380D;
  
  /* compiled from: 0085 */
  class LoaderManagerImpl extends LoaderManager {
      static boolean DEBUG = false;
      static final String TAG = "LoaderManager";
      private final LifecycleOwner mLifecycleOwner;
      private final LoaderViewModel mLoaderViewModel;
  
      /* compiled from: 0084 */
      public static class LoaderInfo<D> extends MutableLiveData<D> implements Loader.OnLoadCompleteListener<D> {
          private final Bundle mArgs;
          private final int mId;
          private LifecycleOwner mLifecycleOwner;
          private final Loader<D> mLoader;
          private LoaderObserver<D> mObserver;
          private Loader<D> mPriorLoader;
  
          LoaderInfo(int id, Bundle args, Loader<D> loader, Loader<D> loader2) {
              this.mId = id;
              this.mArgs = args;
              this.mLoader = loader;
              this.mPriorLoader = loader2;
              loader.registerListener(id, this);
          }
  
          /* access modifiers changed from: package-private */
          public Loader<D> destroy(boolean reset) {
              if (LoaderManagerImpl.DEBUG) {
                  Log.v(LoaderManagerImpl.TAG, "  Destroying: " + this);
              }
              this.mLoader.cancelLoad();
              this.mLoader.abandon();
              LoaderObserver<D> loaderObserver = this.mObserver;
              if (loaderObserver != null) {
                  removeObserver(loaderObserver);
                  if (reset) {
                      loaderObserver.reset();
                  }
              }
              this.mLoader.unregisterListener(this);
              if ((loaderObserver == null || loaderObserver.hasDeliveredData()) && !reset) {
                  return this.mLoader;
              }
              this.mLoader.reset();
              return this.mPriorLoader;
          }
  
          public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
              writer.print(prefix);
              writer.print("mId=");
              writer.print(this.mId);
              writer.print(" mArgs=");
              writer.println(this.mArgs);
              writer.print(prefix);
              writer.print("mLoader=");
              writer.println(this.mLoader);
              this.mLoader.dump(prefix + "  ", fd, writer, args);
              if (this.mObserver != null) {
                  writer.print(prefix);
                  writer.print("mCallbacks=");
                  writer.println(this.mObserver);
                  this.mObserver.dump(prefix + "  ", writer);
              }
              writer.print(prefix);
              writer.print("mData=");
              writer.println(getLoader().dataToString(getValue()));
              writer.print(prefix);
              writer.print("mStarted=");
              writer.println(hasActiveObservers());
          }
  
          /* access modifiers changed from: package-private */
          public Loader<D> getLoader() {
              return this.mLoader;
          }
  
          /* access modifiers changed from: package-private */
          /* JADX WARNING: Code restructure failed: missing block: B:3:0x0008, code lost:
              r0 = r2.mObserver;
           */
          /* Code decompiled incorrectly, please refer to instructions dump. */
          public boolean isCallbackWaitingForData() {
              /*
                  r2 = this;
                  boolean r0 = r2.hasActiveObservers()
                  r1 = 0
                  if (r0 != 0) goto L_0x0008
                  return r1
              L_0x0008:
                  androidx.loader.app.LoaderManagerImpl$LoaderObserver<D> r0 = r2.mObserver
                  if (r0 == 0) goto L_0x0013
                  boolean r0 = r0.hasDeliveredData()
                  if (r0 != 0) goto L_0x0013
                  r1 = 1
              L_0x0013:
                  return r1
              */
              throw new UnsupportedOperationException("Method not decompiled: androidx.loader.app.LoaderManagerImpl.LoaderInfo.isCallbackWaitingForData():boolean");
          }
  
          /* access modifiers changed from: package-private */
          public void markForRedelivery() {
              LifecycleOwner lifecycleOwner = this.mLifecycleOwner;
              LoaderObserver<D> loaderObserver = this.mObserver;
              if (lifecycleOwner != null && loaderObserver != null) {
                  super.removeObserver(loaderObserver);
                  observe(lifecycleOwner, loaderObserver);
              }
          }
  
          /* access modifiers changed from: protected */
          public void onActive() {
              if (LoaderManagerImpl.DEBUG) {
                  Log.v(LoaderManagerImpl.TAG, "  Starting: " + this);
              }
              this.mLoader.startLoading();
          }
  
          /* access modifiers changed from: protected */
          public void onInactive() {
              if (LoaderManagerImpl.DEBUG) {
                  Log.v(LoaderManagerImpl.TAG, "  Stopping: " + this);
              }
              this.mLoader.stopLoading();
          }
  
          public void onLoadComplete(Loader<D> loader, D d) {
              if (LoaderManagerImpl.DEBUG) {
                  Log.v(LoaderManagerImpl.TAG, "onLoadComplete: " + this);
              }
              if (Looper.myLooper() == Looper.getMainLooper()) {
                  setValue(d);
                  return;
              }
              if (LoaderManagerImpl.DEBUG) {
                  Log.w(LoaderManagerImpl.TAG, "onLoadComplete was incorrectly called on a background thread");
              }
              postValue(d);
          }
  
          public void removeObserver(Observer<? super D> observer) {
              super.removeObserver(observer);
              this.mLifecycleOwner = null;
              this.mObserver = null;
          }
  
          /* access modifiers changed from: package-private */
          public Loader<D> setCallback(LifecycleOwner owner, LoaderManager.LoaderCallbacks<D> loaderCallbacks) {
              LoaderObserver<D> loaderObserver = new LoaderObserver<>(this.mLoader, loaderCallbacks);
              observe(owner, loaderObserver);
              LoaderObserver<D> loaderObserver2 = this.mObserver;
              if (loaderObserver2 != null) {
                  removeObserver(loaderObserver2);
              }
              this.mLifecycleOwner = owner;
              this.mObserver = loaderObserver;
              return this.mLoader;
          }
  
          public void setValue(D d) {
              super.setValue(d);
              Loader<D> loader = this.mPriorLoader;
              if (loader != null) {
                  loader.reset();
                  this.mPriorLoader = null;
              }
          }
  
          public String toString() {
              StringBuilder sb = new StringBuilder(64);
              sb.append("LoaderInfo{");
              String hexString = Integer.toHexString(System.identityHashCode(this));
              Log1F380D.a((Object) hexString);
              sb.append(hexString);
              sb.append(" #");
              sb.append(this.mId);
              sb.append(" : ");
              DebugUtils.buildShortClassTag(this.mLoader, sb);
              sb.append("}}");
              return sb.toString();
          }
      }
  
      static class LoaderObserver<D> implements Observer<D> {
          private final LoaderManager.LoaderCallbacks<D> mCallback;
          private boolean mDeliveredData = false;
          private final Loader<D> mLoader;
  
          LoaderObserver(Loader<D> loader, LoaderManager.LoaderCallbacks<D> loaderCallbacks) {
              this.mLoader = loader;
              this.mCallback = loaderCallbacks;
          }
  
          public void dump(String prefix, PrintWriter writer) {
              writer.print(prefix);
              writer.print("mDeliveredData=");
              writer.println(this.mDeliveredData);
          }
  
          /* access modifiers changed from: package-private */
          public boolean hasDeliveredData() {
              return this.mDeliveredData;
          }
  
          public void onChanged(D d) {
              if (LoaderManagerImpl.DEBUG) {
                  Log.v(LoaderManagerImpl.TAG, "  onLoadFinished in " + this.mLoader + ": " + this.mLoader.dataToString(d));
              }
              this.mCallback.onLoadFinished(this.mLoader, d);
              this.mDeliveredData = true;
          }
  
          /* access modifiers changed from: package-private */
          public void reset() {
              if (this.mDeliveredData) {
                  if (LoaderManagerImpl.DEBUG) {
                      Log.v(LoaderManagerImpl.TAG, "  Resetting: " + this.mLoader);
                  }
                  this.mCallback.onLoaderReset(this.mLoader);
              }
          }
  
          public String toString() {
              return this.mCallback.toString();
          }
      }
  
      static class LoaderViewModel extends ViewModel {
          private static final ViewModelProvider.Factory FACTORY = new ViewModelProvider.Factory() {
              public <T extends ViewModel> T create(Class<T> cls) {
                  return new LoaderViewModel();
              }
          };
          private boolean mCreatingLoader = false;
          private SparseArrayCompat<LoaderInfo> mLoaders = new SparseArrayCompat<>();
  
          LoaderViewModel() {
          }
  
          static LoaderViewModel getInstance(ViewModelStore viewModelStore) {
              return (LoaderViewModel) new ViewModelProvider(viewModelStore, FACTORY).get(LoaderViewModel.class);
          }
  
          public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
              if (this.mLoaders.size() > 0) {
                  writer.print(prefix);
                  writer.println("Loaders:");
                  String str = prefix + "    ";
                  for (int i = 0; i < this.mLoaders.size(); i++) {
                      LoaderInfo valueAt = this.mLoaders.valueAt(i);
                      writer.print(prefix);
                      writer.print("  #");
                      writer.print(this.mLoaders.keyAt(i));
                      writer.print(": ");
                      writer.println(valueAt.toString());
                      valueAt.dump(str, fd, writer, args);
                  }
              }
          }
  
          /* access modifiers changed from: package-private */
          public void finishCreatingLoader() {
              this.mCreatingLoader = false;
          }
  
          /* access modifiers changed from: package-private */
          public <D> LoaderInfo<D> getLoader(int id) {
              return this.mLoaders.get(id);
          }
  
          /* access modifiers changed from: package-private */
          public boolean hasRunningLoaders() {
              int size = this.mLoaders.size();
              for (int i = 0; i < size; i++) {
                  if (this.mLoaders.valueAt(i).isCallbackWaitingForData()) {
                      return true;
                  }
              }
              return false;
          }
  
          /* access modifiers changed from: package-private */
          public boolean isCreatingLoader() {
              return this.mCreatingLoader;
          }
  
          /* access modifiers changed from: package-private */
          public void markForRedelivery() {
              int size = this.mLoaders.size();
              for (int i = 0; i < size; i++) {
                  this.mLoaders.valueAt(i).markForRedelivery();
              }
          }
  
          /* access modifiers changed from: protected */
          public void onCleared() {
              super.onCleared();
              int size = this.mLoaders.size();
              for (int i = 0; i < size; i++) {
                  this.mLoaders.valueAt(i).destroy(true);
              }
              this.mLoaders.clear();
          }
  
          /* access modifiers changed from: package-private */
          public void putLoader(int id, LoaderInfo info) {
              this.mLoaders.put(id, info);
          }
  
          /* access modifiers changed from: package-private */
          public void removeLoader(int id) {
              this.mLoaders.remove(id);
          }
  
          /* access modifiers changed from: package-private */
          public void startCreatingLoader() {
              this.mCreatingLoader = true;
          }
      }
  
      LoaderManagerImpl(LifecycleOwner lifecycleOwner, ViewModelStore viewModelStore) {
          this.mLifecycleOwner = lifecycleOwner;
          this.mLoaderViewModel = LoaderViewModel.getInstance(viewModelStore);
      }
  
      private <D> Loader<D> createAndInstallLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> loaderCallbacks, Loader<D> loader) {
          try {
              this.mLoaderViewModel.startCreatingLoader();
              Loader<D> onCreateLoader = loaderCallbacks.onCreateLoader(id, args);
              if (onCreateLoader != null) {
                  if (onCreateLoader.getClass().isMemberClass()) {
                      if (!Modifier.isStatic(onCreateLoader.getClass().getModifiers())) {
                          throw new IllegalArgumentException("Object returned from onCreateLoader must not be a non-static inner member class: " + onCreateLoader);
                      }
                  }
                  LoaderInfo loaderInfo = new LoaderInfo(id, args, onCreateLoader, loader);
                  try {
                      if (DEBUG) {
                          Log.v(TAG, "  Created new loader " + loaderInfo);
                      }
                      this.mLoaderViewModel.putLoader(id, loaderInfo);
                      this.mLoaderViewModel.finishCreatingLoader();
                      return loaderInfo.setCallback(this.mLifecycleOwner, loaderCallbacks);
                  } catch (Throwable th) {
                      th = th;
                      this.mLoaderViewModel.finishCreatingLoader();
                      throw th;
                  }
              } else {
                  throw new IllegalArgumentException("Object returned from onCreateLoader must not be null");
              }
          } catch (Throwable th2) {
              th = th2;
              this.mLoaderViewModel.finishCreatingLoader();
              throw th;
          }
      }
  
      public void destroyLoader(int id) {
          if (this.mLoaderViewModel.isCreatingLoader()) {
              throw new IllegalStateException("Called while creating a loader");
          } else if (Looper.getMainLooper() == Looper.myLooper()) {
              if (DEBUG) {
                  Log.v(TAG, "destroyLoader in " + this + " of " + id);
              }
              LoaderInfo loader = this.mLoaderViewModel.getLoader(id);
              if (loader != null) {
                  loader.destroy(true);
                  this.mLoaderViewModel.removeLoader(id);
              }
          } else {
              throw new IllegalStateException("destroyLoader must be called on the main thread");
          }
      }
  
      @Deprecated
      public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
          this.mLoaderViewModel.dump(prefix, fd, writer, args);
      }
  
      public <D> Loader<D> getLoader(int id) {
          if (!this.mLoaderViewModel.isCreatingLoader()) {
              LoaderInfo loader = this.mLoaderViewModel.getLoader(id);
              if (loader != null) {
                  return loader.getLoader();
              }
              return null;
          }
          throw new IllegalStateException("Called while creating a loader");
      }
  
      public boolean hasRunningLoaders() {
          return this.mLoaderViewModel.hasRunningLoaders();
      }
  
      public <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> loaderCallbacks) {
          if (this.mLoaderViewModel.isCreatingLoader()) {
              throw new IllegalStateException("Called while creating a loader");
          } else if (Looper.getMainLooper() == Looper.myLooper()) {
              LoaderInfo loader = this.mLoaderViewModel.getLoader(id);
              if (DEBUG) {
                  Log.v(TAG, "initLoader in " + this + ": args=" + args);
              }
              if (loader == null) {
                  return createAndInstallLoader(id, args, loaderCallbacks, (Loader) null);
              }
              if (DEBUG) {
                  Log.v(TAG, "  Re-using existing loader " + loader);
              }
              return loader.setCallback(this.mLifecycleOwner, loaderCallbacks);
          } else {
              throw new IllegalStateException("initLoader must be called on the main thread");
          }
      }
  
      public void markForRedelivery() {
          this.mLoaderViewModel.markForRedelivery();
      }
  
      public <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> loaderCallbacks) {
          if (this.mLoaderViewModel.isCreatingLoader()) {
              throw new IllegalStateException("Called while creating a loader");
          } else if (Looper.getMainLooper() == Looper.myLooper()) {
              if (DEBUG) {
                  Log.v(TAG, "restartLoader in " + this + ": args=" + args);
              }
              LoaderInfo loader = this.mLoaderViewModel.getLoader(id);
              Loader loader2 = null;
              if (loader != null) {
                  loader2 = loader.destroy(false);
              }
              return createAndInstallLoader(id, args, loaderCallbacks, loader2);
          } else {
              throw new IllegalStateException("restartLoader must be called on the main thread");
          }
      }
  
      public String toString() {
          StringBuilder sb = new StringBuilder(128);
          sb.append("LoaderManager{");
          String hexString = Integer.toHexString(System.identityHashCode(this));
          Log1F380D.a((Object) hexString);
          sb.append(hexString);
          sb.append(" in ");
          DebugUtils.buildShortClassTag(this.mLifecycleOwner, sb);
          sb.append("}}");
          return sb.toString();
      }
  }
  