package androidx.lifecycle;

import f2.C2035d;
import java.io.Closeable;
import java.util.Iterator;
import w4.InterfaceC3141c;

/* JADX INFO: loaded from: classes.dex */
public abstract class b0 {
    private final C2035d impl = new C2035d();

    public final void addCloseable(String key, AutoCloseable closeable) {
        AutoCloseable autoCloseable;
        kotlin.jvm.internal.o.h(key, "key");
        kotlin.jvm.internal.o.h(closeable, "closeable");
        C2035d c2035d = this.impl;
        if (c2035d != null) {
            if (c2035d.f16408d) {
                C2035d.b(closeable);
                return;
            }
            synchronized (c2035d.f16405a) {
                autoCloseable = (AutoCloseable) c2035d.f16406b.put(key, closeable);
            }
            C2035d.b(autoCloseable);
        }
    }

    public final void clear$lifecycle_viewmodel_release() {
        C2035d c2035d = this.impl;
        if (c2035d != null && !c2035d.f16408d) {
            c2035d.f16408d = true;
            synchronized (c2035d.f16405a) {
                try {
                    Iterator it = c2035d.f16406b.values().iterator();
                    while (it.hasNext()) {
                        C2035d.b((AutoCloseable) it.next());
                    }
                    Iterator it2 = c2035d.f16407c.iterator();
                    while (it2.hasNext()) {
                        C2035d.b((AutoCloseable) it2.next());
                    }
                    c2035d.f16407c.clear();
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        onCleared();
    }

    public final <T extends AutoCloseable> T getCloseable(String key) {
        T t6;
        kotlin.jvm.internal.o.h(key, "key");
        C2035d c2035d = this.impl;
        if (c2035d == null) {
            return null;
        }
        synchronized (c2035d.f16405a) {
            t6 = (T) c2035d.f16406b.get(key);
        }
        return t6;
    }

    public void onCleared() {
    }

    public void addCloseable(AutoCloseable closeable) {
        kotlin.jvm.internal.o.h(closeable, "closeable");
        C2035d c2035d = this.impl;
        if (c2035d != null) {
            c2035d.a(closeable);
        }
    }

    @InterfaceC3141c
    public /* synthetic */ void addCloseable(Closeable closeable) {
        kotlin.jvm.internal.o.h(closeable, "closeable");
        C2035d c2035d = this.impl;
        if (c2035d != null) {
            c2035d.a(closeable);
        }
    }
}
