content: package androidx.fragment.app;
  
  import android.util.Log;
  import androidx.lifecycle.ViewModel;
  import androidx.lifecycle.ViewModelProvider;
  import androidx.lifecycle.ViewModelStore;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import mt.Log1F380D;
  
  /* compiled from: 0079 */
  final class FragmentManagerViewModel extends ViewModel {
      private static final ViewModelProvider.Factory FACTORY = new ViewModelProvider.Factory() {
          public <T extends ViewModel> T create(Class<T> cls) {
              return new FragmentManagerViewModel(true);
          }
      };
      private static final String TAG = "FragmentManager";
      private final HashMap<String, FragmentManagerViewModel> mChildNonConfigs = new HashMap<>();
      private boolean mHasBeenCleared = false;
      private boolean mHasSavedSnapshot = false;
      private boolean mIsStateSaved = false;
      private final HashMap<String, Fragment> mRetainedFragments = new HashMap<>();
      private final boolean mStateAutomaticallySaved;
      private final HashMap<String, ViewModelStore> mViewModelStores = new HashMap<>();
  
      FragmentManagerViewModel(boolean stateAutomaticallySaved) {
          this.mStateAutomaticallySaved = stateAutomaticallySaved;
      }
  
      static FragmentManagerViewModel getInstance(ViewModelStore viewModelStore) {
          return (FragmentManagerViewModel) new ViewModelProvider(viewModelStore, FACTORY).get(FragmentManagerViewModel.class);
      }
  
      /* access modifiers changed from: package-private */
      public void addRetainedFragment(Fragment fragment) {
          if (this.mIsStateSaved) {
              if (FragmentManager.isLoggingEnabled(2)) {
                  Log.v(TAG, "Ignoring addRetainedFragment as the state is already saved");
              }
          } else if (!this.mRetainedFragments.containsKey(fragment.mWho)) {
              this.mRetainedFragments.put(fragment.mWho, fragment);
              if (FragmentManager.isLoggingEnabled(2)) {
                  Log.v(TAG, "Updating retained Fragments: Added " + fragment);
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void clearNonConfigState(Fragment f) {
          if (FragmentManager.isLoggingEnabled(3)) {
              Log.d(TAG, "Clearing non-config state for " + f);
          }
          FragmentManagerViewModel fragmentManagerViewModel = this.mChildNonConfigs.get(f.mWho);
          if (fragmentManagerViewModel != null) {
              fragmentManagerViewModel.onCleared();
              this.mChildNonConfigs.remove(f.mWho);
          }
          ViewModelStore viewModelStore = this.mViewModelStores.get(f.mWho);
          if (viewModelStore != null) {
              viewModelStore.clear();
              this.mViewModelStores.remove(f.mWho);
          }
      }
  
      public boolean equals(Object o) {
          if (this == o) {
              return true;
          }
          if (o == null || getClass() != o.getClass()) {
              return false;
          }
          FragmentManagerViewModel fragmentManagerViewModel = (FragmentManagerViewModel) o;
          return this.mRetainedFragments.equals(fragmentManagerViewModel.mRetainedFragments) && this.mChildNonConfigs.equals(fragmentManagerViewModel.mChildNonConfigs) && this.mViewModelStores.equals(fragmentManagerViewModel.mViewModelStores);
      }
  
      /* access modifiers changed from: package-private */
      public Fragment findRetainedFragmentByWho(String who) {
          return this.mRetainedFragments.get(who);
      }
  
      /* access modifiers changed from: package-private */
      public FragmentManagerViewModel getChildNonConfig(Fragment f) {
          FragmentManagerViewModel fragmentManagerViewModel = this.mChildNonConfigs.get(f.mWho);
          if (fragmentManagerViewModel != null) {
              return fragmentManagerViewModel;
          }
          FragmentManagerViewModel fragmentManagerViewModel2 = new FragmentManagerViewModel(this.mStateAutomaticallySaved);
          this.mChildNonConfigs.put(f.mWho, fragmentManagerViewModel2);
          return fragmentManagerViewModel2;
      }
  
      /* access modifiers changed from: package-private */
      public Collection<Fragment> getRetainedFragments() {
          return new ArrayList(this.mRetainedFragments.values());
      }
  
      /* access modifiers changed from: package-private */
      @Deprecated
      public FragmentManagerNonConfig getSnapshot() {
          if (this.mRetainedFragments.isEmpty() && this.mChildNonConfigs.isEmpty() && this.mViewModelStores.isEmpty()) {
              return null;
          }
          HashMap hashMap = new HashMap();
          for (Map.Entry next : this.mChildNonConfigs.entrySet()) {
              FragmentManagerNonConfig snapshot = ((FragmentManagerViewModel) next.getValue()).getSnapshot();
              if (snapshot != null) {
                  hashMap.put(next.getKey(), snapshot);
              }
          }
          this.mHasSavedSnapshot = true;
          if (!this.mRetainedFragments.isEmpty() || !hashMap.isEmpty() || !this.mViewModelStores.isEmpty()) {
              return new FragmentManagerNonConfig(new ArrayList(this.mRetainedFragments.values()), hashMap, new HashMap(this.mViewModelStores));
          }
          return null;
      }
  
      /* access modifiers changed from: package-private */
      public ViewModelStore getViewModelStore(Fragment f) {
          ViewModelStore viewModelStore = this.mViewModelStores.get(f.mWho);
          if (viewModelStore != null) {
              return viewModelStore;
          }
          ViewModelStore viewModelStore2 = new ViewModelStore();
          this.mViewModelStores.put(f.mWho, viewModelStore2);
          return viewModelStore2;
      }
  
      public int hashCode() {
          return (((this.mRetainedFragments.hashCode() * 31) + this.mChildNonConfigs.hashCode()) * 31) + this.mViewModelStores.hashCode();
      }
  
      /* access modifiers changed from: package-private */
      public boolean isCleared() {
          return this.mHasBeenCleared;
      }
  
      /* access modifiers changed from: protected */
      public void onCleared() {
          if (FragmentManager.isLoggingEnabled(3)) {
              Log.d(TAG, "onCleared called for " + this);
          }
          this.mHasBeenCleared = true;
      }
  
      /* access modifiers changed from: package-private */
      public void removeRetainedFragment(Fragment fragment) {
          if (!this.mIsStateSaved) {
              if ((this.mRetainedFragments.remove(fragment.mWho) != null) && FragmentManager.isLoggingEnabled(2)) {
                  Log.v(TAG, "Updating retained Fragments: Removed " + fragment);
              }
          } else if (FragmentManager.isLoggingEnabled(2)) {
              Log.v(TAG, "Ignoring removeRetainedFragment as the state is already saved");
          }
      }
  
      /* access modifiers changed from: package-private */
      @Deprecated
      public void restoreFromSnapshot(FragmentManagerNonConfig nonConfig) {
          this.mRetainedFragments.clear();
          this.mChildNonConfigs.clear();
          this.mViewModelStores.clear();
          if (nonConfig != null) {
              Collection<Fragment> fragments = nonConfig.getFragments();
              if (fragments != null) {
                  for (Fragment next : fragments) {
                      if (next != null) {
                          this.mRetainedFragments.put(next.mWho, next);
                      }
                  }
              }
              Map<String, FragmentManagerNonConfig> childNonConfigs = nonConfig.getChildNonConfigs();
              if (childNonConfigs != null) {
                  for (Map.Entry next2 : childNonConfigs.entrySet()) {
                      FragmentManagerViewModel fragmentManagerViewModel = new FragmentManagerViewModel(this.mStateAutomaticallySaved);
                      fragmentManagerViewModel.restoreFromSnapshot((FragmentManagerNonConfig) next2.getValue());
                      this.mChildNonConfigs.put(next2.getKey(), fragmentManagerViewModel);
                  }
              }
              Map<String, ViewModelStore> viewModelStores = nonConfig.getViewModelStores();
              if (viewModelStores != null) {
                  this.mViewModelStores.putAll(viewModelStores);
              }
          }
          this.mHasSavedSnapshot = false;
      }
  
      /* access modifiers changed from: package-private */
      public void setIsStateSaved(boolean isStateSaved) {
          this.mIsStateSaved = isStateSaved;
      }
  
      /* access modifiers changed from: package-private */
      public boolean shouldDestroy(Fragment fragment) {
          if (!this.mRetainedFragments.containsKey(fragment.mWho)) {
              return true;
          }
          return this.mStateAutomaticallySaved ? this.mHasBeenCleared : !this.mHasSavedSnapshot;
      }
  
      public String toString() {
          StringBuilder sb = new StringBuilder("FragmentManagerViewModel{");
          String hexString = Integer.toHexString(System.identityHashCode(this));
          Log1F380D.a((Object) hexString);
          sb.append(hexString);
          sb.append("} Fragments (");
          Iterator<Fragment> it = this.mRetainedFragments.values().iterator();
          while (it.hasNext()) {
              sb.append(it.next());
              if (it.hasNext()) {
                  sb.append(", ");
              }
          }
          sb.append(") Child Non Config (");
          Iterator<String> it2 = this.mChildNonConfigs.keySet().iterator();
          while (it2.hasNext()) {
              sb.append(it2.next());
              if (it2.hasNext()) {
                  sb.append(", ");
              }
          }
          sb.append(") ViewModelStores (");
          Iterator<String> it3 = this.mViewModelStores.keySet().iterator();
          while (it3.hasNext()) {
              sb.append(it3.next());
              if (it3.hasNext()) {
                  sb.append(", ");
              }
          }
          sb.append(')');
          return sb.toString();
      }
  }
  