package androidx.lifecycle;

import android.app.Application;
import java.lang.reflect.InvocationTargetException;

/* JADX INFO: loaded from: classes.dex */
public final class t0 extends v0 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static t0 f2704c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final eb.e f2705d = new eb.e();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Application f2706b;

    public t0(Application application) {
        this.f2706b = application;
    }

    @Override // androidx.lifecycle.v0, androidx.lifecycle.u0
    public final s0 a(Class cls) {
        Application application = this.f2706b;
        if (application != null) {
            return d(cls, application);
        }
        throw new UnsupportedOperationException("AndroidViewModelFactory constructed with empty constructor works only with create(modelClass: Class<T>, extras: CreationExtras).");
    }

    @Override // androidx.lifecycle.v0, androidx.lifecycle.u0
    public final s0 c(Class cls, n1.c cVar) {
        if (this.f2706b != null) {
            return a(cls);
        }
        Application application = (Application) cVar.f30758a.get(f2705d);
        if (application != null) {
            return d(cls, application);
        }
        if (AndroidViewModel.class.isAssignableFrom(cls)) {
            throw new IllegalArgumentException("CreationExtras must have an application by `APPLICATION_KEY`");
        }
        return com.bumptech.glide.g.b(cls);
    }

    public final s0 d(Class cls, Application application) {
        if (!AndroidViewModel.class.isAssignableFrom(cls)) {
            return com.bumptech.glide.g.b(cls);
        }
        try {
            s0 s0Var = (s0) cls.getConstructor(Application.class).newInstance(application);
            nb.g.h(s0Var, "{\n                try {\n…          }\n            }");
            return s0Var;
        } catch (IllegalAccessException e10) {
            throw new RuntimeException("Cannot create an instance of " + cls, e10);
        } catch (InstantiationException e11) {
            throw new RuntimeException("Cannot create an instance of " + cls, e11);
        } catch (NoSuchMethodException e12) {
            throw new RuntimeException("Cannot create an instance of " + cls, e12);
        } catch (InvocationTargetException e13) {
            throw new RuntimeException("Cannot create an instance of " + cls, e13);
        }
    }
}
