package o;

import android.app.Application;
import android.os.Bundle;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.o40, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2020o40 implements InterfaceC1221fk0 {
    public final Application a;
    public final C1125ek0 b;
    public final Bundle c;
    public final WK d;
    public final C1640k40 e;

    public C2020o40(Application application, InterfaceC1925n40 interfaceC1925n40, Bundle bundle) {
        C1125ek0 c1125ek0;
        this.e = interfaceC1925n40.getSavedStateRegistry();
        this.d = interfaceC1925n40.getLifecycle();
        this.c = bundle;
        this.a = application;
        if (application != null) {
            if (C1125ek0.c == null) {
                C1125ek0.c = new C1125ek0(application);
            }
            c1125ek0 = C1125ek0.c;
        } else {
            c1125ek0 = new C1125ek0(null);
        }
        this.b = c1125ek0;
    }

    @Override // o.InterfaceC1221fk0
    public final AbstractC0934ck0 a(Class cls) {
        String canonicalName = cls.getCanonicalName();
        if (canonicalName != null) {
            return d(canonicalName, cls);
        }
        throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels");
    }

    @Override // o.InterfaceC1221fk0
    public final AbstractC0934ck0 b(C0474Sh c0474Sh, FQ fq) {
        return c(c0474Sh.a(), fq);
    }

    @Override // o.InterfaceC1221fk0
    public final AbstractC0934ck0 c(Class cls, FQ fq) {
        BP bp = OD.p;
        LinkedHashMap linkedHashMap = fq.a;
        String str = (String) linkedHashMap.get(bp);
        if (str == null) {
            throw new IllegalStateException("VIEW_MODEL_KEY must always be provided by ViewModelProvider");
        }
        if (linkedHashMap.get(AbstractC2378rs0.f) == null || linkedHashMap.get(AbstractC2378rs0.g) == null) {
            if (this.d != null) {
                return d(str, cls);
            }
            throw new IllegalStateException("SAVED_STATE_REGISTRY_OWNER_KEY andVIEW_MODEL_STORE_OWNER_KEY must be provided in the creation extras tosuccessfully create a ViewModel.");
        }
        Application application = (Application) linkedHashMap.get(C1125ek0.d);
        boolean zIsAssignableFrom = AbstractC0784b6.class.isAssignableFrom(cls);
        Constructor constructorA = (!zIsAssignableFrom || application == null) ? AbstractC2115p40.a(cls, AbstractC2115p40.b) : AbstractC2115p40.a(cls, AbstractC2115p40.a);
        return constructorA == null ? this.b.c(cls, fq) : (!zIsAssignableFrom || application == null) ? AbstractC2115p40.b(cls, constructorA, AbstractC2378rs0.J(fq)) : AbstractC2115p40.b(cls, constructorA, application, AbstractC2378rs0.J(fq));
    }

    public final AbstractC0934ck0 d(String str, Class cls) {
        AutoCloseable autoCloseable;
        Application application;
        WK wk = this.d;
        if (wk == null) {
            throw new UnsupportedOperationException("SavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class<T>, extras: CreationExtras).");
        }
        boolean zIsAssignableFrom = AbstractC0784b6.class.isAssignableFrom(cls);
        Constructor constructorA = (!zIsAssignableFrom || this.a == null) ? AbstractC2115p40.a(cls, AbstractC2115p40.b) : AbstractC2115p40.a(cls, AbstractC2115p40.a);
        if (constructorA == null) {
            if (this.a != null) {
                return this.b.a(cls);
            }
            if (C1317gk0.a == null) {
                C1317gk0.a = new C1317gk0();
            }
            C1317gk0.a.getClass();
            return C2887xC.m(cls);
        }
        C1640k40 c1640k40 = this.e;
        C0972d40 c0972d40P = AbstractC0940cn0.p(c1640k40.a(str), this.c);
        C1067e40 c1067e40 = new C1067e40(str, c0972d40P);
        c1067e40.j(c1640k40, wk);
        VK vkB = wk.b();
        if (vkB == VK.m || vkB.a(VK.f372o)) {
            c1640k40.d();
        } else {
            wk.a(new C2184pq(1, wk, c1640k40));
        }
        AbstractC0934ck0 abstractC0934ck0B = (!zIsAssignableFrom || (application = this.a) == null) ? AbstractC2115p40.b(cls, constructorA, c0972d40P) : AbstractC2115p40.b(cls, constructorA, application, c0972d40P);
        C1030dk0 c1030dk0 = abstractC0934ck0B.a;
        if (c1030dk0 == null) {
            return abstractC0934ck0B;
        }
        if (c1030dk0.d) {
            C1030dk0.a(c1067e40);
            return abstractC0934ck0B;
        }
        synchronized (c1030dk0.a) {
            autoCloseable = (AutoCloseable) c1030dk0.b.put("androidx.lifecycle.savedstate.vm.tag", c1067e40);
        }
        C1030dk0.a(autoCloseable);
        return abstractC0934ck0B;
    }
}
