package androidx.lifecycle; import android.os.Bundle; import androidx.savedstate.SavedStateRegistry; import java.util.Map; import kotlin.Lazy; import kotlin.LazyKt__LazyJVMKt; import kotlin.jvm.functions.Function0; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; @SourceDebugExtension({"SMAP\nSavedStateHandleSupport.kt\nKotlin\n*S Kotlin\n*F\n+ 1 SavedStateHandleSupport.kt\nandroidx/lifecycle/SavedStateHandlesProvider\n+ 2 _Maps.kt\nkotlin/collections/MapsKt___MapsKt\n+ 3 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,225:1\n215#2,2:226\n1#3:228\n*S KotlinDebug\n*F\n+ 1 SavedStateHandleSupport.kt\nandroidx/lifecycle/SavedStateHandlesProvider\n*L\n146#1:226,2\n*E\n"}) /* loaded from: classes.dex */ public final class SavedStateHandlesProvider implements SavedStateRegistry.SavedStateProvider { private boolean restored; private Bundle restoredState; private final SavedStateRegistry savedStateRegistry; private final Lazy viewModel$delegate; public SavedStateHandlesProvider(SavedStateRegistry savedStateRegistry, final ViewModelStoreOwner viewModelStoreOwner) { Lazy lazy; Intrinsics.checkNotNullParameter(savedStateRegistry, "savedStateRegistry"); Intrinsics.checkNotNullParameter(viewModelStoreOwner, "viewModelStoreOwner"); this.savedStateRegistry = savedStateRegistry; lazy = LazyKt__LazyJVMKt.lazy(new Function0() { // from class: androidx.lifecycle.SavedStateHandlesProvider$viewModel$2 { super(0); } @Override // kotlin.jvm.functions.Function0 public final SavedStateHandlesVM invoke() { return SavedStateHandleSupport.getSavedStateHandlesVM(ViewModelStoreOwner.this); } }); this.viewModel$delegate = lazy; } private final SavedStateHandlesVM getViewModel() { return (SavedStateHandlesVM) this.viewModel$delegate.getValue(); } @Override // androidx.savedstate.SavedStateRegistry.SavedStateProvider public Bundle saveState() { Bundle bundle = new Bundle(); Bundle bundle2 = this.restoredState; if (bundle2 != null) { bundle.putAll(bundle2); } for (Map.Entry entry : getViewModel().getHandles().entrySet()) { String key = entry.getKey(); Bundle saveState = entry.getValue().savedStateProvider().saveState(); if (!Intrinsics.areEqual(saveState, Bundle.EMPTY)) { bundle.putBundle(key, saveState); } } this.restored = false; return bundle; } public final void performRestore() { if (this.restored) { return; } Bundle consumeRestoredStateForKey = this.savedStateRegistry.consumeRestoredStateForKey("androidx.lifecycle.internal.SavedStateHandlesProvider"); Bundle bundle = new Bundle(); Bundle bundle2 = this.restoredState; if (bundle2 != null) { bundle.putAll(bundle2); } if (consumeRestoredStateForKey != null) { bundle.putAll(consumeRestoredStateForKey); } this.restoredState = bundle; this.restored = true; getViewModel(); } public final Bundle consumeRestoredStateForKey(String key) { Intrinsics.checkNotNullParameter(key, "key"); performRestore(); Bundle bundle = this.restoredState; Bundle bundle2 = bundle != null ? bundle.getBundle(key) : null; Bundle bundle3 = this.restoredState; if (bundle3 != null) { bundle3.remove(key); } Bundle bundle4 = this.restoredState; if (bundle4 != null && bundle4.isEmpty()) { this.restoredState = null; } return bundle2; } }