package androidx.savedstate; import android.os.Bundle; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.e; import androidx.lifecycle.g; import androidx.savedstate.Recreator; import java.util.Map; import k.b; /* loaded from: classes.dex */ public final class SavedStateRegistry { /* renamed from: b, reason: collision with root package name */ private Bundle f2661b; /* renamed from: c, reason: collision with root package name */ private boolean f2662c; /* renamed from: d, reason: collision with root package name */ private Recreator.a f2663d; /* renamed from: a, reason: collision with root package name */ private k.b f2660a = new k.b(); /* renamed from: e, reason: collision with root package name */ boolean f2664e = true; public interface a { void a(c cVar); } public interface b { Bundle a(); } SavedStateRegistry() { } public Bundle a(String str) { if (!this.f2662c) { throw new IllegalStateException("You can consumeRestoredStateForKey only after super.onCreate of corresponding component"); } Bundle bundle = this.f2661b; if (bundle == null) { return null; } Bundle bundle2 = bundle.getBundle(str); this.f2661b.remove(str); if (this.f2661b.isEmpty()) { this.f2661b = null; } return bundle2; } void b(e eVar, Bundle bundle) { if (this.f2662c) { throw new IllegalStateException("SavedStateRegistry was already restored."); } if (bundle != null) { this.f2661b = bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key"); } eVar.a(new g() { // from class: androidx.savedstate.SavedStateRegistry.1 @Override // androidx.lifecycle.g public void onStateChanged(LifecycleOwner lifecycleOwner, e.b bVar) { if (bVar == e.b.ON_START) { SavedStateRegistry.this.f2664e = true; } else if (bVar == e.b.ON_STOP) { SavedStateRegistry.this.f2664e = false; } } }); this.f2662c = true; } void c(Bundle bundle) { Bundle bundle2 = new Bundle(); Bundle bundle3 = this.f2661b; if (bundle3 != null) { bundle2.putAll(bundle3); } b.d c10 = this.f2660a.c(); while (c10.hasNext()) { Map.Entry entry = (Map.Entry) c10.next(); bundle2.putBundle((String) entry.getKey(), ((b) entry.getValue()).a()); } bundle.putBundle("androidx.lifecycle.BundlableSavedStateRegistry.key", bundle2); } public void d(String str, b bVar) { if (((b) this.f2660a.f(str, bVar)) != null) { throw new IllegalArgumentException("SavedStateProvider with the given key is already registered"); } } public void e(Class cls) { if (!this.f2664e) { throw new IllegalStateException("Can not perform this action after onSaveInstanceState"); } if (this.f2663d == null) { this.f2663d = new Recreator.a(this); } try { cls.getDeclaredConstructor(new Class[0]); this.f2663d.b(cls.getName()); } catch (NoSuchMethodException e10) { throw new IllegalArgumentException("Class" + cls.getSimpleName() + " must have default constructor in order to be automatically recreated", e10); } } }