package androidx.lifecycle;

import androidx.annotation.MainThread;
import java.io.Closeable;
import java.util.Iterator;
import kotlin.Deprecated;
import kotlin.DeprecationLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/* JADX INFO: loaded from: classes.dex */
public abstract class s0 {

    @Nullable
    private final o1.b impl = new o1.b();

    public void addCloseable(@NotNull AutoCloseable autoCloseable) {
        nb.g.i(autoCloseable, "closeable");
        o1.b bVar = this.impl;
        if (bVar != null) {
            bVar.a(autoCloseable);
        }
    }

    @MainThread
    public final void clear$lifecycle_viewmodel_release() {
        o1.b bVar = this.impl;
        if (bVar != null && !bVar.f31287d) {
            bVar.f31287d = true;
            synchronized (bVar.f31284a) {
                try {
                    Iterator it = bVar.f31285b.values().iterator();
                    while (it.hasNext()) {
                        o1.b.b((AutoCloseable) it.next());
                    }
                    Iterator it2 = bVar.f31286c.iterator();
                    while (it2.hasNext()) {
                        o1.b.b((AutoCloseable) it2.next());
                    }
                    bVar.f31286c.clear();
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        onCleared();
    }

    @Nullable
    public final <T extends AutoCloseable> T getCloseable(@NotNull String str) {
        T t10;
        nb.g.i(str, "key");
        o1.b bVar = this.impl;
        if (bVar == null) {
            return null;
        }
        synchronized (bVar.f31284a) {
            t10 = (T) bVar.f31285b.get(str);
        }
        return t10;
    }

    public void onCleared() {
    }

    @Deprecated(level = DeprecationLevel.f29180c, message = "Replaced by `AutoCloseable` overload.")
    public /* synthetic */ void addCloseable(Closeable closeable) {
        nb.g.i(closeable, "closeable");
        o1.b bVar = this.impl;
        if (bVar != null) {
            bVar.a(closeable);
        }
    }

    public final void addCloseable(@NotNull String str, @NotNull AutoCloseable autoCloseable) {
        AutoCloseable autoCloseable2;
        nb.g.i(str, "key");
        nb.g.i(autoCloseable, "closeable");
        o1.b bVar = this.impl;
        if (bVar != null) {
            if (bVar.f31287d) {
                o1.b.b(autoCloseable);
                return;
            }
            synchronized (bVar.f31284a) {
                autoCloseable2 = (AutoCloseable) bVar.f31285b.put(str, autoCloseable);
            }
            o1.b.b(autoCloseable2);
        }
    }
}
