package androidx.room;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.CancellationSignal;
import android.os.Looper;
import androidx.annotation.CallSuper;
import androidx.annotation.RestrictTo;
import androidx.annotation.WorkerThread;
import com.bytedance.sdk.component.pglcrypt.PglCryptUtils;
import java.util.ArrayList;
import java.util.Iterator;
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.ReentrantLock;
import kotlin.Deprecated;
import kotlin.DeprecationLevel;
import kotlin.Metadata;
import kotlin.NotImplementedError;
import kotlin.Pair;
import kotlin.ReplaceWith;
import kotlin.collections.EmptyList;
import kotlin.collections.EmptySet;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.JvmField;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.JvmSuppressWildcards;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlinx.coroutines.o1;
import kotlinx.coroutines.y0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

    @NotNull
    public static final k0 Companion = new k0();

    @RestrictTo({RestrictTo.Scope.f557c})
    public static final int MAX_BIND_PARAMETER_CNT = 999;
    private boolean allowMainThreadQueries;

    @Nullable
    private h3.a autoCloser;
    private f0 connectionManager;
    private kotlinx.coroutines.x coroutineScope;
    private Executor internalQueryExecutor;
    private q internalTracker;
    private Executor internalTransactionExecutor;

    @JvmField
    @RestrictTo({RestrictTo.Scope.f557c})
    @Nullable
    protected List<? extends j0> mCallbacks;

    @JvmField
    @Nullable
    protected volatile l3.b mDatabase;
    private kotlin.coroutines.h transactionContext;

    @NotNull
    private final f3.a closeBarrier = new f3.a(new RoomDatabase$closeBarrier$1(0, this, RoomDatabase.class, "onClosed", "onClosed()V", 0));

    @NotNull
    private final ThreadLocal<Integer> suspendingTransactionId = new ThreadLocal<>();

    @NotNull
    private final Map<yd.b, Object> typeConverters = new LinkedHashMap();
    private boolean useTempTrackingTable = true;

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    @Metadata(d1 = {"\u0000\f\n\u0000\n\u0002\u0010\u0010\n\u0002\u0018\u0002\n\u0000\b\u0086\u0081\u0002\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001¨\u0006\u0003"}, d2 = {"androidx/room/RoomDatabase$JournalMode", "", "Landroidx/room/RoomDatabase$JournalMode;", "room-runtime_release"}, k = 1, mv = {2, 0, 0})
    public final class JournalMode {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final JournalMode f3995a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final JournalMode f3996b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static final JournalMode f3997c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static final /* synthetic */ JournalMode[] f3998d;

        static {
            JournalMode journalMode = new JournalMode("AUTOMATIC", 0);
            f3995a = journalMode;
            JournalMode journalMode2 = new JournalMode("TRUNCATE", 1);
            f3996b = journalMode2;
            JournalMode journalMode3 = new JournalMode("WRITE_AHEAD_LOGGING", 2);
            f3997c = journalMode3;
            JournalMode[] journalModeArr = {journalMode, journalMode2, journalMode3};
            f3998d = journalModeArr;
            kotlin.enums.b.a(journalModeArr);
        }

        public static JournalMode valueOf(String str) {
            return (JournalMode) Enum.valueOf(JournalMode.class, str);
        }

        public static JournalMode[] values() {
            return (JournalMode[]) f3998d.clone();
        }
    }

    /* JADX INFO: renamed from: androidx.room.RoomDatabase$performClear$1, reason: invalid class name */
    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n"}, d2 = {"Lkotlinx/coroutines/x;", "Lkd/e;", "<anonymous>"}, k = 3, mv = {2, 0, 0})
    @DebugMetadata(c = "androidx.room.RoomDatabase$performClear$1", f = "RoomDatabase.android.kt", i = {}, l = {PglCryptUtils.UNKNOWN_ERR}, m = "invokeSuspend", n = {}, s = {})
    public static final class AnonymousClass1 extends SuspendLambda implements Function2 {
        final /* synthetic */ boolean $hasForeignKeys;
        final /* synthetic */ String[] $tableNames;
        int label;

        /* JADX INFO: renamed from: androidx.room.RoomDatabase$performClear$1$1, reason: invalid class name and collision with other inner class name */
        @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0001\u001a\u00020\u0000H\n"}, d2 = {"Landroidx/room/v0;", "connection", "Lkd/e;", "<anonymous>"}, k = 3, mv = {2, 0, 0})
        @DebugMetadata(c = "androidx.room.RoomDatabase$performClear$1$1", f = "RoomDatabase.android.kt", i = {0, 1, 2, 3, 4}, l = {508, 509, 511, 517, 518, 519}, m = "invokeSuspend", n = {"connection", "connection", "connection", "connection", "connection"}, s = {"L$0", "L$0", "L$0", "L$0", "L$0"})
        final class C00011 extends SuspendLambda implements Function2 {
            final /* synthetic */ boolean $hasForeignKeys;
            final /* synthetic */ String[] $tableNames;
            /* synthetic */ Object L$0;
            int label;
            final /* synthetic */ RoomDatabase this$0;

            /* JADX INFO: renamed from: androidx.room.RoomDatabase$performClear$1$1$1, reason: invalid class name and collision with other inner class name */
            @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0010\u0002\u001a\u00020\u0001*\b\u0012\u0004\u0012\u00020\u00010\u0000H\n"}, d2 = {"Landroidx/room/u0;", "Lkd/e;", "<anonymous>"}, k = 3, mv = {2, 0, 0})
            @DebugMetadata(c = "androidx.room.RoomDatabase$performClear$1$1$1", f = "RoomDatabase.android.kt", i = {0, 1, 1}, l = {513, 515}, m = "invokeSuspend", n = {"$this$withTransaction", "$this$withTransaction", "$this$forEach$iv"}, s = {"L$0", "L$0", "L$1"})
            @SourceDebugExtension({"SMAP\nRoomDatabase.android.kt\nKotlin\n*S Kotlin\n*F\n+ 1 RoomDatabase.android.kt\nandroidx/room/RoomDatabase$performClear$1$1$1\n+ 2 _Arrays.kt\nkotlin/collections/ArraysKt___ArraysKt\n*L\n1#1,2151:1\n13402#2,2:2152\n*S KotlinDebug\n*F\n+ 1 RoomDatabase.android.kt\nandroidx/room/RoomDatabase$performClear$1$1$1\n*L\n515#1:2152,2\n*E\n"})
            final class C00021 extends SuspendLambda implements Function2 {
                final /* synthetic */ boolean $hasForeignKeys;
                final /* synthetic */ String[] $tableNames;
                int I$0;
                int I$1;
                private /* synthetic */ Object L$0;
                Object L$1;
                int label;

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                public C00021(boolean z10, String[] strArr, Continuation continuation) {
                    super(2, continuation);
                    this.$hasForeignKeys = z10;
                    this.$tableNames = strArr;
                }

                @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
                public final Continuation create(Object obj, Continuation continuation) {
                    C00021 c00021 = new C00021(this.$hasForeignKeys, this.$tableNames, continuation);
                    c00021.L$0 = obj;
                    return c00021;
                }

                @Override // kotlin.jvm.functions.Function2
                public final Object invoke(Object obj, Object obj2) {
                    return ((C00021) create((u0) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
                }

                /* JADX WARN: Removed duplicated region for block: B:17:0x0051  */
                /* JADX WARN: Removed duplicated region for block: B:21:0x0079  */
                /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:18:0x0074 -> B:20:0x0077). Please report as a decompilation issue!!! */
                @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
                /*
                    Code decompiled incorrectly, please refer to instructions dump.
                */
                public final Object invokeSuspend(Object obj) {
                    u0 u0Var;
                    u0 u0Var2;
                    int length;
                    int i10;
                    String[] strArr;
                    C00021 c00021;
                    CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
                    int i11 = this.label;
                    if (i11 == 0) {
                        kotlin.a.d(obj);
                        u0Var = (u0) this.L$0;
                        if (this.$hasForeignKeys) {
                            this.L$0 = u0Var;
                            this.label = 1;
                            if (ua.b.s(u0Var, "PRAGMA defer_foreign_keys = TRUE", this) == coroutineSingletons) {
                                return coroutineSingletons;
                            }
                        }
                    } else if (i11 == 1) {
                        u0Var = (u0) this.L$0;
                        kotlin.a.d(obj);
                    } else {
                        if (i11 != 2) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        length = this.I$1;
                        i10 = this.I$0;
                        strArr = (String[]) this.L$1;
                        u0Var2 = (u0) this.L$0;
                        kotlin.a.d(obj);
                        c00021 = this;
                        i10++;
                        if (i10 < length) {
                            String str = "DELETE FROM `" + strArr[i10] + '`';
                            c00021.L$0 = u0Var2;
                            c00021.L$1 = strArr;
                            c00021.I$0 = i10;
                            c00021.I$1 = length;
                            c00021.label = 2;
                            if (ua.b.s(u0Var2, str, c00021) == coroutineSingletons) {
                                return coroutineSingletons;
                            }
                            i10++;
                            if (i10 < length) {
                                return kd.e.f29109a;
                            }
                        }
                    }
                    String[] strArr2 = this.$tableNames;
                    u0Var2 = u0Var;
                    length = strArr2.length;
                    i10 = 0;
                    strArr = strArr2;
                    c00021 = this;
                    if (i10 < length) {
                    }
                }
            }

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public C00011(RoomDatabase roomDatabase, boolean z10, String[] strArr, Continuation continuation) {
                super(2, continuation);
                this.this$0 = roomDatabase;
                this.$hasForeignKeys = z10;
                this.$tableNames = strArr;
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Continuation create(Object obj, Continuation continuation) {
                C00011 c00011 = new C00011(this.this$0, this.$hasForeignKeys, this.$tableNames, continuation);
                c00011.L$0 = obj;
                return c00011;
            }

            @Override // kotlin.jvm.functions.Function2
            public final Object invoke(Object obj, Object obj2) {
                return ((C00011) create((v0) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
            }

            /* JADX WARN: Removed duplicated region for block: B:18:0x005c  */
            /* JADX WARN: Removed duplicated region for block: B:23:0x0084 A[RETURN] */
            /* JADX WARN: Removed duplicated region for block: B:26:0x0090 A[RETURN] */
            /* JADX WARN: Removed duplicated region for block: B:29:0x0099  */
            /* JADX WARN: Removed duplicated region for block: B:34:0x00b4 A[RETURN] */
            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public final Object invokeSuspend(Object obj) {
                v0 v0Var;
                Transactor$SQLiteTransactionType transactor$SQLiteTransactionType;
                C00021 c00021;
                CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
                switch (this.label) {
                    case 0:
                        kotlin.a.d(obj);
                        v0 v0Var2 = (v0) this.L$0;
                        this.L$0 = v0Var2;
                        this.label = 1;
                        Object objB = v0Var2.b(this);
                        if (objB == coroutineSingletons) {
                            return coroutineSingletons;
                        }
                        v0Var = v0Var2;
                        obj = objB;
                        if (!((Boolean) obj).booleanValue()) {
                            q invalidationTracker = this.this$0.getInvalidationTracker();
                            this.L$0 = v0Var;
                            this.label = 2;
                            if (invalidationTracker.a(this) == coroutineSingletons) {
                                return coroutineSingletons;
                            }
                        }
                        transactor$SQLiteTransactionType = Transactor$SQLiteTransactionType.f4000b;
                        c00021 = new C00021(this.$hasForeignKeys, this.$tableNames, null);
                        this.L$0 = v0Var;
                        this.label = 3;
                        if (v0Var.a(transactor$SQLiteTransactionType, c00021, this) == coroutineSingletons) {
                            return coroutineSingletons;
                        }
                        this.L$0 = v0Var;
                        this.label = 4;
                        obj = v0Var.b(this);
                        if (obj == coroutineSingletons) {
                            return coroutineSingletons;
                        }
                        if (!((Boolean) obj).booleanValue()) {
                            this.L$0 = v0Var;
                            this.label = 5;
                            if (ua.b.s(v0Var, "PRAGMA wal_checkpoint(FULL)", this) == coroutineSingletons) {
                                return coroutineSingletons;
                            }
                            this.L$0 = null;
                            this.label = 6;
                            if (ua.b.s(v0Var, "VACUUM", this) == coroutineSingletons) {
                                return coroutineSingletons;
                            }
                            q invalidationTracker2 = this.this$0.getInvalidationTracker();
                            invalidationTracker2.f4126e.e(invalidationTracker2.f4129h, invalidationTracker2.f4130i);
                        }
                        return kd.e.f29109a;
                    case 1:
                        v0Var = (v0) this.L$0;
                        kotlin.a.d(obj);
                        if (!((Boolean) obj).booleanValue()) {
                        }
                        transactor$SQLiteTransactionType = Transactor$SQLiteTransactionType.f4000b;
                        c00021 = new C00021(this.$hasForeignKeys, this.$tableNames, null);
                        this.L$0 = v0Var;
                        this.label = 3;
                        if (v0Var.a(transactor$SQLiteTransactionType, c00021, this) == coroutineSingletons) {
                        }
                        this.L$0 = v0Var;
                        this.label = 4;
                        obj = v0Var.b(this);
                        if (obj == coroutineSingletons) {
                        }
                        if (!((Boolean) obj).booleanValue()) {
                        }
                        return kd.e.f29109a;
                    case 2:
                        v0Var = (v0) this.L$0;
                        kotlin.a.d(obj);
                        transactor$SQLiteTransactionType = Transactor$SQLiteTransactionType.f4000b;
                        c00021 = new C00021(this.$hasForeignKeys, this.$tableNames, null);
                        this.L$0 = v0Var;
                        this.label = 3;
                        if (v0Var.a(transactor$SQLiteTransactionType, c00021, this) == coroutineSingletons) {
                        }
                        this.L$0 = v0Var;
                        this.label = 4;
                        obj = v0Var.b(this);
                        if (obj == coroutineSingletons) {
                        }
                        if (!((Boolean) obj).booleanValue()) {
                        }
                        return kd.e.f29109a;
                    case 3:
                        v0Var = (v0) this.L$0;
                        kotlin.a.d(obj);
                        this.L$0 = v0Var;
                        this.label = 4;
                        obj = v0Var.b(this);
                        if (obj == coroutineSingletons) {
                        }
                        if (!((Boolean) obj).booleanValue()) {
                        }
                        return kd.e.f29109a;
                    case 4:
                        v0Var = (v0) this.L$0;
                        kotlin.a.d(obj);
                        if (!((Boolean) obj).booleanValue()) {
                        }
                        return kd.e.f29109a;
                    case 5:
                        v0Var = (v0) this.L$0;
                        kotlin.a.d(obj);
                        this.L$0 = null;
                        this.label = 6;
                        if (ua.b.s(v0Var, "VACUUM", this) == coroutineSingletons) {
                        }
                        q invalidationTracker22 = this.this$0.getInvalidationTracker();
                        invalidationTracker22.f4126e.e(invalidationTracker22.f4129h, invalidationTracker22.f4130i);
                        return kd.e.f29109a;
                    case 6:
                        kotlin.a.d(obj);
                        q invalidationTracker222 = this.this$0.getInvalidationTracker();
                        invalidationTracker222.f4126e.e(invalidationTracker222.f4129h, invalidationTracker222.f4130i);
                        return kd.e.f29109a;
                    default:
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
            }
        }

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(boolean z10, String[] strArr, Continuation continuation) {
            super(2, continuation);
            this.$hasForeignKeys = z10;
            this.$tableNames = strArr;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation create(Object obj, Continuation continuation) {
            return RoomDatabase.this.new AnonymousClass1(this.$hasForeignKeys, this.$tableNames, continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(Object obj, Object obj2) {
            return ((AnonymousClass1) create((kotlinx.coroutines.x) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
            int i10 = this.label;
            if (i10 == 0) {
                kotlin.a.d(obj);
                f0 f0Var = RoomDatabase.this.connectionManager;
                if (f0Var == null) {
                    nb.g.U("connectionManager");
                    throw null;
                }
                C00011 c00011 = new C00011(RoomDatabase.this, this.$hasForeignKeys, this.$tableNames, null);
                this.label = 1;
                if (f0Var.f4086f.r(false, c00011, this) == coroutineSingletons) {
                    return coroutineSingletons;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                kotlin.a.d(obj);
            }
            return kd.e.f29109a;
        }
    }

    public static final void access$onClosed(RoomDatabase roomDatabase) throws Exception {
        kotlinx.coroutines.x xVar = roomDatabase.coroutineScope;
        if (xVar == null) {
            nb.g.U("coroutineScope");
            throw null;
        }
        y0 y0Var = (y0) xVar.getCoroutineContext().m(kotlinx.coroutines.u.f29565b);
        if (y0Var == null) {
            throw new IllegalStateException(("Scope cannot be cancelled because it does not have a job: " + xVar).toString());
        }
        y0Var.e(null);
        u uVar = roomDatabase.getInvalidationTracker().f4132k;
        if (uVar != null) {
            uVar.b();
        }
        f0 f0Var = roomDatabase.connectionManager;
        if (f0Var != null) {
            f0Var.f4086f.close();
        } else {
            nb.g.U("connectionManager");
            throw null;
        }
    }

    @Deprecated(level = DeprecationLevel.f29179b, message = "This property is always null and will be removed in a future version.")
    public static /* synthetic */ void getMCallbacks$annotations() {
    }

    @Deprecated(level = DeprecationLevel.f29179b, message = "This property is always null and will be removed in a future version.")
    public static /* synthetic */ void getMDatabase$annotations() {
    }

    public static /* synthetic */ Cursor query$default(RoomDatabase roomDatabase, l3.i iVar, CancellationSignal cancellationSignal, int i10, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: query");
        }
        if ((i10 & 2) != 0) {
            cancellationSignal = null;
        }
        return roomDatabase.query(iVar, cancellationSignal);
    }

    public final void a() {
        assertNotMainThread();
        l3.b bVarC = getOpenHelper().c();
        if (!bVarC.B()) {
            q invalidationTracker = getInvalidationTracker();
            invalidationTracker.getClass();
            androidx.room.coroutines.m.a(new InvalidationTracker$syncBlocking$1(invalidationTracker, null));
        }
        if (bVarC.D()) {
            bVarC.v();
        } else {
            bVarC.f();
        }
    }

    public final void addTypeConverter$room_runtime_release(@NotNull yd.b bVar, @NotNull Object obj) {
        nb.g.i(bVar, "kclass");
        nb.g.i(obj, "converter");
        this.typeConverters.put(bVar, obj);
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    public void assertNotMainThread() {
        if (!this.allowMainThreadQueries && !(!isMainThread$room_runtime_release())) {
            throw new IllegalStateException("Cannot access database on the main thread since it may potentially lock the UI for a long period of time.".toString());
        }
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    public void assertNotSuspendingTransaction() {
        if (inCompatibilityMode$room_runtime_release() && !inTransaction() && this.suspendingTransactionId.get() != null) {
            throw new IllegalStateException("Cannot access database on a different coroutine context inherited from a suspending transaction.".toString());
        }
    }

    public final Object b(g0 g0Var) {
        if (!inCompatibilityMode$room_runtime_release()) {
            return androidx.room.util.b.b(this, false, true, new b0(g0Var, 1));
        }
        beginTransaction();
        try {
            Object objInvoke = g0Var.invoke();
            setTransactionSuccessful();
            return objInvoke;
        } finally {
            endTransaction();
        }
    }

    @Deprecated(message = "beginTransaction() is deprecated", replaceWith = @ReplaceWith(expression = "runInTransaction(Runnable)", imports = {}))
    public void beginTransaction() {
        assertNotMainThread();
        a();
    }

    @WorkerThread
    public abstract void clearAllTables();

    public void close() {
        f3.a aVar = this.closeBarrier;
        synchronized (aVar) {
            if (aVar.f25937c.compareAndSet(false, true)) {
                while (aVar.f25936b.get() != 0) {
                }
                aVar.f25935a.invoke();
            }
        }
    }

    @NotNull
    public l3.j compileStatement(@NotNull String str) {
        nb.g.i(str, "sql");
        assertNotMainThread();
        assertNotSuspendingTransaction();
        return getOpenHelper().c().o(str);
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public List<g3.a> createAutoMigrations(@NotNull Map<yd.b, Object> map) {
        nb.g.i(map, "autoMigrationSpecs");
        LinkedHashMap linkedHashMap = new LinkedHashMap(ua.b.D(map.size()));
        Iterator<T> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            linkedHashMap.put(nb.g.B((yd.b) entry.getKey()), entry.getValue());
        }
        return getAutoMigrations(linkedHashMap);
    }

    @NotNull
    public final f0 createConnectionManager$room_runtime_release(@NotNull e eVar) {
        n0 n0Var;
        nb.g.i(eVar, "configuration");
        try {
            o0 o0VarCreateOpenDelegate = createOpenDelegate();
            nb.g.g(o0VarCreateOpenDelegate, "null cannot be cast to non-null type androidx.room.RoomOpenDelegate");
            n0Var = (n0) o0VarCreateOpenDelegate;
        } catch (NotImplementedError unused) {
            n0Var = null;
        }
        return n0Var == null ? new f0(eVar, new h0(this, 2)) : new f0(eVar, n0Var);
    }

    @NotNull
    public abstract q createInvalidationTracker();

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public o0 createOpenDelegate() {
        throw new NotImplementedError();
    }

    @Deprecated(message = "No longer implemented by generated")
    @NotNull
    public l3.g createOpenHelper(@NotNull e eVar) {
        nb.g.i(eVar, "config");
        throw new NotImplementedError();
    }

    @Deprecated(message = "endTransaction() is deprecated", replaceWith = @ReplaceWith(expression = "runInTransaction(Runnable)", imports = {}))
    public void endTransaction() {
        getOpenHelper().c().z();
        if (inTransaction()) {
            return;
        }
        q invalidationTracker = getInvalidationTracker();
        invalidationTracker.f4126e.e(invalidationTracker.f4129h, invalidationTracker.f4130i);
    }

    @JvmSuppressWildcards
    @NotNull
    @Deprecated(message = "No longer implemented by generated")
    @RestrictTo({RestrictTo.Scope.f557c})
    public List<g3.a> getAutoMigrations(@NotNull Map<Class<Object>, Object> map) {
        nb.g.i(map, "autoMigrationSpecs");
        return EmptyList.f29203a;
    }

    @NotNull
    public final f3.a getCloseBarrier$room_runtime_release() {
        return this.closeBarrier;
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    @NotNull
    public final kotlinx.coroutines.x getCoroutineScope() {
        kotlinx.coroutines.x xVar = this.coroutineScope;
        if (xVar != null) {
            return xVar;
        }
        nb.g.U("coroutineScope");
        throw null;
    }

    @NotNull
    public q getInvalidationTracker() {
        q qVar = this.internalTracker;
        if (qVar != null) {
            return qVar;
        }
        nb.g.U("internalTracker");
        throw null;
    }

    @NotNull
    public l3.g getOpenHelper() {
        f0 f0Var = this.connectionManager;
        if (f0Var == null) {
            nb.g.U("connectionManager");
            throw null;
        }
        l3.g gVarH = f0Var.h();
        if (gVarH != null) {
            return gVarH;
        }
        throw new IllegalStateException("Cannot return a SupportSQLiteOpenHelper since no SupportSQLiteOpenHelper.Factory was configured with Room.".toString());
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    @NotNull
    public final kotlin.coroutines.h getQueryContext() {
        kotlinx.coroutines.x xVar = this.coroutineScope;
        if (xVar != null) {
            return xVar.getCoroutineContext();
        }
        nb.g.U("coroutineScope");
        throw null;
    }

    @NotNull
    public Executor getQueryExecutor() {
        Executor executor = this.internalQueryExecutor;
        if (executor != null) {
            return executor;
        }
        nb.g.U("internalQueryExecutor");
        throw null;
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public Set<yd.b> getRequiredAutoMigrationSpecClasses() {
        Set<Class<Object>> requiredAutoMigrationSpecs = getRequiredAutoMigrationSpecs();
        ArrayList arrayList = new ArrayList(kotlin.collections.i.Z0(10, requiredAutoMigrationSpecs));
        Iterator<T> it = requiredAutoMigrationSpecs.iterator();
        while (it.hasNext()) {
            Class cls = (Class) it.next();
            nb.g.i(cls, "<this>");
            arrayList.add(kotlin.jvm.internal.g.a(cls));
        }
        return kotlin.collections.n.t1(arrayList);
    }

    @Deprecated(message = "No longer implemented by generated")
    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public Set<Class<Object>> getRequiredAutoMigrationSpecs() {
        return EmptySet.f29205a;
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public Map<yd.b, List<yd.b>> getRequiredTypeConverterClasses() {
        Set<Map.Entry<Class<?>, List<Class<?>>>> setEntrySet = getRequiredTypeConverters().entrySet();
        int iD = ua.b.D(kotlin.collections.i.Z0(10, setEntrySet));
        if (iD < 16) {
            iD = 16;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(iD);
        Iterator<T> it = setEntrySet.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Class cls = (Class) entry.getKey();
            List list = (List) entry.getValue();
            nb.g.i(cls, "<this>");
            kotlin.jvm.internal.b bVarA = kotlin.jvm.internal.g.a(cls);
            List<Class> list2 = list;
            ArrayList arrayList = new ArrayList(kotlin.collections.i.Z0(10, list2));
            for (Class cls2 : list2) {
                nb.g.i(cls2, "<this>");
                arrayList.add(kotlin.jvm.internal.g.a(cls2));
            }
            Pair pair = new Pair(bVarA, arrayList);
            linkedHashMap.put(pair.c(), pair.d());
        }
        return linkedHashMap;
    }

    @NotNull
    public final Map<yd.b, List<yd.b>> getRequiredTypeConverterClassesMap$room_runtime_release() {
        return getRequiredTypeConverterClasses();
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public Map<Class<?>, List<Class<?>>> getRequiredTypeConverters() {
        return kotlin.collections.q.V();
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    @NotNull
    public final ThreadLocal<Integer> getSuspendingTransactionId() {
        return this.suspendingTransactionId;
    }

    @NotNull
    public final kotlin.coroutines.h getTransactionContext$room_runtime_release() {
        kotlin.coroutines.h hVar = this.transactionContext;
        if (hVar != null) {
            return hVar;
        }
        nb.g.U("transactionContext");
        throw null;
    }

    @NotNull
    public Executor getTransactionExecutor() {
        Executor executor = this.internalTransactionExecutor;
        if (executor != null) {
            return executor;
        }
        nb.g.U("internalTransactionExecutor");
        throw null;
    }

    @Deprecated(message = "No longer called by generated implementation")
    @Nullable
    public <T> T getTypeConverter(@NotNull Class<T> cls) {
        nb.g.i(cls, "klass");
        return (T) this.typeConverters.get(kotlin.jvm.internal.g.a(cls));
    }

    public final boolean getUseTempTrackingTable$room_runtime_release() {
        return this.useTempTrackingTable;
    }

    public final boolean inCompatibilityMode$room_runtime_release() {
        f0 f0Var = this.connectionManager;
        if (f0Var != null) {
            return f0Var.h() != null;
        }
        nb.g.U("connectionManager");
        throw null;
    }

    public boolean inTransaction() {
        return isOpenInternal() && getOpenHelper().c().B();
    }

    /* JADX WARN: Code restructure failed: missing block: B:27:0x00a8, code lost:
    
        throw new java.lang.IllegalArgumentException("Unexpected auto migration specs found. Annotate AutoMigrationSpec implementation with @ProvidedAutoMigrationSpec annotation or remove this spec from the builder.".toString());
     */
    @CallSuper
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void init(@NotNull e eVar) {
        Executor g0Var;
        kotlin.coroutines.h coroutineContext;
        nb.g.i(eVar, "configuration");
        this.useTempTrackingTable = eVar.f4081v;
        this.connectionManager = createConnectionManager$room_runtime_release(eVar);
        this.internalTracker = createInvalidationTracker();
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        Set<yd.b> requiredAutoMigrationSpecClasses = getRequiredAutoMigrationSpecClasses();
        List list = eVar.f4077r;
        int size = list.size();
        boolean[] zArr = new boolean[size];
        Iterator<yd.b> it = requiredAutoMigrationSpecClasses.iterator();
        while (true) {
            int i10 = -1;
            if (!it.hasNext()) {
                int size2 = list.size() - 1;
                if (size2 >= 0) {
                    while (true) {
                        int i11 = size2 - 1;
                        if (size2 >= size || !zArr[size2]) {
                            break;
                        } else if (i11 < 0) {
                            break;
                        } else {
                            size2 = i11;
                        }
                    }
                }
                for (g3.a aVar : createAutoMigrations(linkedHashMap)) {
                    int i12 = aVar.startVersion;
                    int i13 = aVar.endVersion;
                    l0 l0Var = eVar.f4063d;
                    LinkedHashMap linkedHashMap2 = l0Var.f4113a;
                    if (linkedHashMap2.containsKey(Integer.valueOf(i12))) {
                        Map mapV = (Map) linkedHashMap2.get(Integer.valueOf(i12));
                        if (mapV == null) {
                            mapV = kotlin.collections.q.V();
                        }
                        if (!mapV.containsKey(Integer.valueOf(i13))) {
                        }
                    }
                    l0Var.a(aVar);
                }
                Map<yd.b, List<yd.b>> requiredTypeConverterClassesMap$room_runtime_release = getRequiredTypeConverterClassesMap$room_runtime_release();
                List list2 = eVar.f4076q;
                boolean[] zArr2 = new boolean[list2.size()];
                for (Map.Entry<yd.b, List<yd.b>> entry : requiredTypeConverterClassesMap$room_runtime_release.entrySet()) {
                    yd.b key = entry.getKey();
                    for (yd.b bVar : entry.getValue()) {
                        int size3 = list2.size() - 1;
                        if (size3 >= 0) {
                            while (true) {
                                int i14 = size3 - 1;
                                if (((kotlin.jvm.internal.b) bVar).d(list2.get(size3))) {
                                    zArr2[size3] = true;
                                    break;
                                } else if (i14 < 0) {
                                    break;
                                } else {
                                    size3 = i14;
                                }
                            }
                            size3 = -1;
                        } else {
                            size3 = -1;
                        }
                        if (size3 < 0) {
                            throw new IllegalArgumentException(("A required type converter (" + ((kotlin.jvm.internal.b) bVar).b() + ") for " + ((kotlin.jvm.internal.b) key).b() + " is missing in the database configuration.").toString());
                        }
                        addTypeConverter$room_runtime_release(bVar, list2.get(size3));
                    }
                }
                int size4 = list2.size() - 1;
                if (size4 >= 0) {
                    while (true) {
                        int i15 = size4 - 1;
                        if (!zArr2[size4]) {
                            throw new IllegalArgumentException("Unexpected type converter " + list2.get(size4) + ". Annotate TypeConverter class with @ProvidedTypeConverter annotation or remove this converter from the builder.");
                        }
                        if (i15 < 0) {
                            break;
                        } else {
                            size4 = i15;
                        }
                    }
                }
                l3.g gVar = null;
                kotlin.coroutines.h hVar = eVar.f4080u;
                if (hVar != null) {
                    kotlin.coroutines.f fVarM = hVar.m(kotlin.coroutines.c.f29225a);
                    nb.g.g(fVarM, "null cannot be cast to non-null type kotlinx.coroutines.CoroutineDispatcher");
                    kotlinx.coroutines.t tVar = (kotlinx.coroutines.t) fVarM;
                    kotlinx.coroutines.r0 r0Var = tVar instanceof kotlinx.coroutines.r0 ? (kotlinx.coroutines.r0) tVar : null;
                    if (r0Var == null || (g0Var = r0Var.O()) == null) {
                        g0Var = new kotlinx.coroutines.g0(tVar);
                    }
                    this.internalQueryExecutor = g0Var;
                    this.internalTransactionExecutor = new e.u(g0Var, 1);
                    this.coroutineScope = kotlinx.coroutines.y.b(hVar.p(new o1((y0) hVar.m(kotlinx.coroutines.u.f29565b))));
                    if (inCompatibilityMode$room_runtime_release()) {
                        kotlinx.coroutines.x xVar = this.coroutineScope;
                        if (xVar == null) {
                            nb.g.U("coroutineScope");
                            throw null;
                        }
                        coroutineContext = xVar.getCoroutineContext().p(tVar.N(1));
                    } else {
                        kotlinx.coroutines.x xVar2 = this.coroutineScope;
                        if (xVar2 == null) {
                            nb.g.U("coroutineScope");
                            throw null;
                        }
                        coroutineContext = xVar2.getCoroutineContext();
                    }
                    this.transactionContext = coroutineContext;
                } else {
                    this.internalQueryExecutor = eVar.f4067h;
                    this.internalTransactionExecutor = new e.u(eVar.f4068i, 1);
                    Executor executor = this.internalQueryExecutor;
                    if (executor == null) {
                        nb.g.U("internalQueryExecutor");
                        throw null;
                    }
                    kotlinx.coroutines.internal.e eVarB = kotlinx.coroutines.y.b(kotlin.coroutines.e.a(kotlinx.coroutines.y.o(executor), new o1(null)));
                    this.coroutineScope = eVarB;
                    Executor executor2 = this.internalTransactionExecutor;
                    if (executor2 == null) {
                        nb.g.U("internalTransactionExecutor");
                        throw null;
                    }
                    this.transactionContext = eVarB.f29458a.p(kotlinx.coroutines.y.o(executor2));
                }
                this.allowMainThreadQueries = eVar.f4065f;
                f0 f0Var = this.connectionManager;
                if (f0Var == null) {
                    nb.g.U("connectionManager");
                    throw null;
                }
                l3.g gVarH = f0Var.h();
                if (gVarH == null) {
                    gVarH = null;
                    break;
                }
                while (!(gVarH instanceof h3.g)) {
                    if (!(gVarH instanceof f)) {
                        gVarH = null;
                        break;
                    }
                    gVarH = ((f) gVarH).e();
                }
                f0 f0Var2 = this.connectionManager;
                if (f0Var2 == null) {
                    nb.g.U("connectionManager");
                    throw null;
                }
                l3.g gVarH2 = f0Var2.h();
                if (gVarH2 != null) {
                    while (true) {
                        if (gVarH2 instanceof h3.f) {
                            gVar = gVarH2;
                            break;
                        } else if (!(gVarH2 instanceof f)) {
                            break;
                        } else {
                            gVarH2 = ((f) gVarH2).e();
                        }
                    }
                }
                Intent intent = eVar.f4069j;
                if (intent != null) {
                    String str = eVar.f4061b;
                    if (str == null) {
                        throw new IllegalArgumentException("Required value was null.".toString());
                    }
                    q invalidationTracker = getInvalidationTracker();
                    invalidationTracker.getClass();
                    Context context = eVar.f4060a;
                    nb.g.i(context, "context");
                    invalidationTracker.f4131j = intent;
                    invalidationTracker.f4132k = new u(context, str, invalidationTracker);
                    return;
                }
                return;
            }
            yd.b next = it.next();
            int size5 = list.size() - 1;
            if (size5 >= 0) {
                while (true) {
                    int i16 = size5 - 1;
                    if (((kotlin.jvm.internal.b) next).d(list.get(size5))) {
                        zArr[size5] = true;
                        i10 = size5;
                        break;
                    } else if (i16 < 0) {
                        break;
                    } else {
                        size5 = i16;
                    }
                }
            }
            if (i10 < 0) {
                throw new IllegalArgumentException(("A required auto migration spec (" + ((kotlin.jvm.internal.b) next).b() + ") is missing in the database configuration.").toString());
            }
            linkedHashMap.put(next, list.get(i10));
        }
    }

    @Deprecated(message = "No longer called by generated")
    public void internalInitInvalidationTracker(@NotNull l3.b bVar) throws Exception {
        nb.g.i(bVar, "db");
        internalInitInvalidationTracker(new androidx.room.driver.a(bVar));
    }

    public final boolean isMainThread$room_runtime_release() {
        return Looper.getMainLooper().getThread() == Thread.currentThread();
    }

    public boolean isOpen() {
        f0 f0Var = this.connectionManager;
        if (f0Var == null) {
            nb.g.U("connectionManager");
            throw null;
        }
        l3.b bVar = f0Var.f4087g;
        if (bVar != null) {
            return bVar.isOpen();
        }
        return false;
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    public final boolean isOpenInternal() {
        f0 f0Var = this.connectionManager;
        if (f0Var == null) {
            nb.g.U("connectionManager");
            throw null;
        }
        l3.b bVar = f0Var.f4087g;
        if (bVar != null) {
            return bVar.isOpen();
        }
        return false;
    }

    @RestrictTo({RestrictTo.Scope.f556b})
    public final void performClear(boolean z10, @NotNull String... strArr) {
        nb.g.i(strArr, "tableNames");
        assertNotMainThread();
        assertNotSuspendingTransaction();
        androidx.room.coroutines.m.a(new AnonymousClass1(z10, strArr, null));
    }

    @JvmOverloads
    @NotNull
    public final Cursor query(@NotNull l3.i iVar) {
        nb.g.i(iVar, "query");
        return query$default(this, iVar, null, 2, null);
    }

    public void runInTransaction(@NotNull Runnable runnable) {
        nb.g.i(runnable, "body");
        b(new g0(runnable, 1));
    }

    @Deprecated(message = "setTransactionSuccessful() is deprecated", replaceWith = @ReplaceWith(expression = "runInTransaction(Runnable)", imports = {}))
    public void setTransactionSuccessful() {
        getOpenHelper().c().t();
    }

    public final void setUseTempTrackingTable$room_runtime_release(boolean z10) {
        this.useTempTrackingTable = z10;
    }

    @Nullable
    public final <R> Object useConnection$room_runtime_release(boolean z10, @NotNull Function2 function2, @NotNull Continuation continuation) {
        f0 f0Var = this.connectionManager;
        if (f0Var != null) {
            return f0Var.f4086f.r(z10, function2, continuation);
        }
        nb.g.U("connectionManager");
        throw null;
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    public final void internalInitInvalidationTracker(@NotNull k3.a aVar) throws Exception {
        nb.g.i(aVar, "connection");
        q invalidationTracker = getInvalidationTracker();
        invalidationTracker.getClass();
        x0 x0Var = invalidationTracker.f4126e;
        x0Var.getClass();
        k3.c cVarJ = aVar.J("PRAGMA query_only");
        try {
            cVarJ.G();
            boolean z10 = cVarJ.getLong(0) != 0;
            ua.b.h(cVarJ, null);
            if (!z10) {
                ua.b.t("PRAGMA temp_store = MEMORY", aVar);
                ua.b.t("PRAGMA recursive_triggers = 1", aVar);
                ua.b.t("DROP TABLE IF EXISTS room_table_modification_log", aVar);
                if (x0Var.f4203d) {
                    ua.b.t("CREATE TEMP TABLE IF NOT EXISTS room_table_modification_log (table_id INTEGER PRIMARY KEY, invalidated INTEGER NOT NULL DEFAULT 0)", aVar);
                } else {
                    ua.b.t(kotlin.text.h.h0("CREATE TEMP TABLE IF NOT EXISTS room_table_modification_log (table_id INTEGER PRIMARY KEY, invalidated INTEGER NOT NULL DEFAULT 0)", "TEMP", ""), aVar);
                }
                x xVar = x0Var.f4207h;
                ReentrantLock reentrantLock = (ReentrantLock) xVar.f4197c;
                reentrantLock.lock();
                try {
                    xVar.f4196b = true;
                } finally {
                    reentrantLock.unlock();
                }
            }
            synchronized (invalidationTracker.f4133l) {
                try {
                    u uVar = invalidationTracker.f4132k;
                    if (uVar != null) {
                        Intent intent = invalidationTracker.f4131j;
                        if (intent == null) {
                            throw new IllegalStateException("Required value was null.".toString());
                        }
                        uVar.a(intent);
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        } finally {
        }
    }

    @NotNull
    public Cursor query(@NotNull String str, @Nullable Object[] objArr) {
        nb.g.i(str, "query");
        assertNotMainThread();
        assertNotSuspendingTransaction();
        return getOpenHelper().c().C(new l3.a(str, objArr));
    }

    public <V> V runInTransaction(@NotNull Callable<V> callable) {
        nb.g.i(callable, "body");
        return (V) b(new g0(callable, 0));
    }

    @RestrictTo({RestrictTo.Scope.f557c})
    @NotNull
    public final <T> T getTypeConverter(@NotNull yd.b bVar) {
        nb.g.i(bVar, "klass");
        T t10 = (T) this.typeConverters.get(bVar);
        nb.g.g(t10, "null cannot be cast to non-null type T of androidx.room.RoomDatabase.getTypeConverter");
        return t10;
    }

    @JvmOverloads
    @NotNull
    public Cursor query(@NotNull l3.i iVar, @Nullable CancellationSignal cancellationSignal) {
        nb.g.i(iVar, "query");
        assertNotMainThread();
        assertNotSuspendingTransaction();
        if (cancellationSignal != null) {
            return getOpenHelper().c().K(iVar, cancellationSignal);
        }
        return getOpenHelper().c().C(iVar);
    }
}
