package androidx.lifecycle; import android.os.Bundle; import androidx.savedstate.SavedStateRegistry; import java.util.Map; import kotlin.Lazy; import kotlin.LazyKt; import kotlin.Metadata; import kotlin.jvm.functions.Function0; import kotlin.jvm.internal.Intrinsics; /* compiled from: SavedStateHandleSupport.kt */ @Metadata(d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\b\u0000\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\u0010\u0010\u0011\u001a\u0004\u0018\u00010\n2\u0006\u0010\u0012\u001a\u00020\u0013J\u0006\u0010\u0014\u001a\u00020\u0015J\b\u0010\u0016\u001a\u00020\nH\u0016R\u000e\u0010\u0007\u001a\u00020\bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\t\u001a\u0004\u0018\u00010\nX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u001b\u0010\u000b\u001a\u00020\f8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b\u000f\u0010\u0010\u001a\u0004\b\r\u0010\u000e¨\u0006\u0017"}, d2 = {"Landroidx/lifecycle/SavedStateHandlesProvider;", "Landroidx/savedstate/SavedStateRegistry$SavedStateProvider;", "savedStateRegistry", "Landroidx/savedstate/SavedStateRegistry;", "viewModelStoreOwner", "Landroidx/lifecycle/ViewModelStoreOwner;", "(Landroidx/savedstate/SavedStateRegistry;Landroidx/lifecycle/ViewModelStoreOwner;)V", "restored", "", "restoredState", "Landroid/os/Bundle;", "viewModel", "Landroidx/lifecycle/SavedStateHandlesVM;", "getViewModel", "()Landroidx/lifecycle/SavedStateHandlesVM;", "viewModel$delegate", "Lkotlin/Lazy;", "consumeRestoredStateForKey", "key", "", "performRestore", "", "saveState", "lifecycle-viewmodel-savedstate_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes2.dex */ public final class SavedStateHandlesProvider implements SavedStateRegistry.SavedStateProvider { private boolean restored; private Bundle restoredState; private final SavedStateRegistry savedStateRegistry; /* renamed from: viewModel$delegate, reason: from kotlin metadata */ private final Lazy viewModel; public SavedStateHandlesProvider(SavedStateRegistry savedStateRegistry, final ViewModelStoreOwner viewModelStoreOwner) { Intrinsics.checkNotNullParameter(savedStateRegistry, "savedStateRegistry"); Intrinsics.checkNotNullParameter(viewModelStoreOwner, "viewModelStoreOwner"); this.savedStateRegistry = savedStateRegistry; this.viewModel = LazyKt.lazy(new Function0() { // from class: androidx.lifecycle.SavedStateHandlesProvider$viewModel$2 /* JADX INFO: Access modifiers changed from: package-private */ { super(0); } /* JADX WARN: Can't rename method to resolve collision */ @Override // kotlin.jvm.functions.Function0 public final SavedStateHandlesVM invoke() { return SavedStateHandleSupport.getSavedStateHandlesVM(ViewModelStoreOwner.this); } }); } private final SavedStateHandlesVM getViewModel() { return (SavedStateHandlesVM) this.viewModel.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().getSavedStateProvider().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; } }