package v0;

import android.os.Bundle;
import androidx.lifecycle.AbstractC0309p;
import androidx.lifecycle.C0315w;
import androidx.lifecycle.EnumC0308o;
import d.C0510d;
import java.util.Map;
import o.C0921d;

/* JADX INFO: loaded from: classes.dex */
public final class f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final g f10402a;

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

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

    public f(g gVar) {
        this.f10402a = gVar;
    }

    public final void a() {
        g gVar = this.f10402a;
        AbstractC0309p lifecycle = gVar.getLifecycle();
        if (((C0315w) lifecycle).f4487c != EnumC0308o.f4478l) {
            throw new IllegalStateException("Restarter must be created only during owner's initialization stage");
        }
        lifecycle.a(new b(gVar, 0));
        e eVar = this.f10403b;
        eVar.getClass();
        if (eVar.f10397b) {
            throw new IllegalStateException("SavedStateRegistry was already attached.");
        }
        lifecycle.a(new C0510d(2, eVar));
        eVar.f10397b = true;
        this.f10404c = true;
    }

    public final void b(Bundle bundle) {
        if (!this.f10404c) {
            a();
        }
        C0315w c0315w = (C0315w) this.f10402a.getLifecycle();
        if (c0315w.f4487c.compareTo(EnumC0308o.f4480n) >= 0) {
            throw new IllegalStateException(("performRestore cannot be called when owner is " + c0315w.f4487c).toString());
        }
        e eVar = this.f10403b;
        if (!eVar.f10397b) {
            throw new IllegalStateException("You must call performAttach() before calling performRestore(Bundle).");
        }
        if (eVar.f10399d) {
            throw new IllegalStateException("SavedStateRegistry was already restored.");
        }
        eVar.f10398c = bundle != null ? bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key") : null;
        eVar.f10399d = true;
    }

    public final void c(Bundle bundle) {
        e eVar = this.f10403b;
        eVar.getClass();
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = eVar.f10398c;
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        o.f fVar = eVar.f10396a;
        fVar.getClass();
        C0921d c0921d = new C0921d(fVar);
        fVar.f9375m.put(c0921d, Boolean.FALSE);
        while (c0921d.hasNext()) {
            Map.Entry entry = (Map.Entry) c0921d.next();
            bundle2.putBundle((String) entry.getKey(), ((d) entry.getValue()).a());
        }
        if (bundle2.isEmpty()) {
            return;
        }
        bundle.putBundle("androidx.lifecycle.BundlableSavedStateRegistry.key", bundle2);
    }
}
