package androidx.savedstate;

import android.annotation.SuppressLint;
import android.os.Bundle;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import p037.p099.AbstractC2210;
import p037.p099.C2221;
import p037.p099.InterfaceC2208;
import p037.p099.InterfaceC2219;
import p037.p112.C2430;
import p037.p112.InterfaceC2434;
import p138.p139.p143.p144.C2803;

/* JADX INFO: loaded from: classes.dex */
@SuppressLint({"RestrictedApi"})
public final class Recreator implements InterfaceC2208 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final InterfaceC2434 f1406;

    /* JADX INFO: renamed from: androidx.savedstate.Recreator$֏, reason: contains not printable characters */
    public static final class C0236 implements C2430.InterfaceC2432 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Set<String> f1407 = new HashSet();

        public C0236(C2430 c2430) {
            if (c2430.f7702.mo3327("androidx.savedstate.Restarter", this) != null) {
                throw new IllegalArgumentException("SavedStateProvider with the given key is already registered");
            }
        }

        @Override // p037.p112.C2430.InterfaceC2432
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public Bundle mo815() {
            Bundle bundle = new Bundle();
            bundle.putStringArrayList("classes_to_restore", new ArrayList<>(this.f1407));
            return bundle;
        }
    }

    public Recreator(InterfaceC2434 interfaceC2434) {
        this.f1406 = interfaceC2434;
    }

    @Override // p037.p099.InterfaceC2217
    /* JADX INFO: renamed from: ֏ */
    public void mo87(InterfaceC2219 interfaceC2219, AbstractC2210.EnumC2211 enumC2211) {
        if (enumC2211 != AbstractC2210.EnumC2211.ON_CREATE) {
            throw new AssertionError("Next event must be ON_CREATE");
        }
        ((C2221) interfaceC2219.getLifecycle()).f7159.remove(this);
        Bundle bundleM4512 = this.f1406.getSavedStateRegistry().m4512("androidx.savedstate.Restarter");
        if (bundleM4512 == null) {
            return;
        }
        ArrayList<String> stringArrayList = bundleM4512.getStringArrayList("classes_to_restore");
        if (stringArrayList == null) {
            throw new IllegalStateException("Bundle with restored state for the component \"androidx.savedstate.Restarter\" must contain list of strings by the key \"classes_to_restore\"");
        }
        for (String str : stringArrayList) {
            try {
                Class<? extends U> clsAsSubclass = Class.forName(str, false, Recreator.class.getClassLoader()).asSubclass(C2430.InterfaceC2431.class);
                try {
                    Constructor declaredConstructor = clsAsSubclass.getDeclaredConstructor(new Class[0]);
                    declaredConstructor.setAccessible(true);
                    try {
                        ((C2430.InterfaceC2431) declaredConstructor.newInstance(new Object[0])).mo356(this.f1406);
                    } catch (Exception e) {
                        throw new RuntimeException(C2803.m4879("Failed to instantiate ", str), e);
                    }
                } catch (NoSuchMethodException e2) {
                    StringBuilder sbM4889 = C2803.m4889("Class");
                    sbM4889.append(clsAsSubclass.getSimpleName());
                    sbM4889.append(" must have default constructor in order to be automatically recreated");
                    throw new IllegalStateException(sbM4889.toString(), e2);
                }
            } catch (ClassNotFoundException e3) {
                throw new RuntimeException(C2803.m4880("Class ", str, " wasn't found"), e3);
            }
        }
    }
}
