package c.o;

import android.os.Bundle;
import androidx.savedstate.Recreator;
import c.l.j;
import c.l.n;
import c.o.b;
import g.h0.c.g;
import g.h0.c.l;
import g.i;
import java.util.Map;
import java.util.Objects;

/* JADX INFO: compiled from: SavedStateRegistryController.kt */
/* JADX INFO: loaded from: classes.dex */
@i
public final class c {
    public final d a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final b f1917b = new b();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f1918c;

    public c(d dVar, g gVar) {
        this.a = dVar;
    }

    public static final c a(d dVar) {
        l.f(dVar, "owner");
        return new c(dVar, null);
    }

    public final void b() {
        j lifecycle = this.a.getLifecycle();
        l.e(lifecycle, "owner.lifecycle");
        if (!(lifecycle.b() == j.b.INITIALIZED)) {
            throw new IllegalStateException("Restarter must be created only during owner's initialization stage".toString());
        }
        lifecycle.a(new Recreator(this.a));
        final b bVar = this.f1917b;
        Objects.requireNonNull(bVar);
        l.f(lifecycle, "lifecycle");
        if (!(!bVar.f1912b)) {
            throw new IllegalStateException("SavedStateRegistry was already attached.".toString());
        }
        lifecycle.a(new c.l.l() { // from class: c.o.a
            @Override // c.l.l
            public final void g(n nVar, j.a aVar) {
                b bVar2 = bVar;
                l.f(bVar2, "this$0");
                l.f(nVar, "<anonymous parameter 0>");
                l.f(aVar, "event");
                if (aVar == j.a.ON_START) {
                    bVar2.f1916f = true;
                } else if (aVar == j.a.ON_STOP) {
                    bVar2.f1916f = false;
                }
            }
        });
        bVar.f1912b = true;
        this.f1918c = true;
    }

    public final void c(Bundle bundle) {
        if (!this.f1918c) {
            b();
        }
        j lifecycle = this.a.getLifecycle();
        l.e(lifecycle, "owner.lifecycle");
        if (!(!lifecycle.b().isAtLeast(j.b.STARTED))) {
            StringBuilder sbB = d.b.a.a.a.B("performRestore cannot be called when owner is ");
            sbB.append(lifecycle.b());
            throw new IllegalStateException(sbB.toString().toString());
        }
        b bVar = this.f1917b;
        if (!bVar.f1912b) {
            throw new IllegalStateException("You must call performAttach() before calling performRestore(Bundle).".toString());
        }
        if (!(!bVar.f1914d)) {
            throw new IllegalStateException("SavedStateRegistry was already restored.".toString());
        }
        bVar.f1913c = bundle != null ? bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key") : null;
        bVar.f1914d = true;
    }

    public final void d(Bundle bundle) {
        l.f(bundle, "outBundle");
        b bVar = this.f1917b;
        Objects.requireNonNull(bVar);
        l.f(bundle, "outBundle");
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = bVar.f1913c;
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        c.c.a.b.b<String, b.InterfaceC0024b>.d dVarB = bVar.a.b();
        l.e(dVarB, "this.components.iteratorWithAdditions()");
        while (dVarB.hasNext()) {
            Map.Entry entry = (Map.Entry) dVarB.next();
            bundle2.putBundle((String) entry.getKey(), ((b.InterfaceC0024b) entry.getValue()).a());
        }
        if (bundle2.isEmpty()) {
            return;
        }
        bundle.putBundle("androidx.lifecycle.BundlableSavedStateRegistry.key", bundle2);
    }
}
