package androidx.work.impl;

import android.database.Cursor;
import android.os.Looper;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import o.C0093Dp;
import o.C0332Mv;
import o.C0358Nv;
import o.C0462Rv;
import o.C1390hY;
import o.C2062oc0;
import o.C3031ym0;
import o.C3040yr;
import o.C3126zm0;
import o.Em0;
import o.FC;
import o.Gm0;
import o.Hb0;
import o.II;
import o.InterfaceC0587Wq;
import o.Jb0;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public abstract class WorkDatabase {
    public volatile FC a;
    public Executor b;
    public Hb0 c;
    public boolean e;
    public List f;
    public final LinkedHashMap j;
    public final II d = d();
    public final LinkedHashMap g = new LinkedHashMap();
    public final ReentrantReadWriteLock h = new ReentrantReadWriteLock();
    public final ThreadLocal i = new ThreadLocal();

    public WorkDatabase() {
        Collections.synchronizedMap(new LinkedHashMap());
        this.j = new LinkedHashMap();
    }

    public static Object p(Class cls, Hb0 hb0) {
        if (cls.isInstance(hb0)) {
            return hb0;
        }
        if (hb0 instanceof InterfaceC0587Wq) {
            return p(cls, ((InterfaceC0587Wq) hb0).b());
        }
        return null;
    }

    public final void a() {
        if (!this.e && Looper.getMainLooper().getThread() == Thread.currentThread()) {
            throw new IllegalStateException("Cannot access database on the main thread since it may potentially lock the UI for a long period of time.");
        }
    }

    public final void b() {
        Hb0 hb0 = this.c;
        if (hb0 == null) {
            hb0 = null;
        }
        if (!hb0.L().l() && this.i.get() != null) {
            throw new IllegalStateException("Cannot access database on a different coroutine context inherited from a suspending transaction.");
        }
    }

    public final void c() {
        a();
        a();
        Hb0 hb0 = this.c;
        if (hb0 == null) {
            hb0 = null;
        }
        FC fcL = hb0.L();
        this.d.c(fcL);
        if (fcL.m()) {
            fcL.c();
        } else {
            fcL.b();
        }
    }

    public abstract II d();

    public abstract Hb0 e(C0093Dp c0093Dp);

    public abstract C3040yr f();

    public List g() {
        return C0332Mv.l;
    }

    public Set h() {
        return C0462Rv.l;
    }

    public Map i() {
        return C0358Nv.l;
    }

    public final void j() {
        Hb0 hb0 = this.c;
        if (hb0 == null) {
            hb0 = null;
        }
        hb0.L().f();
        Hb0 hb02 = this.c;
        if (hb02 == null) {
            hb02 = null;
        }
        if (hb02.L().l()) {
            return;
        }
        II ii = this.d;
        if (ii.e.compareAndSet(false, true)) {
            Executor executor = ii.a.b;
            (executor != null ? executor : null).execute(ii.l);
        }
    }

    public abstract C1390hY k();

    public final Cursor l(Jb0 jb0) {
        a();
        b();
        Hb0 hb0 = this.c;
        if (hb0 == null) {
            hb0 = null;
        }
        return hb0.L().u(jb0);
    }

    public final Object m(Callable callable) {
        c();
        try {
            Object objCall = callable.call();
            n();
            return objCall;
        } finally {
            j();
        }
    }

    public final void n() {
        Hb0 hb0 = this.c;
        if (hb0 == null) {
            hb0 = null;
        }
        hb0.L().w();
    }

    public abstract C2062oc0 o();

    public abstract C3031ym0 q();

    public abstract C3126zm0 r();

    public abstract Em0 s();

    public abstract Gm0 t();
}
