Rabbit-R1/switch port/java/sources/androidx/fragment/app/FragmentManager.java
2024-05-21 17:08:36 -04:00

2563 lines
110 KiB
Java

package androidx.fragment.app;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentSender;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.activity.OnBackPressedCallback;
import androidx.activity.OnBackPressedDispatcher;
import androidx.activity.OnBackPressedDispatcherOwner;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.ActivityResultRegistry;
import androidx.activity.result.ActivityResultRegistryOwner;
import androidx.activity.result.IntentSenderRequest;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.app.MultiWindowModeChangedInfo;
import androidx.core.app.OnMultiWindowModeChangedProvider;
import androidx.core.app.OnPictureInPictureModeChangedProvider;
import androidx.core.app.PictureInPictureModeChangedInfo;
import androidx.core.content.OnConfigurationChangedProvider;
import androidx.core.content.OnTrimMemoryProvider;
import androidx.core.util.Consumer;
import androidx.core.view.MenuHost;
import androidx.core.view.MenuProvider;
import androidx.fragment.R;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.strictmode.FragmentStrictMode;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.savedstate.SavedStateRegistry;
import androidx.savedstate.SavedStateRegistryOwner;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes2.dex */
public abstract class FragmentManager implements FragmentResultOwner {
private static boolean DEBUG = false;
private static final String EXTRA_CREATED_FILLIN_INTENT = "androidx.fragment.extra.ACTIVITY_OPTIONS_BUNDLE";
private static final String FRAGMENT_KEY_PREFIX = "fragment_";
private static final String FRAGMENT_MANAGER_STATE_KEY = "state";
public static final int POP_BACK_STACK_INCLUSIVE = 1;
private static final String RESULT_KEY_PREFIX = "result_";
private static final String SAVED_STATE_KEY = "android:support:fragments";
public static final String TAG = "FragmentManager";
ArrayList<BackStackRecord> mBackStack;
private ArrayList<OnBackStackChangedListener> mBackStackChangeListeners;
private FragmentContainer mContainer;
private ArrayList<Fragment> mCreatedMenus;
private boolean mDestroyed;
private boolean mExecutingActions;
private boolean mHavePendingDeferredStart;
private FragmentHostCallback<?> mHost;
private boolean mNeedMenuInvalidate;
private FragmentManagerViewModel mNonConfig;
private OnBackPressedDispatcher mOnBackPressedDispatcher;
private Fragment mParent;
Fragment mPrimaryNav;
private ActivityResultLauncher<String[]> mRequestPermissions;
private ActivityResultLauncher<Intent> mStartActivityForResult;
private ActivityResultLauncher<IntentSenderRequest> mStartIntentSenderForResult;
private boolean mStateSaved;
private boolean mStopped;
private FragmentStrictMode.Policy mStrictModePolicy;
private ArrayList<Fragment> mTmpAddedFragments;
private ArrayList<Boolean> mTmpIsPop;
private ArrayList<BackStackRecord> mTmpRecords;
private final ArrayList<OpGenerator> mPendingActions = new ArrayList<>();
private final FragmentStore mFragmentStore = new FragmentStore();
private final FragmentLayoutInflaterFactory mLayoutInflaterFactory = new FragmentLayoutInflaterFactory(this);
private final OnBackPressedCallback mOnBackPressedCallback = new OnBackPressedCallback(false) { // from class: androidx.fragment.app.FragmentManager.1
@Override // androidx.activity.OnBackPressedCallback
public void handleOnBackPressed() {
FragmentManager.this.handleOnBackPressed();
}
};
private final AtomicInteger mBackStackIndex = new AtomicInteger();
private final Map<String, BackStackState> mBackStackStates = Collections.synchronizedMap(new HashMap());
private final Map<String, Bundle> mResults = Collections.synchronizedMap(new HashMap());
private final Map<String, LifecycleAwareResultListener> mResultListeners = Collections.synchronizedMap(new HashMap());
private final FragmentLifecycleCallbacksDispatcher mLifecycleCallbacksDispatcher = new FragmentLifecycleCallbacksDispatcher(this);
private final CopyOnWriteArrayList<FragmentOnAttachListener> mOnAttachListeners = new CopyOnWriteArrayList<>();
private final Consumer<Configuration> mOnConfigurationChangedListener = new Consumer() { // from class: androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda0
@Override // androidx.core.util.Consumer
public final void accept(Object obj) {
FragmentManager.this.m5171lambda$new$0$androidxfragmentappFragmentManager((Configuration) obj);
}
};
private final Consumer<Integer> mOnTrimMemoryListener = new Consumer() { // from class: androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda1
@Override // androidx.core.util.Consumer
public final void accept(Object obj) {
FragmentManager.this.m5172lambda$new$1$androidxfragmentappFragmentManager((Integer) obj);
}
};
private final Consumer<MultiWindowModeChangedInfo> mOnMultiWindowModeChangedListener = new Consumer() { // from class: androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda2
@Override // androidx.core.util.Consumer
public final void accept(Object obj) {
FragmentManager.this.m5173lambda$new$2$androidxfragmentappFragmentManager((MultiWindowModeChangedInfo) obj);
}
};
private final Consumer<PictureInPictureModeChangedInfo> mOnPictureInPictureModeChangedListener = new Consumer() { // from class: androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda3
@Override // androidx.core.util.Consumer
public final void accept(Object obj) {
FragmentManager.this.m5174lambda$new$3$androidxfragmentappFragmentManager((PictureInPictureModeChangedInfo) obj);
}
};
private final MenuProvider mMenuProvider = new MenuProvider() { // from class: androidx.fragment.app.FragmentManager.2
@Override // androidx.core.view.MenuProvider
public void onPrepareMenu(Menu menu) {
FragmentManager.this.dispatchPrepareOptionsMenu(menu);
}
@Override // androidx.core.view.MenuProvider
public void onCreateMenu(Menu menu, MenuInflater menuInflater) {
FragmentManager.this.dispatchCreateOptionsMenu(menu, menuInflater);
}
@Override // androidx.core.view.MenuProvider
public boolean onMenuItemSelected(MenuItem menuItem) {
return FragmentManager.this.dispatchOptionsItemSelected(menuItem);
}
@Override // androidx.core.view.MenuProvider
public void onMenuClosed(Menu menu) {
FragmentManager.this.dispatchOptionsMenuClosed(menu);
}
};
int mCurState = -1;
private FragmentFactory mFragmentFactory = null;
private FragmentFactory mHostFragmentFactory = new FragmentFactory() { // from class: androidx.fragment.app.FragmentManager.3
@Override // androidx.fragment.app.FragmentFactory
public Fragment instantiate(ClassLoader classLoader, String str) {
return FragmentManager.this.getHost().instantiate(FragmentManager.this.getHost().getContext(), str, null);
}
};
private SpecialEffectsControllerFactory mSpecialEffectsControllerFactory = null;
private SpecialEffectsControllerFactory mDefaultSpecialEffectsControllerFactory = new SpecialEffectsControllerFactory() { // from class: androidx.fragment.app.FragmentManager.4
@Override // androidx.fragment.app.SpecialEffectsControllerFactory
public SpecialEffectsController createController(ViewGroup viewGroup) {
return new DefaultSpecialEffectsController(viewGroup);
}
};
ArrayDeque<LaunchedFragmentInfo> mLaunchedFragments = new ArrayDeque<>();
private Runnable mExecCommit = new Runnable() { // from class: androidx.fragment.app.FragmentManager.5
@Override // java.lang.Runnable
public void run() {
FragmentManager.this.execPendingActions(true);
}
};
/* loaded from: classes2.dex */
public interface BackStackEntry {
@Deprecated
CharSequence getBreadCrumbShortTitle();
@Deprecated
int getBreadCrumbShortTitleRes();
@Deprecated
CharSequence getBreadCrumbTitle();
@Deprecated
int getBreadCrumbTitleRes();
int getId();
String getName();
}
/* loaded from: classes2.dex */
public static abstract class FragmentLifecycleCallbacks {
@Deprecated
public void onFragmentActivityCreated(FragmentManager fragmentManager, Fragment fragment, Bundle bundle) {
}
public void onFragmentAttached(FragmentManager fragmentManager, Fragment fragment, Context context) {
}
public void onFragmentCreated(FragmentManager fragmentManager, Fragment fragment, Bundle bundle) {
}
public void onFragmentDestroyed(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentDetached(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentPaused(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentPreAttached(FragmentManager fragmentManager, Fragment fragment, Context context) {
}
public void onFragmentPreCreated(FragmentManager fragmentManager, Fragment fragment, Bundle bundle) {
}
public void onFragmentResumed(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentSaveInstanceState(FragmentManager fragmentManager, Fragment fragment, Bundle bundle) {
}
public void onFragmentStarted(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentStopped(FragmentManager fragmentManager, Fragment fragment) {
}
public void onFragmentViewCreated(FragmentManager fragmentManager, Fragment fragment, View view, Bundle bundle) {
}
public void onFragmentViewDestroyed(FragmentManager fragmentManager, Fragment fragment) {
}
}
/* loaded from: classes2.dex */
public interface OnBackStackChangedListener {
default void onBackStackChangeCommitted(Fragment fragment, boolean z) {
}
default void onBackStackChangeStarted(Fragment fragment, boolean z) {
}
void onBackStackChanged();
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public interface OpGenerator {
boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2);
}
@Deprecated
public static void enableDebugLogging(boolean z) {
DEBUG = z;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static int reverseTransit(int i) {
int i2 = FragmentTransaction.TRANSIT_FRAGMENT_OPEN;
if (i == 4097) {
return 8194;
}
if (i != 8194) {
i2 = FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_CLOSE;
if (i == 8197) {
return FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN;
}
if (i == 4099) {
return FragmentTransaction.TRANSIT_FRAGMENT_FADE;
}
if (i != 4100) {
return 0;
}
}
return i2;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentContainer getContainer() {
return this.mContainer;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentStore getFragmentStore() {
return this.mFragmentStore;
}
public FragmentHostCallback<?> getHost() {
return this.mHost;
}
/* JADX INFO: Access modifiers changed from: package-private */
public LayoutInflater.Factory2 getLayoutInflaterFactory() {
return this.mLayoutInflaterFactory;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentLifecycleCallbacksDispatcher getLifecycleCallbacksDispatcher() {
return this.mLifecycleCallbacksDispatcher;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Fragment getParent() {
return this.mParent;
}
public Fragment getPrimaryNavigationFragment() {
return this.mPrimaryNav;
}
public FragmentStrictMode.Policy getStrictModePolicy() {
return this.mStrictModePolicy;
}
public boolean isDestroyed() {
return this.mDestroyed;
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isStateAtLeast(int i) {
return this.mCurState >= i;
}
public boolean isStateSaved() {
return this.mStateSaved || this.mStopped;
}
public void setFragmentFactory(FragmentFactory fragmentFactory) {
this.mFragmentFactory = fragmentFactory;
}
void setSpecialEffectsControllerFactory(SpecialEffectsControllerFactory specialEffectsControllerFactory) {
this.mSpecialEffectsControllerFactory = specialEffectsControllerFactory;
}
public void setStrictModePolicy(FragmentStrictMode.Policy policy) {
this.mStrictModePolicy = policy;
}
public static boolean isLoggingEnabled(int i) {
return DEBUG || Log.isLoggable(TAG, i);
}
/* loaded from: classes2.dex */
private static class LifecycleAwareResultListener implements FragmentResultListener {
private final Lifecycle mLifecycle;
private final FragmentResultListener mListener;
private final LifecycleEventObserver mObserver;
LifecycleAwareResultListener(Lifecycle lifecycle, FragmentResultListener fragmentResultListener, LifecycleEventObserver lifecycleEventObserver) {
this.mLifecycle = lifecycle;
this.mListener = fragmentResultListener;
this.mObserver = lifecycleEventObserver;
}
public boolean isAtLeast(Lifecycle.State state) {
return this.mLifecycle.getState().isAtLeast(state);
}
@Override // androidx.fragment.app.FragmentResultListener
public void onFragmentResult(String str, Bundle bundle) {
this.mListener.onFragmentResult(str, bundle);
}
public void removeObserver() {
this.mLifecycle.removeObserver(this.mObserver);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$new$0$androidx-fragment-app-FragmentManager, reason: not valid java name */
public /* synthetic */ void m5171lambda$new$0$androidxfragmentappFragmentManager(Configuration configuration) {
if (isParentAdded()) {
dispatchConfigurationChanged(configuration, false);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$new$1$androidx-fragment-app-FragmentManager, reason: not valid java name */
public /* synthetic */ void m5172lambda$new$1$androidxfragmentappFragmentManager(Integer num) {
if (isParentAdded() && num.intValue() == 80) {
dispatchLowMemory(false);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$new$2$androidx-fragment-app-FragmentManager, reason: not valid java name */
public /* synthetic */ void m5173lambda$new$2$androidxfragmentappFragmentManager(MultiWindowModeChangedInfo multiWindowModeChangedInfo) {
if (isParentAdded()) {
dispatchMultiWindowModeChanged(multiWindowModeChangedInfo.isInMultiWindowMode(), false);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$new$3$androidx-fragment-app-FragmentManager, reason: not valid java name */
public /* synthetic */ void m5174lambda$new$3$androidxfragmentappFragmentManager(PictureInPictureModeChangedInfo pictureInPictureModeChangedInfo) {
if (isParentAdded()) {
dispatchPictureInPictureModeChanged(pictureInPictureModeChangedInfo.isInPictureInPictureMode(), false);
}
}
private void throwException(RuntimeException runtimeException) {
Log.e(TAG, runtimeException.getMessage());
Log.e(TAG, "Activity state:");
PrintWriter printWriter = new PrintWriter(new LogWriter(TAG));
FragmentHostCallback<?> fragmentHostCallback = this.mHost;
if (fragmentHostCallback != null) {
try {
fragmentHostCallback.onDump(" ", null, printWriter, new String[0]);
throw runtimeException;
} catch (Exception e) {
Log.e(TAG, "Failed dumping state", e);
throw runtimeException;
}
}
try {
dump(" ", null, printWriter, new String[0]);
throw runtimeException;
} catch (Exception e2) {
Log.e(TAG, "Failed dumping state", e2);
throw runtimeException;
}
}
@Deprecated
public FragmentTransaction openTransaction() {
return beginTransaction();
}
public FragmentTransaction beginTransaction() {
return new BackStackRecord(this);
}
public boolean executePendingTransactions() {
boolean execPendingActions = execPendingActions(true);
forcePostponedTransactions();
return execPendingActions;
}
private void updateOnBackPressedCallbackEnabled() {
synchronized (this.mPendingActions) {
if (!this.mPendingActions.isEmpty()) {
this.mOnBackPressedCallback.setEnabled(true);
} else {
this.mOnBackPressedCallback.setEnabled(getBackStackEntryCount() > 0 && isPrimaryNavigation(this.mParent));
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isPrimaryNavigation(Fragment fragment) {
if (fragment == null) {
return true;
}
FragmentManager fragmentManager = fragment.mFragmentManager;
return fragment.equals(fragmentManager.getPrimaryNavigationFragment()) && isPrimaryNavigation(fragmentManager.mParent);
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isParentMenuVisible(Fragment fragment) {
if (fragment == null) {
return true;
}
return fragment.isMenuVisible();
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean isParentHidden(Fragment fragment) {
if (fragment == null) {
return false;
}
return fragment.isHidden();
}
void handleOnBackPressed() {
execPendingActions(true);
if (this.mOnBackPressedCallback.getIsEnabled()) {
popBackStackImmediate();
} else {
this.mOnBackPressedDispatcher.onBackPressed();
}
}
public void restoreBackStack(String str) {
enqueueAction(new RestoreBackStackState(str), false);
}
public void saveBackStack(String str) {
enqueueAction(new SaveBackStackState(str), false);
}
public void clearBackStack(String str) {
enqueueAction(new ClearBackStackState(str), false);
}
public void popBackStack() {
enqueueAction(new PopBackStackState(null, -1, 0), false);
}
public boolean popBackStackImmediate() {
return popBackStackImmediate(null, -1, 0);
}
public void popBackStack(String str, int i) {
enqueueAction(new PopBackStackState(str, -1, i), false);
}
public boolean popBackStackImmediate(String str, int i) {
return popBackStackImmediate(str, -1, i);
}
public void popBackStack(int i, int i2) {
popBackStack(i, i2, false);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void popBackStack(int i, int i2, boolean z) {
if (i < 0) {
throw new IllegalArgumentException("Bad id: " + i);
}
enqueueAction(new PopBackStackState(null, i, i2), z);
}
public boolean popBackStackImmediate(int i, int i2) {
if (i < 0) {
throw new IllegalArgumentException("Bad id: " + i);
}
return popBackStackImmediate(null, i, i2);
}
private boolean popBackStackImmediate(String str, int i, int i2) {
execPendingActions(false);
ensureExecReady(true);
Fragment fragment = this.mPrimaryNav;
if (fragment != null && i < 0 && str == null && fragment.getChildFragmentManager().popBackStackImmediate()) {
return true;
}
boolean popBackStackState = popBackStackState(this.mTmpRecords, this.mTmpIsPop, str, i, i2);
if (popBackStackState) {
this.mExecutingActions = true;
try {
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
} finally {
cleanupExec();
}
}
updateOnBackPressedCallbackEnabled();
doPendingDeferredStart();
this.mFragmentStore.burpActive();
return popBackStackState;
}
public int getBackStackEntryCount() {
ArrayList<BackStackRecord> arrayList = this.mBackStack;
if (arrayList != null) {
return arrayList.size();
}
return 0;
}
public BackStackEntry getBackStackEntryAt(int i) {
return this.mBackStack.get(i);
}
public void addOnBackStackChangedListener(OnBackStackChangedListener onBackStackChangedListener) {
if (this.mBackStackChangeListeners == null) {
this.mBackStackChangeListeners = new ArrayList<>();
}
this.mBackStackChangeListeners.add(onBackStackChangedListener);
}
public void removeOnBackStackChangedListener(OnBackStackChangedListener onBackStackChangedListener) {
ArrayList<OnBackStackChangedListener> arrayList = this.mBackStackChangeListeners;
if (arrayList != null) {
arrayList.remove(onBackStackChangedListener);
}
}
@Override // androidx.fragment.app.FragmentResultOwner
public final void setFragmentResult(String str, Bundle bundle) {
LifecycleAwareResultListener lifecycleAwareResultListener = this.mResultListeners.get(str);
if (lifecycleAwareResultListener != null && lifecycleAwareResultListener.isAtLeast(Lifecycle.State.STARTED)) {
lifecycleAwareResultListener.onFragmentResult(str, bundle);
} else {
this.mResults.put(str, bundle);
}
if (isLoggingEnabled(2)) {
Log.v(TAG, "Setting fragment result with key " + str + " and result " + bundle);
}
}
@Override // androidx.fragment.app.FragmentResultOwner
public final void clearFragmentResult(String str) {
this.mResults.remove(str);
if (isLoggingEnabled(2)) {
Log.v(TAG, "Clearing fragment result with key " + str);
}
}
@Override // androidx.fragment.app.FragmentResultOwner
public final void setFragmentResultListener(final String str, LifecycleOwner lifecycleOwner, final FragmentResultListener fragmentResultListener) {
final Lifecycle lifecycle = lifecycleOwner.getLifecycle();
if (lifecycle.getState() == Lifecycle.State.DESTROYED) {
return;
}
LifecycleEventObserver lifecycleEventObserver = new LifecycleEventObserver() { // from class: androidx.fragment.app.FragmentManager.6
@Override // androidx.lifecycle.LifecycleEventObserver
public void onStateChanged(LifecycleOwner lifecycleOwner2, Lifecycle.Event event) {
Bundle bundle;
if (event == Lifecycle.Event.ON_START && (bundle = (Bundle) FragmentManager.this.mResults.get(str)) != null) {
fragmentResultListener.onFragmentResult(str, bundle);
FragmentManager.this.clearFragmentResult(str);
}
if (event == Lifecycle.Event.ON_DESTROY) {
lifecycle.removeObserver(this);
FragmentManager.this.mResultListeners.remove(str);
}
}
};
LifecycleAwareResultListener put = this.mResultListeners.put(str, new LifecycleAwareResultListener(lifecycle, fragmentResultListener, lifecycleEventObserver));
if (put != null) {
put.removeObserver();
}
if (isLoggingEnabled(2)) {
Log.v(TAG, "Setting FragmentResultListener with key " + str + " lifecycleOwner " + lifecycle + " and listener " + fragmentResultListener);
}
lifecycle.addObserver(lifecycleEventObserver);
}
@Override // androidx.fragment.app.FragmentResultOwner
public final void clearFragmentResultListener(String str) {
LifecycleAwareResultListener remove = this.mResultListeners.remove(str);
if (remove != null) {
remove.removeObserver();
}
if (isLoggingEnabled(2)) {
Log.v(TAG, "Clearing FragmentResultListener for key " + str);
}
}
public void putFragment(Bundle bundle, String str, Fragment fragment) {
if (fragment.mFragmentManager != this) {
throwException(new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager"));
}
bundle.putString(str, fragment.mWho);
}
public Fragment getFragment(Bundle bundle, String str) {
String string = bundle.getString(str);
if (string == null) {
return null;
}
Fragment findActiveFragment = findActiveFragment(string);
if (findActiveFragment == null) {
throwException(new IllegalStateException("Fragment no longer exists for key " + str + ": unique id " + string));
}
return findActiveFragment;
}
public static <F extends Fragment> F findFragment(View view) {
F f = (F) findViewFragment(view);
if (f != null) {
return f;
}
throw new IllegalStateException("View " + view + " does not have a Fragment set");
}
/* JADX INFO: Access modifiers changed from: package-private */
public static Fragment findViewFragment(View view) {
while (view != null) {
Fragment viewFragment = getViewFragment(view);
if (viewFragment != null) {
return viewFragment;
}
Object parent = view.getParent();
view = parent instanceof View ? (View) parent : null;
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static Fragment getViewFragment(View view) {
Object tag = view.getTag(R.id.fragment_container_view_tag);
if (tag instanceof Fragment) {
return (Fragment) tag;
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void onContainerAvailable(FragmentContainerView fragmentContainerView) {
for (FragmentStateManager fragmentStateManager : this.mFragmentStore.getActiveFragmentStateManagers()) {
Fragment fragment = fragmentStateManager.getFragment();
if (fragment.mContainerId == fragmentContainerView.getId() && fragment.mView != null && fragment.mView.getParent() == null) {
fragment.mContainer = fragmentContainerView;
fragmentStateManager.addViewToContainer();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static FragmentManager findFragmentManager(View view) {
FragmentActivity fragmentActivity;
Fragment findViewFragment = findViewFragment(view);
if (findViewFragment != null) {
if (!findViewFragment.isAdded()) {
throw new IllegalStateException("The Fragment " + findViewFragment + " that owns View " + view + " has already been destroyed. Nested fragments should always use the child FragmentManager.");
}
return findViewFragment.getChildFragmentManager();
}
Context context = view.getContext();
while (true) {
if (!(context instanceof ContextWrapper)) {
fragmentActivity = null;
break;
}
if (context instanceof FragmentActivity) {
fragmentActivity = (FragmentActivity) context;
break;
}
context = ((ContextWrapper) context).getBaseContext();
}
if (fragmentActivity != null) {
return fragmentActivity.getSupportFragmentManager();
}
throw new IllegalStateException("View " + view + " is not within a subclass of FragmentActivity.");
}
public List<Fragment> getFragments() {
return this.mFragmentStore.getFragments();
}
/* JADX INFO: Access modifiers changed from: package-private */
public ViewModelStore getViewModelStore(Fragment fragment) {
return this.mNonConfig.getViewModelStore(fragment);
}
private FragmentManagerViewModel getChildNonConfig(Fragment fragment) {
return this.mNonConfig.getChildNonConfig(fragment);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void addRetainedFragment(Fragment fragment) {
this.mNonConfig.addRetainedFragment(fragment);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void removeRetainedFragment(Fragment fragment) {
this.mNonConfig.removeRetainedFragment(fragment);
}
/* JADX INFO: Access modifiers changed from: package-private */
public List<Fragment> getActiveFragments() {
return this.mFragmentStore.getActiveFragments();
}
/* JADX INFO: Access modifiers changed from: package-private */
public int getActiveFragmentCount() {
return this.mFragmentStore.getActiveFragmentCount();
}
public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) {
FragmentStateManager fragmentStateManager = this.mFragmentStore.getFragmentStateManager(fragment.mWho);
if (fragmentStateManager == null || !fragmentStateManager.getFragment().equals(fragment)) {
throwException(new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager"));
}
return fragmentStateManager.saveInstanceState();
}
/* JADX WARN: Removed duplicated region for block: B:8:0x0039 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private void clearBackStackStateViewModels() {
/*
r4 = this;
androidx.fragment.app.FragmentHostCallback<?> r0 = r4.mHost
boolean r1 = r0 instanceof androidx.lifecycle.ViewModelStoreOwner
if (r1 == 0) goto L11
androidx.fragment.app.FragmentStore r0 = r4.mFragmentStore
androidx.fragment.app.FragmentManagerViewModel r0 = r0.getNonConfig()
boolean r0 = r0.isCleared()
goto L27
L11:
android.content.Context r0 = r0.getContext()
boolean r0 = r0 instanceof android.app.Activity
if (r0 == 0) goto L29
androidx.fragment.app.FragmentHostCallback<?> r0 = r4.mHost
android.content.Context r0 = r0.getContext()
android.app.Activity r0 = (android.app.Activity) r0
boolean r0 = r0.isChangingConfigurations()
r0 = r0 ^ 1
L27:
if (r0 == 0) goto L5b
L29:
java.util.Map<java.lang.String, androidx.fragment.app.BackStackState> r0 = r4.mBackStackStates
java.util.Collection r0 = r0.values()
java.util.Iterator r0 = r0.iterator()
L33:
boolean r1 = r0.hasNext()
if (r1 == 0) goto L5b
java.lang.Object r1 = r0.next()
androidx.fragment.app.BackStackState r1 = (androidx.fragment.app.BackStackState) r1
java.util.List<java.lang.String> r1 = r1.mFragments
java.util.Iterator r1 = r1.iterator()
L45:
boolean r2 = r1.hasNext()
if (r2 == 0) goto L33
java.lang.Object r2 = r1.next()
java.lang.String r2 = (java.lang.String) r2
androidx.fragment.app.FragmentStore r3 = r4.mFragmentStore
androidx.fragment.app.FragmentManagerViewModel r3 = r3.getNonConfig()
r3.clearNonConfigState(r2)
goto L45
L5b:
return
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.FragmentManager.clearBackStackStateViewModels():void");
}
public String toString() {
StringBuilder sb = new StringBuilder(128);
sb.append("FragmentManager{");
sb.append(Integer.toHexString(System.identityHashCode(this)));
sb.append(" in ");
Fragment fragment = this.mParent;
if (fragment != null) {
sb.append(fragment.getClass().getSimpleName());
sb.append("{");
sb.append(Integer.toHexString(System.identityHashCode(this.mParent)));
sb.append("}");
} else {
FragmentHostCallback<?> fragmentHostCallback = this.mHost;
if (fragmentHostCallback != null) {
sb.append(fragmentHostCallback.getClass().getSimpleName());
sb.append("{");
sb.append(Integer.toHexString(System.identityHashCode(this.mHost)));
sb.append("}");
} else {
sb.append("null");
}
}
sb.append("}}");
return sb.toString();
}
public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
int size;
int size2;
String str2 = str + " ";
this.mFragmentStore.dump(str, fileDescriptor, printWriter, strArr);
ArrayList<Fragment> arrayList = this.mCreatedMenus;
if (arrayList != null && (size2 = arrayList.size()) > 0) {
printWriter.print(str);
printWriter.println("Fragments Created Menus:");
for (int i = 0; i < size2; i++) {
Fragment fragment = this.mCreatedMenus.get(i);
printWriter.print(str);
printWriter.print(" #");
printWriter.print(i);
printWriter.print(": ");
printWriter.println(fragment.toString());
}
}
ArrayList<BackStackRecord> arrayList2 = this.mBackStack;
if (arrayList2 != null && (size = arrayList2.size()) > 0) {
printWriter.print(str);
printWriter.println("Back Stack:");
for (int i2 = 0; i2 < size; i2++) {
BackStackRecord backStackRecord = this.mBackStack.get(i2);
printWriter.print(str);
printWriter.print(" #");
printWriter.print(i2);
printWriter.print(": ");
printWriter.println(backStackRecord.toString());
backStackRecord.dump(str2, printWriter);
}
}
printWriter.print(str);
printWriter.println("Back Stack Index: " + this.mBackStackIndex.get());
synchronized (this.mPendingActions) {
int size3 = this.mPendingActions.size();
if (size3 > 0) {
printWriter.print(str);
printWriter.println("Pending Actions:");
for (int i3 = 0; i3 < size3; i3++) {
OpGenerator opGenerator = this.mPendingActions.get(i3);
printWriter.print(str);
printWriter.print(" #");
printWriter.print(i3);
printWriter.print(": ");
printWriter.println(opGenerator);
}
}
}
printWriter.print(str);
printWriter.println("FragmentManager misc state:");
printWriter.print(str);
printWriter.print(" mHost=");
printWriter.println(this.mHost);
printWriter.print(str);
printWriter.print(" mContainer=");
printWriter.println(this.mContainer);
if (this.mParent != null) {
printWriter.print(str);
printWriter.print(" mParent=");
printWriter.println(this.mParent);
}
printWriter.print(str);
printWriter.print(" mCurState=");
printWriter.print(this.mCurState);
printWriter.print(" mStateSaved=");
printWriter.print(this.mStateSaved);
printWriter.print(" mStopped=");
printWriter.print(this.mStopped);
printWriter.print(" mDestroyed=");
printWriter.println(this.mDestroyed);
if (this.mNeedMenuInvalidate) {
printWriter.print(str);
printWriter.print(" mNeedMenuInvalidate=");
printWriter.println(this.mNeedMenuInvalidate);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void performPendingDeferredStart(FragmentStateManager fragmentStateManager) {
Fragment fragment = fragmentStateManager.getFragment();
if (fragment.mDeferStart) {
if (this.mExecutingActions) {
this.mHavePendingDeferredStart = true;
} else {
fragment.mDeferStart = false;
fragmentStateManager.moveToExpectedState();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void setExitAnimationOrder(Fragment fragment, boolean z) {
ViewGroup fragmentContainer = getFragmentContainer(fragment);
if (fragmentContainer == null || !(fragmentContainer instanceof FragmentContainerView)) {
return;
}
((FragmentContainerView) fragmentContainer).setDrawDisappearingViewsLast(!z);
}
void moveToState(int i, boolean z) {
FragmentHostCallback<?> fragmentHostCallback;
if (this.mHost == null && i != -1) {
throw new IllegalStateException("No activity");
}
if (z || i != this.mCurState) {
this.mCurState = i;
this.mFragmentStore.moveToExpectedState();
startPendingDeferredFragments();
if (this.mNeedMenuInvalidate && (fragmentHostCallback = this.mHost) != null && this.mCurState == 7) {
fragmentHostCallback.onSupportInvalidateOptionsMenu();
this.mNeedMenuInvalidate = false;
}
}
}
private void startPendingDeferredFragments() {
Iterator<FragmentStateManager> it = this.mFragmentStore.getActiveFragmentStateManagers().iterator();
while (it.hasNext()) {
performPendingDeferredStart(it.next());
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentStateManager createOrGetFragmentStateManager(Fragment fragment) {
FragmentStateManager fragmentStateManager = this.mFragmentStore.getFragmentStateManager(fragment.mWho);
if (fragmentStateManager != null) {
return fragmentStateManager;
}
FragmentStateManager fragmentStateManager2 = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, fragment);
fragmentStateManager2.restoreState(this.mHost.getContext().getClassLoader());
fragmentStateManager2.setFragmentManagerState(this.mCurState);
return fragmentStateManager2;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentStateManager addFragment(Fragment fragment) {
if (fragment.mPreviousWho != null) {
FragmentStrictMode.onFragmentReuse(fragment, fragment.mPreviousWho);
}
if (isLoggingEnabled(2)) {
Log.v(TAG, "add: " + fragment);
}
FragmentStateManager createOrGetFragmentStateManager = createOrGetFragmentStateManager(fragment);
fragment.mFragmentManager = this;
this.mFragmentStore.makeActive(createOrGetFragmentStateManager);
if (!fragment.mDetached) {
this.mFragmentStore.addFragment(fragment);
fragment.mRemoving = false;
if (fragment.mView == null) {
fragment.mHiddenChanged = false;
}
if (isMenuAvailable(fragment)) {
this.mNeedMenuInvalidate = true;
}
}
return createOrGetFragmentStateManager;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void removeFragment(Fragment fragment) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting);
}
boolean z = !fragment.isInBackStack();
if (!fragment.mDetached || z) {
this.mFragmentStore.removeFragment(fragment);
if (isMenuAvailable(fragment)) {
this.mNeedMenuInvalidate = true;
}
fragment.mRemoving = true;
setVisibleRemovingFragment(fragment);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void hideFragment(Fragment fragment) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "hide: " + fragment);
}
if (fragment.mHidden) {
return;
}
fragment.mHidden = true;
fragment.mHiddenChanged = true ^ fragment.mHiddenChanged;
setVisibleRemovingFragment(fragment);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void showFragment(Fragment fragment) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "show: " + fragment);
}
if (fragment.mHidden) {
fragment.mHidden = false;
fragment.mHiddenChanged = !fragment.mHiddenChanged;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void detachFragment(Fragment fragment) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "detach: " + fragment);
}
if (fragment.mDetached) {
return;
}
fragment.mDetached = true;
if (fragment.mAdded) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "remove from detach: " + fragment);
}
this.mFragmentStore.removeFragment(fragment);
if (isMenuAvailable(fragment)) {
this.mNeedMenuInvalidate = true;
}
setVisibleRemovingFragment(fragment);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void attachFragment(Fragment fragment) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "attach: " + fragment);
}
if (fragment.mDetached) {
fragment.mDetached = false;
if (fragment.mAdded) {
return;
}
this.mFragmentStore.addFragment(fragment);
if (isLoggingEnabled(2)) {
Log.v(TAG, "add from attach: " + fragment);
}
if (isMenuAvailable(fragment)) {
this.mNeedMenuInvalidate = true;
}
}
}
public Fragment findFragmentById(int i) {
return this.mFragmentStore.findFragmentById(i);
}
public Fragment findFragmentByTag(String str) {
return this.mFragmentStore.findFragmentByTag(str);
}
/* JADX INFO: Access modifiers changed from: package-private */
public Fragment findFragmentByWho(String str) {
return this.mFragmentStore.findFragmentByWho(str);
}
/* JADX INFO: Access modifiers changed from: package-private */
public Fragment findActiveFragment(String str) {
return this.mFragmentStore.findActiveFragment(str);
}
private void checkStateLoss() {
if (isStateSaved()) {
throw new IllegalStateException("Can not perform this action after onSaveInstanceState");
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void enqueueAction(OpGenerator opGenerator, boolean z) {
if (!z) {
if (this.mHost == null) {
if (this.mDestroyed) {
throw new IllegalStateException("FragmentManager has been destroyed");
}
throw new IllegalStateException("FragmentManager has not been attached to a host.");
}
checkStateLoss();
}
synchronized (this.mPendingActions) {
if (this.mHost == null) {
if (!z) {
throw new IllegalStateException("Activity has been destroyed");
}
} else {
this.mPendingActions.add(opGenerator);
scheduleCommit();
}
}
}
void scheduleCommit() {
synchronized (this.mPendingActions) {
if (this.mPendingActions.size() == 1) {
this.mHost.getHandler().removeCallbacks(this.mExecCommit);
this.mHost.getHandler().post(this.mExecCommit);
updateOnBackPressedCallbackEnabled();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public int allocBackStackIndex() {
return this.mBackStackIndex.getAndIncrement();
}
private void ensureExecReady(boolean z) {
if (this.mExecutingActions) {
throw new IllegalStateException("FragmentManager is already executing transactions");
}
if (this.mHost == null) {
if (this.mDestroyed) {
throw new IllegalStateException("FragmentManager has been destroyed");
}
throw new IllegalStateException("FragmentManager has not been attached to a host.");
}
if (Looper.myLooper() != this.mHost.getHandler().getLooper()) {
throw new IllegalStateException("Must be called from main thread of fragment host");
}
if (!z) {
checkStateLoss();
}
if (this.mTmpRecords == null) {
this.mTmpRecords = new ArrayList<>();
this.mTmpIsPop = new ArrayList<>();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void execSingleAction(OpGenerator opGenerator, boolean z) {
if (z && (this.mHost == null || this.mDestroyed)) {
return;
}
ensureExecReady(z);
if (opGenerator.generateOps(this.mTmpRecords, this.mTmpIsPop)) {
this.mExecutingActions = true;
try {
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
} finally {
cleanupExec();
}
}
updateOnBackPressedCallbackEnabled();
doPendingDeferredStart();
this.mFragmentStore.burpActive();
}
private void cleanupExec() {
this.mExecutingActions = false;
this.mTmpIsPop.clear();
this.mTmpRecords.clear();
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean execPendingActions(boolean z) {
ensureExecReady(z);
boolean z2 = false;
while (generateOpsForPendingActions(this.mTmpRecords, this.mTmpIsPop)) {
z2 = true;
this.mExecutingActions = true;
try {
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
} finally {
cleanupExec();
}
}
updateOnBackPressedCallbackEnabled();
doPendingDeferredStart();
this.mFragmentStore.burpActive();
return z2;
}
private void removeRedundantOperationsAndExecute(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
if (arrayList.isEmpty()) {
return;
}
if (arrayList.size() != arrayList2.size()) {
throw new IllegalStateException("Internal error with the back stack records");
}
int size = arrayList.size();
int i = 0;
int i2 = 0;
while (i < size) {
if (!arrayList.get(i).mReorderingAllowed) {
if (i2 != i) {
executeOpsTogether(arrayList, arrayList2, i2, i);
}
i2 = i + 1;
if (arrayList2.get(i).booleanValue()) {
while (i2 < size && arrayList2.get(i2).booleanValue() && !arrayList.get(i2).mReorderingAllowed) {
i2++;
}
}
executeOpsTogether(arrayList, arrayList2, i, i2);
i = i2 - 1;
}
i++;
}
if (i2 != size) {
executeOpsTogether(arrayList, arrayList2, i2, size);
}
}
private void executeOpsTogether(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, int i, int i2) {
ArrayList<OnBackStackChangedListener> arrayList3;
boolean z = arrayList.get(i).mReorderingAllowed;
ArrayList<Fragment> arrayList4 = this.mTmpAddedFragments;
if (arrayList4 == null) {
this.mTmpAddedFragments = new ArrayList<>();
} else {
arrayList4.clear();
}
this.mTmpAddedFragments.addAll(this.mFragmentStore.getFragments());
Fragment primaryNavigationFragment = getPrimaryNavigationFragment();
boolean z2 = false;
for (int i3 = i; i3 < i2; i3++) {
BackStackRecord backStackRecord = arrayList.get(i3);
if (!arrayList2.get(i3).booleanValue()) {
primaryNavigationFragment = backStackRecord.expandOps(this.mTmpAddedFragments, primaryNavigationFragment);
} else {
primaryNavigationFragment = backStackRecord.trackAddedFragmentsInPop(this.mTmpAddedFragments, primaryNavigationFragment);
}
z2 = z2 || backStackRecord.mAddToBackStack;
}
this.mTmpAddedFragments.clear();
if (!z && this.mCurState >= 1) {
for (int i4 = i; i4 < i2; i4++) {
Iterator<FragmentTransaction.Op> it = arrayList.get(i4).mOps.iterator();
while (it.hasNext()) {
Fragment fragment = it.next().mFragment;
if (fragment != null && fragment.mFragmentManager != null) {
this.mFragmentStore.makeActive(createOrGetFragmentStateManager(fragment));
}
}
}
}
executeOps(arrayList, arrayList2, i, i2);
boolean booleanValue = arrayList2.get(i2 - 1).booleanValue();
if (z2 && (arrayList3 = this.mBackStackChangeListeners) != null && !arrayList3.isEmpty()) {
LinkedHashSet linkedHashSet = new LinkedHashSet();
Iterator<BackStackRecord> it2 = arrayList.iterator();
while (it2.hasNext()) {
linkedHashSet.addAll(fragmentsFromRecord(it2.next()));
}
Iterator<OnBackStackChangedListener> it3 = this.mBackStackChangeListeners.iterator();
while (it3.hasNext()) {
OnBackStackChangedListener next = it3.next();
Iterator it4 = linkedHashSet.iterator();
while (it4.hasNext()) {
next.onBackStackChangeStarted((Fragment) it4.next(), booleanValue);
}
}
Iterator<OnBackStackChangedListener> it5 = this.mBackStackChangeListeners.iterator();
while (it5.hasNext()) {
OnBackStackChangedListener next2 = it5.next();
Iterator it6 = linkedHashSet.iterator();
while (it6.hasNext()) {
next2.onBackStackChangeCommitted((Fragment) it6.next(), booleanValue);
}
}
}
for (int i5 = i; i5 < i2; i5++) {
BackStackRecord backStackRecord2 = arrayList.get(i5);
if (booleanValue) {
for (int size = backStackRecord2.mOps.size() - 1; size >= 0; size--) {
Fragment fragment2 = backStackRecord2.mOps.get(size).mFragment;
if (fragment2 != null) {
createOrGetFragmentStateManager(fragment2).moveToExpectedState();
}
}
} else {
Iterator<FragmentTransaction.Op> it7 = backStackRecord2.mOps.iterator();
while (it7.hasNext()) {
Fragment fragment3 = it7.next().mFragment;
if (fragment3 != null) {
createOrGetFragmentStateManager(fragment3).moveToExpectedState();
}
}
}
}
moveToState(this.mCurState, true);
for (SpecialEffectsController specialEffectsController : collectChangedControllers(arrayList, i, i2)) {
specialEffectsController.updateOperationDirection(booleanValue);
specialEffectsController.markPostponedState();
specialEffectsController.executePendingOperations();
}
while (i < i2) {
BackStackRecord backStackRecord3 = arrayList.get(i);
if (arrayList2.get(i).booleanValue() && backStackRecord3.mIndex >= 0) {
backStackRecord3.mIndex = -1;
}
backStackRecord3.runOnCommitRunnables();
i++;
}
if (z2) {
reportBackStackChanged();
}
}
private Set<SpecialEffectsController> collectChangedControllers(ArrayList<BackStackRecord> arrayList, int i, int i2) {
ViewGroup viewGroup;
HashSet hashSet = new HashSet();
while (i < i2) {
Iterator<FragmentTransaction.Op> it = arrayList.get(i).mOps.iterator();
while (it.hasNext()) {
Fragment fragment = it.next().mFragment;
if (fragment != null && (viewGroup = fragment.mContainer) != null) {
hashSet.add(SpecialEffectsController.getOrCreateController(viewGroup, this));
}
}
i++;
}
return hashSet;
}
private static void executeOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, int i, int i2) {
while (i < i2) {
BackStackRecord backStackRecord = arrayList.get(i);
if (arrayList2.get(i).booleanValue()) {
backStackRecord.bumpBackStackNesting(-1);
backStackRecord.executePopOps();
} else {
backStackRecord.bumpBackStackNesting(1);
backStackRecord.executeOps();
}
i++;
}
}
private void setVisibleRemovingFragment(Fragment fragment) {
ViewGroup fragmentContainer = getFragmentContainer(fragment);
if (fragmentContainer == null || fragment.getEnterAnim() + fragment.getExitAnim() + fragment.getPopEnterAnim() + fragment.getPopExitAnim() <= 0) {
return;
}
if (fragmentContainer.getTag(R.id.visible_removing_fragment_view_tag) == null) {
fragmentContainer.setTag(R.id.visible_removing_fragment_view_tag, fragment);
}
((Fragment) fragmentContainer.getTag(R.id.visible_removing_fragment_view_tag)).setPopDirection(fragment.getPopDirection());
}
private ViewGroup getFragmentContainer(Fragment fragment) {
if (fragment.mContainer != null) {
return fragment.mContainer;
}
if (fragment.mContainerId > 0 && this.mContainer.onHasView()) {
View onFindViewById = this.mContainer.onFindViewById(fragment.mContainerId);
if (onFindViewById instanceof ViewGroup) {
return (ViewGroup) onFindViewById;
}
}
return null;
}
private void forcePostponedTransactions() {
Iterator<SpecialEffectsController> it = collectAllSpecialEffectsController().iterator();
while (it.hasNext()) {
it.next().forcePostponedExecutePendingOperations();
}
}
private void endAnimatingAwayFragments() {
Iterator<SpecialEffectsController> it = collectAllSpecialEffectsController().iterator();
while (it.hasNext()) {
it.next().forceCompleteAllOperations();
}
}
private Set<SpecialEffectsController> collectAllSpecialEffectsController() {
HashSet hashSet = new HashSet();
Iterator<FragmentStateManager> it = this.mFragmentStore.getActiveFragmentStateManagers().iterator();
while (it.hasNext()) {
ViewGroup viewGroup = it.next().getFragment().mContainer;
if (viewGroup != null) {
hashSet.add(SpecialEffectsController.getOrCreateController(viewGroup, getSpecialEffectsControllerFactory()));
}
}
return hashSet;
}
private boolean generateOpsForPendingActions(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
synchronized (this.mPendingActions) {
if (this.mPendingActions.isEmpty()) {
return false;
}
try {
int size = this.mPendingActions.size();
boolean z = false;
for (int i = 0; i < size; i++) {
z |= this.mPendingActions.get(i).generateOps(arrayList, arrayList2);
}
return z;
} finally {
this.mPendingActions.clear();
this.mHost.getHandler().removeCallbacks(this.mExecCommit);
}
}
}
private void doPendingDeferredStart() {
if (this.mHavePendingDeferredStart) {
this.mHavePendingDeferredStart = false;
startPendingDeferredFragments();
}
}
private void reportBackStackChanged() {
if (this.mBackStackChangeListeners != null) {
for (int i = 0; i < this.mBackStackChangeListeners.size(); i++) {
this.mBackStackChangeListeners.get(i).onBackStackChanged();
}
}
}
private Set<Fragment> fragmentsFromRecord(BackStackRecord backStackRecord) {
HashSet hashSet = new HashSet();
for (int i = 0; i < backStackRecord.mOps.size(); i++) {
Fragment fragment = backStackRecord.mOps.get(i).mFragment;
if (fragment != null && backStackRecord.mAddToBackStack) {
hashSet.add(fragment);
}
}
return hashSet;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void addBackStackState(BackStackRecord backStackRecord) {
if (this.mBackStack == null) {
this.mBackStack = new ArrayList<>();
}
this.mBackStack.add(backStackRecord);
}
boolean restoreBackStackState(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, String str) {
BackStackState remove = this.mBackStackStates.remove(str);
if (remove == null) {
return false;
}
HashMap hashMap = new HashMap();
Iterator<BackStackRecord> it = arrayList.iterator();
while (it.hasNext()) {
BackStackRecord next = it.next();
if (next.mBeingSaved) {
Iterator<FragmentTransaction.Op> it2 = next.mOps.iterator();
while (it2.hasNext()) {
FragmentTransaction.Op next2 = it2.next();
if (next2.mFragment != null) {
hashMap.put(next2.mFragment.mWho, next2.mFragment);
}
}
}
}
Iterator<BackStackRecord> it3 = remove.instantiate(this, hashMap).iterator();
while (true) {
boolean z = false;
while (it3.hasNext()) {
if (it3.next().generateOps(arrayList, arrayList2) || z) {
z = true;
}
}
return z;
}
}
boolean saveBackStackState(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, String str) {
String str2;
int findBackStackIndex = findBackStackIndex(str, -1, true);
if (findBackStackIndex < 0) {
return false;
}
for (int i = findBackStackIndex; i < this.mBackStack.size(); i++) {
BackStackRecord backStackRecord = this.mBackStack.get(i);
if (!backStackRecord.mReorderingAllowed) {
throwException(new IllegalArgumentException("saveBackStack(\"" + str + "\") included FragmentTransactions must use setReorderingAllowed(true) to ensure that the back stack can be restored as an atomic operation. Found " + backStackRecord + " that did not use setReorderingAllowed(true)."));
}
}
HashSet hashSet = new HashSet();
for (int i2 = findBackStackIndex; i2 < this.mBackStack.size(); i2++) {
BackStackRecord backStackRecord2 = this.mBackStack.get(i2);
HashSet hashSet2 = new HashSet();
HashSet hashSet3 = new HashSet();
Iterator<FragmentTransaction.Op> it = backStackRecord2.mOps.iterator();
while (it.hasNext()) {
FragmentTransaction.Op next = it.next();
Fragment fragment = next.mFragment;
if (fragment != null) {
if (!next.mFromExpandedOp || next.mCmd == 1 || next.mCmd == 2 || next.mCmd == 8) {
hashSet.add(fragment);
hashSet2.add(fragment);
}
if (next.mCmd == 1 || next.mCmd == 2) {
hashSet3.add(fragment);
}
}
}
hashSet2.removeAll(hashSet3);
if (!hashSet2.isEmpty()) {
StringBuilder append = new StringBuilder("saveBackStack(\"").append(str).append("\") must be self contained and not reference fragments from non-saved FragmentTransactions. Found reference to fragment");
if (hashSet2.size() == 1) {
str2 = " " + hashSet2.iterator().next();
} else {
str2 = "s " + hashSet2;
}
throwException(new IllegalArgumentException(append.append(str2).append(" in ").append(backStackRecord2).append(" that were previously added to the FragmentManager through a separate FragmentTransaction.").toString()));
}
}
ArrayDeque arrayDeque = new ArrayDeque(hashSet);
while (!arrayDeque.isEmpty()) {
Fragment fragment2 = (Fragment) arrayDeque.removeFirst();
if (fragment2.mRetainInstance) {
throwException(new IllegalArgumentException("saveBackStack(\"" + str + "\") must not contain retained fragments. Found " + (hashSet.contains(fragment2) ? "direct reference to retained " : "retained child ") + "fragment " + fragment2));
}
for (Fragment fragment3 : fragment2.mChildFragmentManager.getActiveFragments()) {
if (fragment3 != null) {
arrayDeque.addLast(fragment3);
}
}
}
ArrayList arrayList3 = new ArrayList();
Iterator it2 = hashSet.iterator();
while (it2.hasNext()) {
arrayList3.add(((Fragment) it2.next()).mWho);
}
ArrayList arrayList4 = new ArrayList(this.mBackStack.size() - findBackStackIndex);
for (int i3 = findBackStackIndex; i3 < this.mBackStack.size(); i3++) {
arrayList4.add(null);
}
BackStackState backStackState = new BackStackState(arrayList3, arrayList4);
for (int size = this.mBackStack.size() - 1; size >= findBackStackIndex; size--) {
BackStackRecord remove = this.mBackStack.remove(size);
BackStackRecord backStackRecord3 = new BackStackRecord(remove);
backStackRecord3.collapseOps();
arrayList4.set(size - findBackStackIndex, new BackStackRecordState(backStackRecord3));
remove.mBeingSaved = true;
arrayList.add(remove);
arrayList2.add(true);
}
this.mBackStackStates.put(str, backStackState);
return true;
}
boolean clearBackStackState(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, String str) {
if (restoreBackStackState(arrayList, arrayList2, str)) {
return popBackStackState(arrayList, arrayList2, str, -1, 1);
}
return false;
}
boolean popBackStackState(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, String str, int i, int i2) {
int findBackStackIndex = findBackStackIndex(str, i, (i2 & 1) != 0);
if (findBackStackIndex < 0) {
return false;
}
for (int size = this.mBackStack.size() - 1; size >= findBackStackIndex; size--) {
arrayList.add(this.mBackStack.remove(size));
arrayList2.add(true);
}
return true;
}
private int findBackStackIndex(String str, int i, boolean z) {
ArrayList<BackStackRecord> arrayList = this.mBackStack;
if (arrayList == null || arrayList.isEmpty()) {
return -1;
}
if (str == null && i < 0) {
if (z) {
return 0;
}
return this.mBackStack.size() - 1;
}
int size = this.mBackStack.size() - 1;
while (size >= 0) {
BackStackRecord backStackRecord = this.mBackStack.get(size);
if ((str != null && str.equals(backStackRecord.getName())) || (i >= 0 && i == backStackRecord.mIndex)) {
break;
}
size--;
}
if (size < 0) {
return size;
}
if (!z) {
if (size == this.mBackStack.size() - 1) {
return -1;
}
return size + 1;
}
while (size > 0) {
BackStackRecord backStackRecord2 = this.mBackStack.get(size - 1);
if ((str == null || !str.equals(backStackRecord2.getName())) && (i < 0 || i != backStackRecord2.mIndex)) {
return size;
}
size--;
}
return size;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Deprecated
public FragmentManagerNonConfig retainNonConfig() {
if (this.mHost instanceof ViewModelStoreOwner) {
throwException(new IllegalStateException("You cannot use retainNonConfig when your FragmentHostCallback implements ViewModelStoreOwner."));
}
return this.mNonConfig.getSnapshot();
}
/* JADX INFO: Access modifiers changed from: package-private */
public Parcelable saveAllState() {
if (this.mHost instanceof SavedStateRegistryOwner) {
throwException(new IllegalStateException("You cannot use saveAllState when your FragmentHostCallback implements SavedStateRegistryOwner."));
}
Bundle m5170lambda$attachController$4$androidxfragmentappFragmentManager = m5170lambda$attachController$4$androidxfragmentappFragmentManager();
if (m5170lambda$attachController$4$androidxfragmentappFragmentManager.isEmpty()) {
return null;
}
return m5170lambda$attachController$4$androidxfragmentappFragmentManager;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: saveAllStateInternal, reason: merged with bridge method [inline-methods] */
public Bundle m5170lambda$attachController$4$androidxfragmentappFragmentManager() {
BackStackRecordState[] backStackRecordStateArr;
int size;
Bundle bundle = new Bundle();
forcePostponedTransactions();
endAnimatingAwayFragments();
execPendingActions(true);
this.mStateSaved = true;
this.mNonConfig.setIsStateSaved(true);
ArrayList<String> saveActiveFragments = this.mFragmentStore.saveActiveFragments();
HashMap<String, Bundle> allSavedState = this.mFragmentStore.getAllSavedState();
if (allSavedState.isEmpty()) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "saveAllState: no fragments!");
}
} else {
ArrayList<String> saveAddedFragments = this.mFragmentStore.saveAddedFragments();
ArrayList<BackStackRecord> arrayList = this.mBackStack;
if (arrayList == null || (size = arrayList.size()) <= 0) {
backStackRecordStateArr = null;
} else {
backStackRecordStateArr = new BackStackRecordState[size];
for (int i = 0; i < size; i++) {
backStackRecordStateArr[i] = new BackStackRecordState(this.mBackStack.get(i));
if (isLoggingEnabled(2)) {
Log.v(TAG, "saveAllState: adding back stack #" + i + ": " + this.mBackStack.get(i));
}
}
}
FragmentManagerState fragmentManagerState = new FragmentManagerState();
fragmentManagerState.mActive = saveActiveFragments;
fragmentManagerState.mAdded = saveAddedFragments;
fragmentManagerState.mBackStack = backStackRecordStateArr;
fragmentManagerState.mBackStackIndex = this.mBackStackIndex.get();
Fragment fragment = this.mPrimaryNav;
if (fragment != null) {
fragmentManagerState.mPrimaryNavActiveWho = fragment.mWho;
}
fragmentManagerState.mBackStackStateKeys.addAll(this.mBackStackStates.keySet());
fragmentManagerState.mBackStackStates.addAll(this.mBackStackStates.values());
fragmentManagerState.mLaunchedFragments = new ArrayList<>(this.mLaunchedFragments);
bundle.putParcelable("state", fragmentManagerState);
for (String str : this.mResults.keySet()) {
bundle.putBundle(RESULT_KEY_PREFIX + str, this.mResults.get(str));
}
for (String str2 : allSavedState.keySet()) {
bundle.putBundle(FRAGMENT_KEY_PREFIX + str2, allSavedState.get(str2));
}
}
return bundle;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void restoreAllState(Parcelable parcelable, FragmentManagerNonConfig fragmentManagerNonConfig) {
if (this.mHost instanceof ViewModelStoreOwner) {
throwException(new IllegalStateException("You must use restoreSaveState when your FragmentHostCallback implements ViewModelStoreOwner"));
}
this.mNonConfig.restoreFromSnapshot(fragmentManagerNonConfig);
restoreSaveStateInternal(parcelable);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void restoreSaveState(Parcelable parcelable) {
if (this.mHost instanceof SavedStateRegistryOwner) {
throwException(new IllegalStateException("You cannot use restoreSaveState when your FragmentHostCallback implements SavedStateRegistryOwner."));
}
restoreSaveStateInternal(parcelable);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void restoreSaveStateInternal(Parcelable parcelable) {
FragmentStateManager fragmentStateManager;
Bundle bundle;
Bundle bundle2;
if (parcelable == null) {
return;
}
Bundle bundle3 = (Bundle) parcelable;
for (String str : bundle3.keySet()) {
if (str.startsWith(RESULT_KEY_PREFIX) && (bundle2 = bundle3.getBundle(str)) != null) {
bundle2.setClassLoader(this.mHost.getContext().getClassLoader());
this.mResults.put(str.substring(7), bundle2);
}
}
HashMap<String, Bundle> hashMap = new HashMap<>();
for (String str2 : bundle3.keySet()) {
if (str2.startsWith(FRAGMENT_KEY_PREFIX) && (bundle = bundle3.getBundle(str2)) != null) {
bundle.setClassLoader(this.mHost.getContext().getClassLoader());
hashMap.put(str2.substring(9), bundle);
}
}
this.mFragmentStore.restoreSaveState(hashMap);
FragmentManagerState fragmentManagerState = (FragmentManagerState) bundle3.getParcelable("state");
if (fragmentManagerState == null) {
return;
}
this.mFragmentStore.resetActiveFragments();
Iterator<String> it = fragmentManagerState.mActive.iterator();
while (it.hasNext()) {
Bundle savedState = this.mFragmentStore.setSavedState(it.next(), null);
if (savedState != null) {
Fragment findRetainedFragmentByWho = this.mNonConfig.findRetainedFragmentByWho(((FragmentState) savedState.getParcelable("state")).mWho);
if (findRetainedFragmentByWho != null) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "restoreSaveState: re-attaching retained " + findRetainedFragmentByWho);
}
fragmentStateManager = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, findRetainedFragmentByWho, savedState);
} else {
fragmentStateManager = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, this.mHost.getContext().getClassLoader(), getFragmentFactory(), savedState);
}
Fragment fragment = fragmentStateManager.getFragment();
fragment.mSavedFragmentState = savedState;
fragment.mFragmentManager = this;
if (isLoggingEnabled(2)) {
Log.v(TAG, "restoreSaveState: active (" + fragment.mWho + "): " + fragment);
}
fragmentStateManager.restoreState(this.mHost.getContext().getClassLoader());
this.mFragmentStore.makeActive(fragmentStateManager);
fragmentStateManager.setFragmentManagerState(this.mCurState);
}
}
for (Fragment fragment2 : this.mNonConfig.getRetainedFragments()) {
if (!this.mFragmentStore.containsActiveFragment(fragment2.mWho)) {
if (isLoggingEnabled(2)) {
Log.v(TAG, "Discarding retained Fragment " + fragment2 + " that was not found in the set of active Fragments " + fragmentManagerState.mActive);
}
this.mNonConfig.removeRetainedFragment(fragment2);
fragment2.mFragmentManager = this;
FragmentStateManager fragmentStateManager2 = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, fragment2);
fragmentStateManager2.setFragmentManagerState(1);
fragmentStateManager2.moveToExpectedState();
fragment2.mRemoving = true;
fragmentStateManager2.moveToExpectedState();
}
}
this.mFragmentStore.restoreAddedFragments(fragmentManagerState.mAdded);
if (fragmentManagerState.mBackStack != null) {
this.mBackStack = new ArrayList<>(fragmentManagerState.mBackStack.length);
for (int i = 0; i < fragmentManagerState.mBackStack.length; i++) {
BackStackRecord instantiate = fragmentManagerState.mBackStack[i].instantiate(this);
if (isLoggingEnabled(2)) {
Log.v(TAG, "restoreAllState: back stack #" + i + " (index " + instantiate.mIndex + "): " + instantiate);
PrintWriter printWriter = new PrintWriter(new LogWriter(TAG));
instantiate.dump(" ", printWriter, false);
printWriter.close();
}
this.mBackStack.add(instantiate);
}
} else {
this.mBackStack = null;
}
this.mBackStackIndex.set(fragmentManagerState.mBackStackIndex);
if (fragmentManagerState.mPrimaryNavActiveWho != null) {
Fragment findActiveFragment = findActiveFragment(fragmentManagerState.mPrimaryNavActiveWho);
this.mPrimaryNav = findActiveFragment;
dispatchParentPrimaryNavigationFragmentChanged(findActiveFragment);
}
ArrayList<String> arrayList = fragmentManagerState.mBackStackStateKeys;
if (arrayList != null) {
for (int i2 = 0; i2 < arrayList.size(); i2++) {
this.mBackStackStates.put(arrayList.get(i2), fragmentManagerState.mBackStackStates.get(i2));
}
}
this.mLaunchedFragments = new ArrayDeque<>(fragmentManagerState.mLaunchedFragments);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Multi-variable type inference failed */
public void attachController(FragmentHostCallback<?> fragmentHostCallback, FragmentContainer fragmentContainer, final Fragment fragment) {
if (this.mHost != null) {
throw new IllegalStateException("Already attached");
}
this.mHost = fragmentHostCallback;
this.mContainer = fragmentContainer;
this.mParent = fragment;
if (fragment != null) {
addFragmentOnAttachListener(new FragmentOnAttachListener() { // from class: androidx.fragment.app.FragmentManager.7
@Override // androidx.fragment.app.FragmentOnAttachListener
public void onAttachFragment(FragmentManager fragmentManager, Fragment fragment2) {
fragment.onAttachFragment(fragment2);
}
});
} else if (fragmentHostCallback instanceof FragmentOnAttachListener) {
addFragmentOnAttachListener((FragmentOnAttachListener) fragmentHostCallback);
}
if (this.mParent != null) {
updateOnBackPressedCallbackEnabled();
}
if (fragmentHostCallback instanceof OnBackPressedDispatcherOwner) {
OnBackPressedDispatcherOwner onBackPressedDispatcherOwner = (OnBackPressedDispatcherOwner) fragmentHostCallback;
OnBackPressedDispatcher onBackPressedDispatcher = onBackPressedDispatcherOwner.getOnBackPressedDispatcher();
this.mOnBackPressedDispatcher = onBackPressedDispatcher;
LifecycleOwner lifecycleOwner = onBackPressedDispatcherOwner;
if (fragment != null) {
lifecycleOwner = fragment;
}
onBackPressedDispatcher.addCallback(lifecycleOwner, this.mOnBackPressedCallback);
}
if (fragment != null) {
this.mNonConfig = fragment.mFragmentManager.getChildNonConfig(fragment);
} else if (fragmentHostCallback instanceof ViewModelStoreOwner) {
this.mNonConfig = FragmentManagerViewModel.getInstance(((ViewModelStoreOwner) fragmentHostCallback).getViewModelStore());
} else {
this.mNonConfig = new FragmentManagerViewModel(false);
}
this.mNonConfig.setIsStateSaved(isStateSaved());
this.mFragmentStore.setNonConfig(this.mNonConfig);
Object obj = this.mHost;
if ((obj instanceof SavedStateRegistryOwner) && fragment == null) {
SavedStateRegistry savedStateRegistry = ((SavedStateRegistryOwner) obj).getSavedStateRegistry();
savedStateRegistry.registerSavedStateProvider(SAVED_STATE_KEY, new SavedStateRegistry.SavedStateProvider() { // from class: androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda4
@Override // androidx.savedstate.SavedStateRegistry.SavedStateProvider
public final Bundle saveState() {
return FragmentManager.this.m5170lambda$attachController$4$androidxfragmentappFragmentManager();
}
});
Bundle consumeRestoredStateForKey = savedStateRegistry.consumeRestoredStateForKey(SAVED_STATE_KEY);
if (consumeRestoredStateForKey != null) {
restoreSaveStateInternal(consumeRestoredStateForKey);
}
}
Object obj2 = this.mHost;
if (obj2 instanceof ActivityResultRegistryOwner) {
ActivityResultRegistry activityResultRegistry = ((ActivityResultRegistryOwner) obj2).getActivityResultRegistry();
String str = "FragmentManager:" + (fragment != null ? fragment.mWho + ":" : "");
this.mStartActivityForResult = activityResultRegistry.register(str + "StartActivityForResult", new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() { // from class: androidx.fragment.app.FragmentManager.8
@Override // androidx.activity.result.ActivityResultCallback
public void onActivityResult(ActivityResult activityResult) {
LaunchedFragmentInfo pollLast = FragmentManager.this.mLaunchedFragments.pollLast();
if (pollLast == null) {
Log.w(FragmentManager.TAG, "No Activities were started for result for " + this);
return;
}
String str2 = pollLast.mWho;
int i = pollLast.mRequestCode;
Fragment findFragmentByWho = FragmentManager.this.mFragmentStore.findFragmentByWho(str2);
if (findFragmentByWho == null) {
Log.w(FragmentManager.TAG, "Activity result delivered for unknown Fragment " + str2);
} else {
findFragmentByWho.onActivityResult(i, activityResult.getResultCode(), activityResult.getData());
}
}
});
this.mStartIntentSenderForResult = activityResultRegistry.register(str + "StartIntentSenderForResult", new FragmentIntentSenderContract(), new ActivityResultCallback<ActivityResult>() { // from class: androidx.fragment.app.FragmentManager.9
@Override // androidx.activity.result.ActivityResultCallback
public void onActivityResult(ActivityResult activityResult) {
LaunchedFragmentInfo pollFirst = FragmentManager.this.mLaunchedFragments.pollFirst();
if (pollFirst == null) {
Log.w(FragmentManager.TAG, "No IntentSenders were started for " + this);
return;
}
String str2 = pollFirst.mWho;
int i = pollFirst.mRequestCode;
Fragment findFragmentByWho = FragmentManager.this.mFragmentStore.findFragmentByWho(str2);
if (findFragmentByWho == null) {
Log.w(FragmentManager.TAG, "Intent Sender result delivered for unknown Fragment " + str2);
} else {
findFragmentByWho.onActivityResult(i, activityResult.getResultCode(), activityResult.getData());
}
}
});
this.mRequestPermissions = activityResultRegistry.register(str + "RequestPermissions", new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { // from class: androidx.fragment.app.FragmentManager.10
@Override // androidx.activity.result.ActivityResultCallback
public void onActivityResult(Map<String, Boolean> map) {
String[] strArr = (String[]) map.keySet().toArray(new String[0]);
ArrayList arrayList = new ArrayList(map.values());
int[] iArr = new int[arrayList.size()];
for (int i = 0; i < arrayList.size(); i++) {
iArr[i] = ((Boolean) arrayList.get(i)).booleanValue() ? 0 : -1;
}
LaunchedFragmentInfo pollFirst = FragmentManager.this.mLaunchedFragments.pollFirst();
if (pollFirst == null) {
Log.w(FragmentManager.TAG, "No permissions were requested for " + this);
return;
}
String str2 = pollFirst.mWho;
int i2 = pollFirst.mRequestCode;
Fragment findFragmentByWho = FragmentManager.this.mFragmentStore.findFragmentByWho(str2);
if (findFragmentByWho == null) {
Log.w(FragmentManager.TAG, "Permission request result delivered for unknown Fragment " + str2);
} else {
findFragmentByWho.onRequestPermissionsResult(i2, strArr, iArr);
}
}
});
}
Object obj3 = this.mHost;
if (obj3 instanceof OnConfigurationChangedProvider) {
((OnConfigurationChangedProvider) obj3).addOnConfigurationChangedListener(this.mOnConfigurationChangedListener);
}
Object obj4 = this.mHost;
if (obj4 instanceof OnTrimMemoryProvider) {
((OnTrimMemoryProvider) obj4).addOnTrimMemoryListener(this.mOnTrimMemoryListener);
}
Object obj5 = this.mHost;
if (obj5 instanceof OnMultiWindowModeChangedProvider) {
((OnMultiWindowModeChangedProvider) obj5).addOnMultiWindowModeChangedListener(this.mOnMultiWindowModeChangedListener);
}
Object obj6 = this.mHost;
if (obj6 instanceof OnPictureInPictureModeChangedProvider) {
((OnPictureInPictureModeChangedProvider) obj6).addOnPictureInPictureModeChangedListener(this.mOnPictureInPictureModeChangedListener);
}
Object obj7 = this.mHost;
if ((obj7 instanceof MenuHost) && fragment == null) {
((MenuHost) obj7).addMenuProvider(this.mMenuProvider);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void noteStateNotSaved() {
if (this.mHost == null) {
return;
}
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.noteStateNotSaved();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void launchStartActivityForResult(Fragment fragment, Intent intent, int i, Bundle bundle) {
if (this.mStartActivityForResult != null) {
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
if (bundle != null) {
intent.putExtra(ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE, bundle);
}
this.mStartActivityForResult.launch(intent);
return;
}
this.mHost.onStartActivityFromFragment(fragment, intent, i, bundle);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void launchStartIntentSenderForResult(Fragment fragment, IntentSender intentSender, int i, Intent intent, int i2, int i3, int i4, Bundle bundle) throws IntentSender.SendIntentException {
Intent intent2;
if (this.mStartIntentSenderForResult != null) {
if (bundle != null) {
if (intent == null) {
intent2 = new Intent();
intent2.putExtra(EXTRA_CREATED_FILLIN_INTENT, true);
} else {
intent2 = intent;
}
if (isLoggingEnabled(2)) {
Log.v(TAG, "ActivityOptions " + bundle + " were added to fillInIntent " + intent2 + " for fragment " + fragment);
}
intent2.putExtra(ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE, bundle);
} else {
intent2 = intent;
}
IntentSenderRequest build = new IntentSenderRequest.Builder(intentSender).setFillInIntent(intent2).setFlags(i3, i2).build();
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
if (isLoggingEnabled(2)) {
Log.v(TAG, "Fragment " + fragment + "is launching an IntentSender for result ");
}
this.mStartIntentSenderForResult.launch(build);
return;
}
this.mHost.onStartIntentSenderFromFragment(fragment, intentSender, i, intent, i2, i3, i4, bundle);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void launchRequestPermissions(Fragment fragment, String[] strArr, int i) {
if (this.mRequestPermissions != null) {
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
this.mRequestPermissions.launch(strArr);
return;
}
this.mHost.onRequestPermissionsFromFragment(fragment, strArr, i);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchAttach() {
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
dispatchStateChange(0);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchCreate() {
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
dispatchStateChange(1);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchViewCreated() {
dispatchStateChange(2);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchActivityCreated() {
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
dispatchStateChange(4);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchStart() {
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
dispatchStateChange(5);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchResume() {
this.mStateSaved = false;
this.mStopped = false;
this.mNonConfig.setIsStateSaved(false);
dispatchStateChange(7);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchPause() {
dispatchStateChange(5);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchStop() {
this.mStopped = true;
this.mNonConfig.setIsStateSaved(true);
dispatchStateChange(4);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchDestroyView() {
dispatchStateChange(1);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchDestroy() {
this.mDestroyed = true;
execPendingActions(true);
endAnimatingAwayFragments();
clearBackStackStateViewModels();
dispatchStateChange(-1);
Object obj = this.mHost;
if (obj instanceof OnTrimMemoryProvider) {
((OnTrimMemoryProvider) obj).removeOnTrimMemoryListener(this.mOnTrimMemoryListener);
}
Object obj2 = this.mHost;
if (obj2 instanceof OnConfigurationChangedProvider) {
((OnConfigurationChangedProvider) obj2).removeOnConfigurationChangedListener(this.mOnConfigurationChangedListener);
}
Object obj3 = this.mHost;
if (obj3 instanceof OnMultiWindowModeChangedProvider) {
((OnMultiWindowModeChangedProvider) obj3).removeOnMultiWindowModeChangedListener(this.mOnMultiWindowModeChangedListener);
}
Object obj4 = this.mHost;
if (obj4 instanceof OnPictureInPictureModeChangedProvider) {
((OnPictureInPictureModeChangedProvider) obj4).removeOnPictureInPictureModeChangedListener(this.mOnPictureInPictureModeChangedListener);
}
Object obj5 = this.mHost;
if ((obj5 instanceof MenuHost) && this.mParent == null) {
((MenuHost) obj5).removeMenuProvider(this.mMenuProvider);
}
this.mHost = null;
this.mContainer = null;
this.mParent = null;
if (this.mOnBackPressedDispatcher != null) {
this.mOnBackPressedCallback.remove();
this.mOnBackPressedDispatcher = null;
}
ActivityResultLauncher<Intent> activityResultLauncher = this.mStartActivityForResult;
if (activityResultLauncher != null) {
activityResultLauncher.unregister();
this.mStartIntentSenderForResult.unregister();
this.mRequestPermissions.unregister();
}
}
private void dispatchStateChange(int i) {
try {
this.mExecutingActions = true;
this.mFragmentStore.dispatchStateChange(i);
moveToState(i, false);
Iterator<SpecialEffectsController> it = collectAllSpecialEffectsController().iterator();
while (it.hasNext()) {
it.next().forceCompleteAllOperations();
}
this.mExecutingActions = false;
execPendingActions(true);
} catch (Throwable th) {
this.mExecutingActions = false;
throw th;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchMultiWindowModeChanged(boolean z, boolean z2) {
if (z2 && (this.mHost instanceof OnMultiWindowModeChangedProvider)) {
throwException(new IllegalStateException("Do not call dispatchMultiWindowModeChanged() on host. Host implements OnMultiWindowModeChangedProvider and automatically dispatches multi-window mode changes to fragments."));
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.performMultiWindowModeChanged(z);
if (z2) {
fragment.mChildFragmentManager.dispatchMultiWindowModeChanged(z, true);
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchPictureInPictureModeChanged(boolean z, boolean z2) {
if (z2 && (this.mHost instanceof OnPictureInPictureModeChangedProvider)) {
throwException(new IllegalStateException("Do not call dispatchPictureInPictureModeChanged() on host. Host implements OnPictureInPictureModeChangedProvider and automatically dispatches picture-in-picture mode changes to fragments."));
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.performPictureInPictureModeChanged(z);
if (z2) {
fragment.mChildFragmentManager.dispatchPictureInPictureModeChanged(z, true);
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchConfigurationChanged(Configuration configuration, boolean z) {
if (z && (this.mHost instanceof OnConfigurationChangedProvider)) {
throwException(new IllegalStateException("Do not call dispatchConfigurationChanged() on host. Host implements OnConfigurationChangedProvider and automatically dispatches configuration changes to fragments."));
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.performConfigurationChanged(configuration);
if (z) {
fragment.mChildFragmentManager.dispatchConfigurationChanged(configuration, true);
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchLowMemory(boolean z) {
if (z && (this.mHost instanceof OnTrimMemoryProvider)) {
throwException(new IllegalStateException("Do not call dispatchLowMemory() on host. Host implements OnTrimMemoryProvider and automatically dispatches low memory callbacks to fragments."));
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.performLowMemory();
if (z) {
fragment.mChildFragmentManager.dispatchLowMemory(true);
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
if (this.mCurState < 1) {
return false;
}
ArrayList<Fragment> arrayList = null;
boolean z = false;
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null && isParentMenuVisible(fragment) && fragment.performCreateOptionsMenu(menu, menuInflater)) {
if (arrayList == null) {
arrayList = new ArrayList<>();
}
arrayList.add(fragment);
z = true;
}
}
if (this.mCreatedMenus != null) {
for (int i = 0; i < this.mCreatedMenus.size(); i++) {
Fragment fragment2 = this.mCreatedMenus.get(i);
if (arrayList == null || !arrayList.contains(fragment2)) {
fragment2.onDestroyOptionsMenu();
}
}
}
this.mCreatedMenus = arrayList;
return z;
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean dispatchPrepareOptionsMenu(Menu menu) {
boolean z = false;
if (this.mCurState < 1) {
return false;
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null && isParentMenuVisible(fragment) && fragment.performPrepareOptionsMenu(menu)) {
z = true;
}
}
return z;
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean dispatchOptionsItemSelected(MenuItem menuItem) {
if (this.mCurState < 1) {
return false;
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null && fragment.performOptionsItemSelected(menuItem)) {
return true;
}
}
return false;
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean dispatchContextItemSelected(MenuItem menuItem) {
if (this.mCurState < 1) {
return false;
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null && fragment.performContextItemSelected(menuItem)) {
return true;
}
}
return false;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchOptionsMenuClosed(Menu menu) {
if (this.mCurState < 1) {
return;
}
for (Fragment fragment : this.mFragmentStore.getFragments()) {
if (fragment != null) {
fragment.performOptionsMenuClosed(menu);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public void setPrimaryNavigationFragment(Fragment fragment) {
if (fragment != null && (!fragment.equals(findActiveFragment(fragment.mWho)) || (fragment.mHost != null && fragment.mFragmentManager != this))) {
throw new IllegalArgumentException("Fragment " + fragment + " is not an active fragment of FragmentManager " + this);
}
Fragment fragment2 = this.mPrimaryNav;
this.mPrimaryNav = fragment;
dispatchParentPrimaryNavigationFragmentChanged(fragment2);
dispatchParentPrimaryNavigationFragmentChanged(this.mPrimaryNav);
}
private void dispatchParentPrimaryNavigationFragmentChanged(Fragment fragment) {
if (fragment == null || !fragment.equals(findActiveFragment(fragment.mWho))) {
return;
}
fragment.performPrimaryNavigationFragmentChanged();
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchPrimaryNavigationFragmentChanged() {
updateOnBackPressedCallbackEnabled();
dispatchParentPrimaryNavigationFragmentChanged(this.mPrimaryNav);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void setMaxLifecycle(Fragment fragment, Lifecycle.State state) {
if (!fragment.equals(findActiveFragment(fragment.mWho)) || (fragment.mHost != null && fragment.mFragmentManager != this)) {
throw new IllegalArgumentException("Fragment " + fragment + " is not an active fragment of FragmentManager " + this);
}
fragment.mMaxState = state;
}
public FragmentFactory getFragmentFactory() {
FragmentFactory fragmentFactory = this.mFragmentFactory;
if (fragmentFactory != null) {
return fragmentFactory;
}
Fragment fragment = this.mParent;
return fragment != null ? fragment.mFragmentManager.getFragmentFactory() : this.mHostFragmentFactory;
}
/* JADX INFO: Access modifiers changed from: package-private */
public SpecialEffectsControllerFactory getSpecialEffectsControllerFactory() {
SpecialEffectsControllerFactory specialEffectsControllerFactory = this.mSpecialEffectsControllerFactory;
if (specialEffectsControllerFactory != null) {
return specialEffectsControllerFactory;
}
Fragment fragment = this.mParent;
return fragment != null ? fragment.mFragmentManager.getSpecialEffectsControllerFactory() : this.mDefaultSpecialEffectsControllerFactory;
}
public void registerFragmentLifecycleCallbacks(FragmentLifecycleCallbacks fragmentLifecycleCallbacks, boolean z) {
this.mLifecycleCallbacksDispatcher.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, z);
}
public void unregisterFragmentLifecycleCallbacks(FragmentLifecycleCallbacks fragmentLifecycleCallbacks) {
this.mLifecycleCallbacksDispatcher.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks);
}
public void addFragmentOnAttachListener(FragmentOnAttachListener fragmentOnAttachListener) {
this.mOnAttachListeners.add(fragmentOnAttachListener);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchOnAttachFragment(Fragment fragment) {
Iterator<FragmentOnAttachListener> it = this.mOnAttachListeners.iterator();
while (it.hasNext()) {
it.next().onAttachFragment(this, fragment);
}
}
public void removeFragmentOnAttachListener(FragmentOnAttachListener fragmentOnAttachListener) {
this.mOnAttachListeners.remove(fragmentOnAttachListener);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void dispatchOnHiddenChanged() {
for (Fragment fragment : this.mFragmentStore.getActiveFragments()) {
if (fragment != null) {
fragment.onHiddenChanged(fragment.isHidden());
fragment.mChildFragmentManager.dispatchOnHiddenChanged();
}
}
}
boolean checkForMenus() {
boolean z = false;
for (Fragment fragment : this.mFragmentStore.getActiveFragments()) {
if (fragment != null) {
z = isMenuAvailable(fragment);
}
if (z) {
return true;
}
}
return false;
}
private boolean isMenuAvailable(Fragment fragment) {
return (fragment.mHasMenu && fragment.mMenuVisible) || fragment.mChildFragmentManager.checkForMenus();
}
/* JADX INFO: Access modifiers changed from: package-private */
public void invalidateMenuForFragment(Fragment fragment) {
if (fragment.mAdded && isMenuAvailable(fragment)) {
this.mNeedMenuInvalidate = true;
}
}
private boolean isParentAdded() {
Fragment fragment = this.mParent;
if (fragment == null) {
return true;
}
return fragment.isAdded() && this.mParent.getParentFragmentManager().isParentAdded();
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public class PopBackStackState implements OpGenerator {
final int mFlags;
final int mId;
final String mName;
PopBackStackState(String str, int i, int i2) {
this.mName = str;
this.mId = i;
this.mFlags = i2;
}
@Override // androidx.fragment.app.FragmentManager.OpGenerator
public boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
if (FragmentManager.this.mPrimaryNav == null || this.mId >= 0 || this.mName != null || !FragmentManager.this.mPrimaryNav.getChildFragmentManager().popBackStackImmediate()) {
return FragmentManager.this.popBackStackState(arrayList, arrayList2, this.mName, this.mId, this.mFlags);
}
return false;
}
}
/* loaded from: classes2.dex */
private class RestoreBackStackState implements OpGenerator {
private final String mName;
RestoreBackStackState(String str) {
this.mName = str;
}
@Override // androidx.fragment.app.FragmentManager.OpGenerator
public boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
return FragmentManager.this.restoreBackStackState(arrayList, arrayList2, this.mName);
}
}
/* loaded from: classes2.dex */
private class SaveBackStackState implements OpGenerator {
private final String mName;
SaveBackStackState(String str) {
this.mName = str;
}
@Override // androidx.fragment.app.FragmentManager.OpGenerator
public boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
return FragmentManager.this.saveBackStackState(arrayList, arrayList2, this.mName);
}
}
/* loaded from: classes2.dex */
private class ClearBackStackState implements OpGenerator {
private final String mName;
ClearBackStackState(String str) {
this.mName = str;
}
@Override // androidx.fragment.app.FragmentManager.OpGenerator
public boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) {
return FragmentManager.this.clearBackStackState(arrayList, arrayList2, this.mName);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class LaunchedFragmentInfo implements Parcelable {
public static final Parcelable.Creator<LaunchedFragmentInfo> CREATOR = new Parcelable.Creator<LaunchedFragmentInfo>() { // from class: androidx.fragment.app.FragmentManager.LaunchedFragmentInfo.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public LaunchedFragmentInfo createFromParcel(Parcel parcel) {
return new LaunchedFragmentInfo(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public LaunchedFragmentInfo[] newArray(int i) {
return new LaunchedFragmentInfo[i];
}
};
int mRequestCode;
String mWho;
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
LaunchedFragmentInfo(String str, int i) {
this.mWho = str;
this.mRequestCode = i;
}
LaunchedFragmentInfo(Parcel parcel) {
this.mWho = parcel.readString();
this.mRequestCode = parcel.readInt();
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.mWho);
parcel.writeInt(this.mRequestCode);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class FragmentIntentSenderContract extends ActivityResultContract<IntentSenderRequest, ActivityResult> {
FragmentIntentSenderContract() {
}
@Override // androidx.activity.result.contract.ActivityResultContract
public Intent createIntent(Context context, IntentSenderRequest intentSenderRequest) {
Bundle bundleExtra;
Intent intent = new Intent(ActivityResultContracts.StartIntentSenderForResult.ACTION_INTENT_SENDER_REQUEST);
Intent fillInIntent = intentSenderRequest.getFillInIntent();
if (fillInIntent != null && (bundleExtra = fillInIntent.getBundleExtra(ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE)) != null) {
intent.putExtra(ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE, bundleExtra);
fillInIntent.removeExtra(ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE);
if (fillInIntent.getBooleanExtra(FragmentManager.EXTRA_CREATED_FILLIN_INTENT, false)) {
intentSenderRequest = new IntentSenderRequest.Builder(intentSenderRequest.getIntentSender()).setFillInIntent(null).setFlags(intentSenderRequest.getFlagsValues(), intentSenderRequest.getFlagsMask()).build();
}
}
intent.putExtra(ActivityResultContracts.StartIntentSenderForResult.EXTRA_INTENT_SENDER_REQUEST, intentSenderRequest);
if (FragmentManager.isLoggingEnabled(2)) {
Log.v(FragmentManager.TAG, "CreateIntent created the following intent: " + intent);
}
return intent;
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // androidx.activity.result.contract.ActivityResultContract
public ActivityResult parseResult(int i, Intent intent) {
return new ActivityResult(i, intent);
}
}
}