package androidx.lifecycle; import android.app.Application; import android.os.Bundle; import androidx.lifecycle.v; import androidx.savedstate.SavedStateRegistry; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; /* loaded from: classes.dex */ public final class s extends v.c { /* renamed from: f, reason: collision with root package name */ private static final Class[] f2113f = {Application.class, r.class}; /* renamed from: g, reason: collision with root package name */ private static final Class[] f2114g = {r.class}; /* renamed from: a, reason: collision with root package name */ private final Application f2115a; /* renamed from: b, reason: collision with root package name */ private final v.b f2116b; /* renamed from: c, reason: collision with root package name */ private final Bundle f2117c; /* renamed from: d, reason: collision with root package name */ private final e f2118d; /* renamed from: e, reason: collision with root package name */ private final SavedStateRegistry f2119e; public s(Application application, androidx.savedstate.c cVar, Bundle bundle) { this.f2119e = cVar.getSavedStateRegistry(); this.f2118d = cVar.getLifecycle(); this.f2117c = bundle; this.f2115a = application; this.f2116b = application != null ? v.a.c(application) : v.d.b(); } private static Constructor d(Class cls, Class[] clsArr) { for (Constructor constructor : cls.getConstructors()) { if (Arrays.equals(clsArr, constructor.getParameterTypes())) { return constructor; } } return null; } @Override // androidx.lifecycle.v.b public u a(Class cls) { String canonicalName = cls.getCanonicalName(); if (canonicalName != null) { return c(canonicalName, cls); } throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } @Override // androidx.lifecycle.v.e void b(u uVar) { SavedStateHandleController.a(uVar, this.f2119e, this.f2118d); } @Override // androidx.lifecycle.v.c public u c(String str, Class cls) { u uVar; boolean isAssignableFrom = a.class.isAssignableFrom(cls); Constructor d10 = (!isAssignableFrom || this.f2115a == null) ? d(cls, f2114g) : d(cls, f2113f); if (d10 == null) { return this.f2116b.a(cls); } SavedStateHandleController c10 = SavedStateHandleController.c(this.f2119e, this.f2118d, str, this.f2117c); if (isAssignableFrom) { try { Application application = this.f2115a; if (application != null) { uVar = (u) d10.newInstance(application, c10.d()); uVar.e("androidx.lifecycle.savedstate.vm.tag", c10); return uVar; } } catch (IllegalAccessException e10) { throw new RuntimeException("Failed to access " + cls, e10); } catch (InstantiationException e11) { throw new RuntimeException("A " + cls + " cannot be instantiated.", e11); } catch (InvocationTargetException e12) { throw new RuntimeException("An exception happened in constructor of " + cls, e12.getCause()); } } uVar = (u) d10.newInstance(c10.d()); uVar.e("androidx.lifecycle.savedstate.vm.tag", c10); return uVar; } }