package androidx.lifecycle; import android.app.Application; import androidx.annotation.MainThread; import androidx.annotation.RestrictTo; import androidx.lifecycle.viewmodel.CreationExtras; import androidx.lifecycle.viewmodel.InitializerViewModelFactory; import androidx.lifecycle.viewmodel.MutableCreationExtras; import androidx.lifecycle.viewmodel.ViewModelInitializer; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; @SourceDebugExtension({"SMAP\nViewModelProvider.kt\nKotlin\n*S Kotlin\n*F\n+ 1 ViewModelProvider.kt\nandroidx/lifecycle/ViewModelProvider\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,375:1\n1#2:376\n*E\n"}) /* loaded from: classes.dex */ public class ViewModelProvider { private final CreationExtras defaultCreationExtras; private final Factory factory; private final ViewModelStore store; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) public static class OnRequeryFactory { public void onRequery(ViewModel viewModel) { Intrinsics.checkNotNullParameter(viewModel, "viewModel"); } } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public ViewModelProvider(ViewModelStore store, Factory factory) { this(store, factory, null, 4, null); Intrinsics.checkNotNullParameter(store, "store"); Intrinsics.checkNotNullParameter(factory, "factory"); } public ViewModelProvider(ViewModelStore store, Factory factory, CreationExtras defaultCreationExtras) { Intrinsics.checkNotNullParameter(store, "store"); Intrinsics.checkNotNullParameter(factory, "factory"); Intrinsics.checkNotNullParameter(defaultCreationExtras, "defaultCreationExtras"); this.store = store; this.factory = factory; this.defaultCreationExtras = defaultCreationExtras; } public /* synthetic */ ViewModelProvider(ViewModelStore viewModelStore, Factory factory, CreationExtras creationExtras, int i, DefaultConstructorMarker defaultConstructorMarker) { this(viewModelStore, factory, (i & 4) != 0 ? CreationExtras.Empty.INSTANCE : creationExtras); } public interface Factory { public static final Companion Companion = Companion.$$INSTANCE; static Factory from(ViewModelInitializer... viewModelInitializerArr) { return Companion.from(viewModelInitializerArr); } default T create(Class modelClass) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); throw new UnsupportedOperationException("Factory.create(String) is unsupported. This Factory requires `CreationExtras` to be passed into `create` method."); } default T create(Class modelClass, CreationExtras extras) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); Intrinsics.checkNotNullParameter(extras, "extras"); return (T) create(modelClass); } public static final class Companion { static final /* synthetic */ Companion $$INSTANCE = new Companion(); private Companion() { } public final Factory from(ViewModelInitializer... initializers) { Intrinsics.checkNotNullParameter(initializers, "initializers"); return new InitializerViewModelFactory((ViewModelInitializer[]) Arrays.copyOf(initializers, initializers.length)); } } } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public ViewModelProvider(ViewModelStoreOwner owner) { this(owner.getViewModelStore(), AndroidViewModelFactory.Companion.defaultFactory$lifecycle_viewmodel_release(owner), ViewModelProviderGetKt.defaultCreationExtras(owner)); Intrinsics.checkNotNullParameter(owner, "owner"); } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public ViewModelProvider(ViewModelStoreOwner owner, Factory factory) { this(owner.getViewModelStore(), factory, ViewModelProviderGetKt.defaultCreationExtras(owner)); Intrinsics.checkNotNullParameter(owner, "owner"); Intrinsics.checkNotNullParameter(factory, "factory"); } @MainThread public T get(Class modelClass) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); String canonicalName = modelClass.getCanonicalName(); if (canonicalName == null) { throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels"); } return (T) get("androidx.lifecycle.ViewModelProvider.DefaultKey:" + canonicalName, modelClass); } @MainThread public T get(String key, Class modelClass) { T t; Intrinsics.checkNotNullParameter(key, "key"); Intrinsics.checkNotNullParameter(modelClass, "modelClass"); T t2 = (T) this.store.get(key); if (modelClass.isInstance(t2)) { Object obj = this.factory; OnRequeryFactory onRequeryFactory = obj instanceof OnRequeryFactory ? (OnRequeryFactory) obj : null; if (onRequeryFactory != null) { Intrinsics.checkNotNull(t2); onRequeryFactory.onRequery(t2); } Intrinsics.checkNotNull(t2, "null cannot be cast to non-null type T of androidx.lifecycle.ViewModelProvider.get"); return t2; } MutableCreationExtras mutableCreationExtras = new MutableCreationExtras(this.defaultCreationExtras); mutableCreationExtras.set(NewInstanceFactory.VIEW_MODEL_KEY, key); try { t = (T) this.factory.create(modelClass, mutableCreationExtras); } catch (AbstractMethodError unused) { t = (T) this.factory.create(modelClass); } this.store.put(key, t); return t; } public static class NewInstanceFactory implements Factory { public static final Companion Companion = new Companion(null); public static final CreationExtras.Key VIEW_MODEL_KEY = Companion.ViewModelKeyImpl.INSTANCE; private static NewInstanceFactory sInstance; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) public static final NewInstanceFactory getInstance() { return Companion.getInstance(); } @Override // androidx.lifecycle.ViewModelProvider.Factory public T create(Class modelClass) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); try { T newInstance = modelClass.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]); Intrinsics.checkNotNullExpressionValue(newInstance, "{\n modelC…wInstance()\n }"); return newInstance; } catch (IllegalAccessException e) { throw new RuntimeException("Cannot create an instance of " + modelClass, e); } catch (InstantiationException e2) { throw new RuntimeException("Cannot create an instance of " + modelClass, e2); } catch (NoSuchMethodException e3) { throw new RuntimeException("Cannot create an instance of " + modelClass, e3); } } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public static /* synthetic */ void getInstance$annotations() { } private Companion() { } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) public final NewInstanceFactory getInstance() { if (NewInstanceFactory.sInstance == null) { NewInstanceFactory.sInstance = new NewInstanceFactory(); } NewInstanceFactory newInstanceFactory = NewInstanceFactory.sInstance; Intrinsics.checkNotNull(newInstanceFactory); return newInstanceFactory; } public static final class ViewModelKeyImpl implements CreationExtras.Key { public static final ViewModelKeyImpl INSTANCE = new ViewModelKeyImpl(); private ViewModelKeyImpl() { } } } } public static class AndroidViewModelFactory extends NewInstanceFactory { public static final String DEFAULT_KEY = "androidx.lifecycle.ViewModelProvider.DefaultKey"; private static AndroidViewModelFactory sInstance; private final Application application; public static final Companion Companion = new Companion(null); public static final CreationExtras.Key APPLICATION_KEY = Companion.ApplicationKeyImpl.INSTANCE; public static final AndroidViewModelFactory getInstance(Application application) { return Companion.getInstance(application); } private AndroidViewModelFactory(Application application, int i) { this.application = application; } public AndroidViewModelFactory() { this(null, 0); } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public AndroidViewModelFactory(Application application) { this(application, 0); Intrinsics.checkNotNullParameter(application, "application"); } @Override // androidx.lifecycle.ViewModelProvider.Factory public T create(Class modelClass, CreationExtras extras) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); Intrinsics.checkNotNullParameter(extras, "extras"); if (this.application != null) { return (T) create(modelClass); } Application application = (Application) extras.get(APPLICATION_KEY); if (application != null) { return (T) create(modelClass, application); } if (AndroidViewModel.class.isAssignableFrom(modelClass)) { throw new IllegalArgumentException("CreationExtras must have an application by `APPLICATION_KEY`"); } return (T) super.create(modelClass); } @Override // androidx.lifecycle.ViewModelProvider.NewInstanceFactory, androidx.lifecycle.ViewModelProvider.Factory public T create(Class modelClass) { Intrinsics.checkNotNullParameter(modelClass, "modelClass"); Application application = this.application; if (application == null) { throw new UnsupportedOperationException("AndroidViewModelFactory constructed with empty constructor works only with create(modelClass: Class, extras: CreationExtras)."); } return (T) create(modelClass, application); } private final T create(Class cls, Application application) { if (AndroidViewModel.class.isAssignableFrom(cls)) { try { T newInstance = cls.getConstructor(Application.class).newInstance(application); Intrinsics.checkNotNullExpressionValue(newInstance, "{\n try {\n… }\n }"); return newInstance; } catch (IllegalAccessException e) { throw new RuntimeException("Cannot create an instance of " + cls, e); } catch (InstantiationException e2) { throw new RuntimeException("Cannot create an instance of " + cls, e2); } catch (NoSuchMethodException e3) { throw new RuntimeException("Cannot create an instance of " + cls, e3); } catch (InvocationTargetException e4) { throw new RuntimeException("Cannot create an instance of " + cls, e4); } } return (T) super.create(cls); } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } public final Factory defaultFactory$lifecycle_viewmodel_release(ViewModelStoreOwner owner) { Intrinsics.checkNotNullParameter(owner, "owner"); return owner instanceof HasDefaultViewModelProviderFactory ? ((HasDefaultViewModelProviderFactory) owner).getDefaultViewModelProviderFactory() : NewInstanceFactory.Companion.getInstance(); } public final AndroidViewModelFactory getInstance(Application application) { Intrinsics.checkNotNullParameter(application, "application"); if (AndroidViewModelFactory.sInstance == null) { AndroidViewModelFactory.sInstance = new AndroidViewModelFactory(application); } AndroidViewModelFactory androidViewModelFactory = AndroidViewModelFactory.sInstance; Intrinsics.checkNotNull(androidViewModelFactory); return androidViewModelFactory; } public static final class ApplicationKeyImpl implements CreationExtras.Key { public static final ApplicationKeyImpl INSTANCE = new ApplicationKeyImpl(); private ApplicationKeyImpl() { } } } } }