package androidx.fragment.app;

import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class p0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f11689a = new ArrayList();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f11690b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HashMap f11691c = new HashMap();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public FragmentManagerViewModel f11692d;

    public final void a(G g6) {
        if (this.f11689a.contains(g6)) {
            throw new IllegalStateException("Fragment already added: " + g6);
        }
        synchronized (this.f11689a) {
            this.f11689a.add(g6);
        }
        g6.mAdded = true;
    }

    public final G b(String str) {
        o0 o0Var = (o0) this.f11690b.get(str);
        if (o0Var != null) {
            return o0Var.f11684c;
        }
        return null;
    }

    public final G c(String str) {
        G gFindFragmentByWho;
        for (o0 o0Var : this.f11690b.values()) {
            if (o0Var != null && (gFindFragmentByWho = o0Var.f11684c.findFragmentByWho(str)) != null) {
                return gFindFragmentByWho;
            }
        }
        return null;
    }

    public final ArrayList d() {
        ArrayList arrayList = new ArrayList();
        for (o0 o0Var : this.f11690b.values()) {
            if (o0Var != null) {
                arrayList.add(o0Var);
            }
        }
        return arrayList;
    }

    public final ArrayList e() {
        ArrayList arrayList = new ArrayList();
        for (o0 o0Var : this.f11690b.values()) {
            if (o0Var != null) {
                arrayList.add(o0Var.f11684c);
            } else {
                arrayList.add(null);
            }
        }
        return arrayList;
    }

    public final List f() {
        ArrayList arrayList;
        if (this.f11689a.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        synchronized (this.f11689a) {
            arrayList = new ArrayList(this.f11689a);
        }
        return arrayList;
    }

    public final void g(o0 o0Var) {
        G g6 = o0Var.f11684c;
        String str = g6.mWho;
        HashMap map = this.f11690b;
        if (map.get(str) != null) {
            return;
        }
        map.put(g6.mWho, o0Var);
        if (g6.mRetainInstanceChangedWhileDetached) {
            if (g6.mRetainInstance) {
                this.f11692d.addRetainedFragment(g6);
            } else {
                this.f11692d.removeRetainedFragment(g6);
            }
            g6.mRetainInstanceChangedWhileDetached = false;
        }
        if (AbstractC1050g0.H(2)) {
            Log.v("FragmentManager", "Added fragment to active set " + g6);
        }
    }

    public final void h(o0 o0Var) {
        G g6 = o0Var.f11684c;
        if (g6.mRetainInstance) {
            this.f11692d.removeRetainedFragment(g6);
        }
        HashMap map = this.f11690b;
        if (map.get(g6.mWho) == o0Var && ((o0) map.put(g6.mWho, null)) != null && AbstractC1050g0.H(2)) {
            Log.v("FragmentManager", "Removed fragment from active set " + g6);
        }
    }

    public final Bundle i(Bundle bundle, String str) {
        HashMap map = this.f11691c;
        return bundle != null ? (Bundle) map.put(str, bundle) : (Bundle) map.remove(str);
    }
}
