content: package androidx.savedstate;
  
  import android.os.Bundle;
  import androidx.arch.core.internal.SafeIterableMap;
  import androidx.core.app.NotificationCompat;
  import androidx.lifecycle.Lifecycle;
  import androidx.lifecycle.LifecycleOwner;
  import androidx.savedstate.Recreator;
  import java.util.Iterator;
  import java.util.Map;
  import kotlin.Metadata;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  
  @Metadata(d1 = {"\u0000J\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u0000 )2\u00020\u0001:\u0003()*B\u0007\b\u0000¢\u0006\u0002\u0010\u0002J\u0012\u0010\u0014\u001a\u0004\u0018\u00010\u00132\u0006\u0010\u0015\u001a\u00020\u0007H\u0007J\u0010\u0010\u0016\u001a\u0004\u0018\u00010\b2\u0006\u0010\u0015\u001a\u00020\u0007J\u0015\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\u001aH\u0001¢\u0006\u0002\b\u001bJ\u0017\u0010\u001c\u001a\u00020\u00182\b\u0010\u001d\u001a\u0004\u0018\u00010\u0013H\u0001¢\u0006\u0002\b\u001eJ\u0010\u0010\u001f\u001a\u00020\u00182\u0006\u0010 \u001a\u00020\u0013H\u0007J\u0018\u0010!\u001a\u00020\u00182\u0006\u0010\u0015\u001a\u00020\u00072\u0006\u0010\"\u001a\u00020\bH\u0007J\u0018\u0010#\u001a\u00020\u00182\u000e\u0010$\u001a\n\u0012\u0006\b\u0001\u0012\u00020&0%H\u0007J\u0010\u0010'\u001a\u00020\u00182\u0006\u0010\u0015\u001a\u00020\u0007H\u0007R\u000e\u0010\u0003\u001a\u00020\u0004X\u000e¢\u0006\u0002\n\u0000R\u001a\u0010\u0005\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\b0\u0006X\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\t\u001a\u00020\u0004X\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\n\u0010\u000b\"\u0004\b\f\u0010\rR \u0010\u000f\u001a\u00020\u00042\u0006\u0010\u000e\u001a\u00020\u00048G@BX\u000e¢\u0006\b\n\u0000\u001a\u0004\b\u000f\u0010\u000bR\u0010\u0010\u0010\u001a\u0004\u0018\u00010\u0011X\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0012\u001a\u0004\u0018\u00010\u0013X\u000e¢\u0006\u0002\n\u0000¨\u0006+"}, d2 = {"Landroidx/savedstate/SavedStateRegistry;", "", "()V", "attached", "", "components", "Landroidx/arch/core/internal/SafeIterableMap;", "", "Landroidx/savedstate/SavedStateRegistry$SavedStateProvider;", "isAllowingSavingState", "isAllowingSavingState$savedstate_release", "()Z", "setAllowingSavingState$savedstate_release", "(Z)V", "<set-?>", "isRestored", "recreatorProvider", "Landroidx/savedstate/Recreator$SavedStateProvider;", "restoredState", "Landroid/os/Bundle;", "consumeRestoredStateForKey", "key", "getSavedStateProvider", "performAttach", "", "lifecycle", "Landroidx/lifecycle/Lifecycle;", "performAttach$savedstate_release", "performRestore", "savedState", "performRestore$savedstate_release", "performSave", "outBundle", "registerSavedStateProvider", "provider", "runOnNextRecreation", "clazz", "Ljava/lang/Class;", "Landroidx/savedstate/SavedStateRegistry$AutoRecreated;", "unregisterSavedStateProvider", "AutoRecreated", "Companion", "SavedStateProvider", "savedstate_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
  /* compiled from: SavedStateRegistry.kt */
  public final class SavedStateRegistry {
      private static final Companion Companion = new Companion((DefaultConstructorMarker) null);
      @Deprecated
      private static final String SAVED_COMPONENTS_KEY = "androidx.lifecycle.BundlableSavedStateRegistry.key";
      private boolean attached;
      private final SafeIterableMap<String, SavedStateProvider> components = new SafeIterableMap<>();
      private boolean isAllowingSavingState = true;
      private boolean isRestored;
      private Recreator.SavedStateProvider recreatorProvider;
      private Bundle restoredState;
  
      @Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\bf\u0018\u00002\u00020\u0001J\u0010\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u0005H&¨\u0006\u0006"}, d2 = {"Landroidx/savedstate/SavedStateRegistry$AutoRecreated;", "", "onRecreated", "", "owner", "Landroidx/savedstate/SavedStateRegistryOwner;", "savedstate_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
      /* compiled from: SavedStateRegistry.kt */
      public interface AutoRecreated {
          void onRecreated(SavedStateRegistryOwner savedStateRegistryOwner);
      }
  
      @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000¨\u0006\u0005"}, d2 = {"Landroidx/savedstate/SavedStateRegistry$Companion;", "", "()V", "SAVED_COMPONENTS_KEY", "", "savedstate_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
      /* compiled from: SavedStateRegistry.kt */
      private static final class Companion {
          private Companion() {
          }
  
          public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
              this();
          }
      }
  
      @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\bæ\u0001\u0018\u00002\u00020\u0001J\b\u0010\u0002\u001a\u00020\u0003H&¨\u0006\u0004"}, d2 = {"Landroidx/savedstate/SavedStateRegistry$SavedStateProvider;", "", "saveState", "Landroid/os/Bundle;", "savedstate_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
      /* compiled from: SavedStateRegistry.kt */
      public interface SavedStateProvider {
          Bundle saveState();
      }
  
      /* access modifiers changed from: private */
      /* renamed from: performAttach$lambda-4  reason: not valid java name */
      public static final void m31performAttach$lambda4(SavedStateRegistry this$0, LifecycleOwner lifecycleOwner, Lifecycle.Event event) {
          Intrinsics.checkNotNullParameter(this$0, "this$0");
          Intrinsics.checkNotNullParameter(lifecycleOwner, "<anonymous parameter 0>");
          Intrinsics.checkNotNullParameter(event, NotificationCompat.CATEGORY_EVENT);
          if (event == Lifecycle.Event.ON_START) {
              this$0.isAllowingSavingState = true;
          } else if (event == Lifecycle.Event.ON_STOP) {
              this$0.isAllowingSavingState = false;
          }
      }
  
      public final Bundle consumeRestoredStateForKey(String key) {
          Intrinsics.checkNotNullParameter(key, "key");
          if (this.isRestored) {
              Bundle bundle = this.restoredState;
              if (bundle == null) {
                  return null;
              }
              Bundle bundle2 = bundle != null ? bundle.getBundle(key) : null;
              Bundle bundle3 = this.restoredState;
              if (bundle3 != null) {
                  bundle3.remove(key);
              }
              Bundle bundle4 = this.restoredState;
              boolean z = false;
              if (bundle4 != null && !bundle4.isEmpty()) {
                  z = true;
              }
              if (!z) {
                  this.restoredState = null;
              }
              return bundle2;
          }
          throw new IllegalStateException("You can consumeRestoredStateForKey only after super.onCreate of corresponding component".toString());
      }
  
      public final SavedStateProvider getSavedStateProvider(String key) {
          Intrinsics.checkNotNullParameter(key, "key");
          Iterator<Map.Entry<String, SavedStateProvider>> it = this.components.iterator();
          while (it.hasNext()) {
              Map.Entry next = it.next();
              Intrinsics.checkNotNullExpressionValue(next, "components");
              SavedStateProvider savedStateProvider = (SavedStateProvider) next.getValue();
              if (Intrinsics.areEqual((Object) (String) next.getKey(), (Object) key)) {
                  return savedStateProvider;
              }
          }
          return null;
      }
  
      public final boolean isAllowingSavingState$savedstate_release() {
          return this.isAllowingSavingState;
      }
  
      public final boolean isRestored() {
          return this.isRestored;
      }
  
      public final void performAttach$savedstate_release(Lifecycle lifecycle) {
          Intrinsics.checkNotNullParameter(lifecycle, "lifecycle");
          if (!this.attached) {
              lifecycle.addObserver(new SavedStateRegistry$$ExternalSyntheticLambda0(this));
              this.attached = true;
              return;
          }
          throw new IllegalStateException("SavedStateRegistry was already attached.".toString());
      }
  
      public final void performRestore$savedstate_release(Bundle savedState) {
          if (!this.attached) {
              throw new IllegalStateException("You must call performAttach() before calling performRestore(Bundle).".toString());
          } else if (!this.isRestored) {
              this.restoredState = savedState != null ? savedState.getBundle(SAVED_COMPONENTS_KEY) : null;
              this.isRestored = true;
          } else {
              throw new IllegalStateException("SavedStateRegistry was already restored.".toString());
          }
      }
  
      public final void performSave(Bundle outBundle) {
          Intrinsics.checkNotNullParameter(outBundle, "outBundle");
          Bundle bundle = new Bundle();
          Bundle bundle2 = this.restoredState;
          if (bundle2 != null) {
              bundle.putAll(bundle2);
          }
          SafeIterableMap<K, V>.IteratorWithAdditions iteratorWithAdditions = this.components.iteratorWithAdditions();
          Intrinsics.checkNotNullExpressionValue(iteratorWithAdditions, "this.components.iteratorWithAdditions()");
          Iterator it = iteratorWithAdditions;
          while (it.hasNext()) {
              Map.Entry entry = (Map.Entry) it.next();
              bundle.putBundle((String) entry.getKey(), ((SavedStateProvider) entry.getValue()).saveState());
          }
          if (!bundle.isEmpty()) {
              outBundle.putBundle(SAVED_COMPONENTS_KEY, bundle);
          }
      }
  
      public final void registerSavedStateProvider(String key, SavedStateProvider provider) {
          Intrinsics.checkNotNullParameter(key, "key");
          Intrinsics.checkNotNullParameter(provider, "provider");
          if (!(this.components.putIfAbsent(key, provider) == null)) {
              throw new IllegalArgumentException("SavedStateProvider with the given key is already registered".toString());
          }
      }
  
      public final void runOnNextRecreation(Class<? extends AutoRecreated> clazz) {
          Intrinsics.checkNotNullParameter(clazz, "clazz");
          if (this.isAllowingSavingState) {
              Recreator.SavedStateProvider savedStateProvider = this.recreatorProvider;
              if (savedStateProvider == null) {
                  savedStateProvider = new Recreator.SavedStateProvider(this);
              }
              this.recreatorProvider = savedStateProvider;
              try {
                  clazz.getDeclaredConstructor(new Class[0]);
                  Recreator.SavedStateProvider savedStateProvider2 = this.recreatorProvider;
                  if (savedStateProvider2 != null) {
                      String name = clazz.getName();
                      Intrinsics.checkNotNullExpressionValue(name, "clazz.name");
                      savedStateProvider2.add(name);
                  }
              } catch (NoSuchMethodException e) {
                  throw new IllegalArgumentException("Class " + clazz.getSimpleName() + " must have default constructor in order to be automatically recreated", e);
              }
          } else {
              throw new IllegalStateException("Can not perform this action after onSaveInstanceState".toString());
          }
      }
  
      public final void setAllowingSavingState$savedstate_release(boolean z) {
          this.isAllowingSavingState = z;
      }
  
      public final void unregisterSavedStateProvider(String key) {
          Intrinsics.checkNotNullParameter(key, "key");
          this.components.remove(key);
      }
  }
  