package o;

import android.os.Bundle;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.k40, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1640k40 {
    public final C1830m40 a;
    public C2404s7 b;

    public C1640k40(C1830m40 c1830m40) {
        this.a = c1830m40;
    }

    public final Bundle a(String str) {
        C1830m40 c1830m40 = this.a;
        if (!c1830m40.g) {
            throw new IllegalStateException("You can 'consumeRestoredStateForKey' only after the corresponding component has moved to the 'CREATED' state");
        }
        Bundle bundle = c1830m40.f;
        if (bundle == null) {
            return null;
        }
        Bundle bundleF = bundle.containsKey(str) ? Co0.F(str, bundle) : null;
        bundle.remove(str);
        if (bundle.isEmpty()) {
            c1830m40.f = null;
        }
        return bundleF;
    }

    public final InterfaceC1545j40 b() {
        InterfaceC1545j40 interfaceC1545j40;
        C1830m40 c1830m40 = this.a;
        synchronized (c1830m40.c) {
            Iterator it = c1830m40.d.entrySet().iterator();
            do {
                interfaceC1545j40 = null;
                if (!it.hasNext()) {
                    break;
                }
                Map.Entry entry = (Map.Entry) it.next();
                String str = (String) entry.getKey();
                InterfaceC1545j40 interfaceC1545j402 = (InterfaceC1545j40) entry.getValue();
                if (F3.c(str, "androidx.lifecycle.internal.SavedStateHandlesProvider")) {
                    interfaceC1545j40 = interfaceC1545j402;
                }
            } while (interfaceC1545j40 == null);
        }
        return interfaceC1545j40;
    }

    public final void c(String str, InterfaceC1545j40 interfaceC1545j40) {
        C1830m40 c1830m40 = this.a;
        synchronized (c1830m40.c) {
            if (c1830m40.d.containsKey(str)) {
                throw new IllegalArgumentException("SavedStateProvider with the given key is already registered");
            }
            c1830m40.d.put(str, interfaceC1545j40);
        }
    }

    public final void d() {
        if (!this.a.h) {
            throw new IllegalStateException("Can not perform this action after onSaveInstanceState");
        }
        C2404s7 c2404s7 = this.b;
        if (c2404s7 == null) {
            c2404s7 = new C2404s7(this);
        }
        this.b = c2404s7;
        try {
            LK.class.getDeclaredConstructor(null);
            C2404s7 c2404s72 = this.b;
            if (c2404s72 != null) {
                ((LinkedHashSet) c2404s72.b).add(LK.class.getName());
            }
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Class " + LK.class.getSimpleName() + " must have default constructor in order to be automatically recreated", e);
        }
    }
}
