package androidx.room;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.util.Log;
import androidx.lifecycle.a0;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteStatement;
import com.google.firebase.perf.FirebasePerformance;
import f5.l;
import f5.r;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.text.y;
import rm.n0;
import sm.c0;
import sm.q0;
import sm.w0;
import sm.x0;

/* loaded from: classes.dex */
public class d {

    /* renamed from: q, reason: collision with root package name */
    public static final a f5523q = new a(null);

    /* renamed from: r, reason: collision with root package name */
    private static final String[] f5524r = {"UPDATE", FirebasePerformance.HttpMethod.DELETE, "INSERT"};

    /* renamed from: a, reason: collision with root package name */
    private final r f5525a;

    /* renamed from: b, reason: collision with root package name */
    private final Map f5526b;

    /* renamed from: c, reason: collision with root package name */
    private final Map f5527c;

    /* renamed from: d, reason: collision with root package name */
    private final Map f5528d;

    /* renamed from: e, reason: collision with root package name */
    private final String[] f5529e;

    /* renamed from: f, reason: collision with root package name */
    private f5.c f5530f;

    /* renamed from: g, reason: collision with root package name */
    private final AtomicBoolean f5531g;

    /* renamed from: h, reason: collision with root package name */
    private volatile boolean f5532h;

    /* renamed from: i, reason: collision with root package name */
    private volatile SupportSQLiteStatement f5533i;

    /* renamed from: j, reason: collision with root package name */
    private final b f5534j;

    /* renamed from: k, reason: collision with root package name */
    private final l f5535k;

    /* renamed from: l, reason: collision with root package name */
    private final q.b f5536l;

    /* renamed from: m, reason: collision with root package name */
    private androidx.room.e f5537m;

    /* renamed from: n, reason: collision with root package name */
    private final Object f5538n;

    /* renamed from: o, reason: collision with root package name */
    private final Object f5539o;

    /* renamed from: p, reason: collision with root package name */
    public final Runnable f5540p;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }

        public final void a(SupportSQLiteDatabase database) {
            t.g(database, "database");
            if (database.isWriteAheadLoggingEnabled()) {
                database.beginTransactionNonExclusive();
            } else {
                database.beginTransaction();
            }
        }

        public final String b(String tableName, String triggerType) {
            t.g(tableName, "tableName");
            t.g(triggerType, "triggerType");
            return "`room_table_modification_trigger_" + tableName + '_' + triggerType + '`';
        }
    }

    /* loaded from: classes.dex */
    public static final class b {

        /* renamed from: e, reason: collision with root package name */
        public static final a f5541e = new a(null);

        /* renamed from: a, reason: collision with root package name */
        private final long[] f5542a;

        /* renamed from: b, reason: collision with root package name */
        private final boolean[] f5543b;

        /* renamed from: c, reason: collision with root package name */
        private final int[] f5544c;

        /* renamed from: d, reason: collision with root package name */
        private boolean f5545d;

        /* loaded from: classes.dex */
        public static final class a {
            private a() {
            }

            public /* synthetic */ a(k kVar) {
                this();
            }
        }

        public b(int i10) {
            this.f5542a = new long[i10];
            this.f5543b = new boolean[i10];
            this.f5544c = new int[i10];
        }

        public final int[] a() {
            synchronized (this) {
                if (!this.f5545d) {
                    return null;
                }
                long[] jArr = this.f5542a;
                int length = jArr.length;
                int i10 = 0;
                int i11 = 0;
                while (i10 < length) {
                    int i12 = i11 + 1;
                    int i13 = 1;
                    boolean z10 = jArr[i10] > 0;
                    boolean[] zArr = this.f5543b;
                    if (z10 != zArr[i11]) {
                        int[] iArr = this.f5544c;
                        if (!z10) {
                            i13 = 2;
                        }
                        iArr[i11] = i13;
                    } else {
                        this.f5544c[i11] = 0;
                    }
                    zArr[i11] = z10;
                    i10++;
                    i11 = i12;
                }
                this.f5545d = false;
                return (int[]) this.f5544c.clone();
            }
        }

        public final boolean b(int... tableIds) {
            boolean z10;
            t.g(tableIds, "tableIds");
            synchronized (this) {
                z10 = false;
                for (int i10 : tableIds) {
                    long[] jArr = this.f5542a;
                    long j10 = jArr[i10];
                    jArr[i10] = 1 + j10;
                    if (j10 == 0) {
                        z10 = true;
                        this.f5545d = true;
                    }
                }
                n0 n0Var = n0.f34904a;
            }
            return z10;
        }

        public final boolean c(int... tableIds) {
            boolean z10;
            t.g(tableIds, "tableIds");
            synchronized (this) {
                z10 = false;
                for (int i10 : tableIds) {
                    long[] jArr = this.f5542a;
                    long j10 = jArr[i10];
                    jArr[i10] = j10 - 1;
                    if (j10 == 1) {
                        z10 = true;
                        this.f5545d = true;
                    }
                }
                n0 n0Var = n0.f34904a;
            }
            return z10;
        }

        public final void d() {
            synchronized (this) {
                Arrays.fill(this.f5543b, false);
                this.f5545d = true;
                n0 n0Var = n0.f34904a;
            }
        }
    }

    /* loaded from: classes.dex */
    public static abstract class c {

        /* renamed from: a, reason: collision with root package name */
        private final String[] f5546a;

        public c(String[] tables) {
            t.g(tables, "tables");
            this.f5546a = tables;
        }

        public final String[] a() {
            return this.f5546a;
        }

        public boolean b() {
            return false;
        }

        public abstract void c(Set set);
    }

    /* renamed from: androidx.room.d$d, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0140d {

        /* renamed from: a, reason: collision with root package name */
        private final c f5547a;

        /* renamed from: b, reason: collision with root package name */
        private final int[] f5548b;

        /* renamed from: c, reason: collision with root package name */
        private final String[] f5549c;

        /* renamed from: d, reason: collision with root package name */
        private final Set f5550d;

        public C0140d(c observer, int[] tableIds, String[] tableNames) {
            t.g(observer, "observer");
            t.g(tableIds, "tableIds");
            t.g(tableNames, "tableNames");
            this.f5547a = observer;
            this.f5548b = tableIds;
            this.f5549c = tableNames;
            this.f5550d = (tableNames.length == 0) ^ true ? w0.c(tableNames[0]) : x0.d();
            if (!(tableIds.length == tableNames.length)) {
                throw new IllegalStateException("Check failed.".toString());
            }
        }

        public final int[] a() {
            return this.f5548b;
        }

        public final void b(Set invalidatedTablesIds) {
            Set d10;
            Set b10;
            t.g(invalidatedTablesIds, "invalidatedTablesIds");
            int[] iArr = this.f5548b;
            int length = iArr.length;
            if (length != 0) {
                int i10 = 0;
                if (length != 1) {
                    b10 = w0.b();
                    int[] iArr2 = this.f5548b;
                    int length2 = iArr2.length;
                    int i11 = 0;
                    while (i10 < length2) {
                        int i12 = i11 + 1;
                        if (invalidatedTablesIds.contains(Integer.valueOf(iArr2[i10]))) {
                            b10.add(this.f5549c[i11]);
                        }
                        i10++;
                        i11 = i12;
                    }
                    d10 = w0.a(b10);
                } else {
                    d10 = invalidatedTablesIds.contains(Integer.valueOf(iArr[0])) ? this.f5550d : x0.d();
                }
            } else {
                d10 = x0.d();
            }
            if (!d10.isEmpty()) {
                this.f5547a.c(d10);
            }
        }

        public final void c(String[] tables) {
            Set d10;
            boolean z10;
            Set b10;
            boolean z11;
            t.g(tables, "tables");
            int length = this.f5549c.length;
            if (length != 0) {
                boolean z12 = false;
                if (length != 1) {
                    b10 = w0.b();
                    for (String str : tables) {
                        for (String str2 : this.f5549c) {
                            z11 = y.z(str2, str, true);
                            if (z11) {
                                b10.add(str2);
                            }
                        }
                    }
                    d10 = w0.a(b10);
                } else {
                    int length2 = tables.length;
                    int i10 = 0;
                    while (true) {
                        if (i10 >= length2) {
                            break;
                        }
                        z10 = y.z(tables[i10], this.f5549c[0], true);
                        if (z10) {
                            z12 = true;
                            break;
                        }
                        i10++;
                    }
                    d10 = z12 ? this.f5550d : x0.d();
                }
            } else {
                d10 = x0.d();
            }
            if (!d10.isEmpty()) {
                this.f5547a.c(d10);
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class e extends c {

        /* renamed from: b, reason: collision with root package name */
        private final d f5551b;

        /* renamed from: c, reason: collision with root package name */
        private final WeakReference f5552c;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public e(d tracker, c delegate) {
            super(delegate.a());
            t.g(tracker, "tracker");
            t.g(delegate, "delegate");
            this.f5551b = tracker;
            this.f5552c = new WeakReference(delegate);
        }

        @Override // androidx.room.d.c
        public void c(Set tables) {
            t.g(tables, "tables");
            c cVar = (c) this.f5552c.get();
            if (cVar == null) {
                this.f5551b.p(this);
            } else {
                cVar.c(tables);
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class f implements Runnable {
        f() {
        }

        private final Set a() {
            Set b10;
            Set a10;
            d dVar = d.this;
            b10 = w0.b();
            Cursor A = r.A(dVar.h(), new o5.a("SELECT * FROM room_table_modification_log WHERE invalidated = 1;"), null, 2, null);
            while (A.moveToNext()) {
                try {
                    b10.add(Integer.valueOf(A.getInt(0)));
                } finally {
                }
            }
            n0 n0Var = n0.f34904a;
            bn.c.a(A, null);
            a10 = w0.a(b10);
            if (!a10.isEmpty()) {
                if (d.this.g() == null) {
                    throw new IllegalStateException("Required value was null.".toString());
                }
                SupportSQLiteStatement g10 = d.this.g();
                if (g10 == null) {
                    throw new IllegalArgumentException("Required value was null.".toString());
                }
                g10.executeUpdateDelete();
            }
            return a10;
        }

        /* JADX WARN: Code restructure failed: missing block: B:30:0x0080, code lost:
        
            if (r0 != null) goto L26;
         */
        /* JADX WARN: Code restructure failed: missing block: B:31:0x0082, code lost:
        
            r0.e();
         */
        /* JADX WARN: Code restructure failed: missing block: B:33:0x00c5, code lost:
        
            if ((!r3.isEmpty()) == false) goto L56;
         */
        /* JADX WARN: Code restructure failed: missing block: B:34:0x00c7, code lost:
        
            r0 = r5.f5553p.i();
            r5 = r5.f5553p;
         */
        /* JADX WARN: Code restructure failed: missing block: B:35:0x00cf, code lost:
        
            monitor-enter(r0);
         */
        /* JADX WARN: Code restructure failed: missing block: B:37:0x00d0, code lost:
        
            r5 = r5.i().iterator();
         */
        /* JADX WARN: Code restructure failed: missing block: B:39:0x00dc, code lost:
        
            if (r5.hasNext() == false) goto L66;
         */
        /* JADX WARN: Code restructure failed: missing block: B:40:0x00de, code lost:
        
            ((androidx.room.d.C0140d) ((java.util.Map.Entry) r5.next()).getValue()).b(r3);
         */
        /* JADX WARN: Code restructure failed: missing block: B:42:0x00ee, code lost:
        
            r5 = rm.n0.f34904a;
         */
        /* JADX WARN: Code restructure failed: missing block: B:43:0x00f0, code lost:
        
            monitor-exit(r0);
         */
        /* JADX WARN: Code restructure failed: missing block: B:44:?, code lost:
        
            return;
         */
        /* JADX WARN: Code restructure failed: missing block: B:48:0x00f5, code lost:
        
            return;
         */
        /* JADX WARN: Code restructure failed: missing block: B:61:0x00a2, code lost:
        
            if (r0 == null) goto L42;
         */
        /* JADX WARN: Code restructure failed: missing block: B:65:0x00ba, code lost:
        
            if (r0 == null) goto L42;
         */
        @Override // java.lang.Runnable
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public void run() {
            Set d10;
            f5.c cVar;
            f5.c cVar2;
            Lock l10 = d.this.h().l();
            l10.lock();
            try {
                try {
                    if (!d.this.f()) {
                        if (cVar2 != null) {
                            return;
                        } else {
                            return;
                        }
                    }
                    if (!d.this.j().compareAndSet(true, false)) {
                        l10.unlock();
                        f5.c cVar3 = d.this.f5530f;
                        if (cVar3 != null) {
                            cVar3.e();
                            return;
                        }
                        return;
                    }
                    if (d.this.h().s()) {
                        l10.unlock();
                        f5.c cVar4 = d.this.f5530f;
                        if (cVar4 != null) {
                            cVar4.e();
                            return;
                        }
                        return;
                    }
                    SupportSQLiteDatabase writableDatabase = d.this.h().n().getWritableDatabase();
                    writableDatabase.beginTransactionNonExclusive();
                    try {
                        d10 = a();
                        writableDatabase.setTransactionSuccessful();
                        l10.unlock();
                        cVar = d.this.f5530f;
                    } finally {
                        writableDatabase.endTransaction();
                    }
                } catch (SQLiteException e10) {
                    Log.e("ROOM", "Cannot run invalidation tracker. Is the db closed?", e10);
                    d10 = x0.d();
                    l10.unlock();
                    cVar = d.this.f5530f;
                } catch (IllegalStateException e11) {
                    Log.e("ROOM", "Cannot run invalidation tracker. Is the db closed?", e11);
                    d10 = x0.d();
                    l10.unlock();
                    cVar = d.this.f5530f;
                }
            } finally {
                l10.unlock();
                cVar2 = d.this.f5530f;
                if (cVar2 != null) {
                    cVar2.e();
                }
            }
        }
    }

    public d(r database, Map shadowTablesMap, Map viewTables, String... tableNames) {
        Object j10;
        String str;
        t.g(database, "database");
        t.g(shadowTablesMap, "shadowTablesMap");
        t.g(viewTables, "viewTables");
        t.g(tableNames, "tableNames");
        this.f5525a = database;
        this.f5526b = shadowTablesMap;
        this.f5527c = viewTables;
        this.f5531g = new AtomicBoolean(false);
        this.f5534j = new b(tableNames.length);
        this.f5535k = new l(database);
        this.f5536l = new q.b();
        this.f5538n = new Object();
        this.f5539o = new Object();
        this.f5528d = new LinkedHashMap();
        int length = tableNames.length;
        String[] strArr = new String[length];
        for (int i10 = 0; i10 < length; i10++) {
            String str2 = tableNames[i10];
            Locale US = Locale.US;
            t.f(US, "US");
            String lowerCase = str2.toLowerCase(US);
            t.f(lowerCase, "this as java.lang.String).toLowerCase(locale)");
            this.f5528d.put(lowerCase, Integer.valueOf(i10));
            String str3 = (String) this.f5526b.get(tableNames[i10]);
            if (str3 != null) {
                t.f(US, "US");
                str = str3.toLowerCase(US);
                t.f(str, "this as java.lang.String).toLowerCase(locale)");
            } else {
                str = null;
            }
            if (str != null) {
                lowerCase = str;
            }
            strArr[i10] = lowerCase;
        }
        this.f5529e = strArr;
        for (Map.Entry entry : this.f5526b.entrySet()) {
            String str4 = (String) entry.getValue();
            Locale US2 = Locale.US;
            t.f(US2, "US");
            String lowerCase2 = str4.toLowerCase(US2);
            t.f(lowerCase2, "this as java.lang.String).toLowerCase(locale)");
            if (this.f5528d.containsKey(lowerCase2)) {
                String str5 = (String) entry.getKey();
                t.f(US2, "US");
                String lowerCase3 = str5.toLowerCase(US2);
                t.f(lowerCase3, "this as java.lang.String).toLowerCase(locale)");
                Map map = this.f5528d;
                j10 = q0.j(map, lowerCase2);
                map.put(lowerCase3, j10);
            }
        }
        this.f5540p = new f();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void n() {
        synchronized (this.f5539o) {
            this.f5532h = false;
            this.f5534j.d();
            SupportSQLiteStatement supportSQLiteStatement = this.f5533i;
            if (supportSQLiteStatement != null) {
                supportSQLiteStatement.close();
                n0 n0Var = n0.f34904a;
            }
        }
    }

    private final String[] q(String[] strArr) {
        Set b10;
        Set a10;
        b10 = w0.b();
        for (String str : strArr) {
            Map map = this.f5527c;
            Locale US = Locale.US;
            t.f(US, "US");
            String lowerCase = str.toLowerCase(US);
            t.f(lowerCase, "this as java.lang.String).toLowerCase(locale)");
            if (map.containsKey(lowerCase)) {
                Map map2 = this.f5527c;
                t.f(US, "US");
                String lowerCase2 = str.toLowerCase(US);
                t.f(lowerCase2, "this as java.lang.String).toLowerCase(locale)");
                Object obj = map2.get(lowerCase2);
                t.d(obj);
                b10.addAll((Collection) obj);
            } else {
                b10.add(str);
            }
        }
        a10 = w0.a(b10);
        return (String[]) a10.toArray(new String[0]);
    }

    private final void t(SupportSQLiteDatabase supportSQLiteDatabase, int i10) {
        supportSQLiteDatabase.execSQL("INSERT OR IGNORE INTO room_table_modification_log VALUES(" + i10 + ", 0)");
        String str = this.f5529e[i10];
        for (String str2 : f5524r) {
            String str3 = "CREATE TEMP TRIGGER IF NOT EXISTS " + f5523q.b(str, str2) + " AFTER " + str2 + " ON `" + str + "` BEGIN UPDATE room_table_modification_log SET invalidated = 1 WHERE table_id = " + i10 + " AND invalidated = 0; END";
            t.f(str3, "StringBuilder().apply(builderAction).toString()");
            supportSQLiteDatabase.execSQL(str3);
        }
    }

    private final void u(SupportSQLiteDatabase supportSQLiteDatabase, int i10) {
        String str = this.f5529e[i10];
        for (String str2 : f5524r) {
            String str3 = "DROP TRIGGER IF EXISTS " + f5523q.b(str, str2);
            t.f(str3, "StringBuilder().apply(builderAction).toString()");
            supportSQLiteDatabase.execSQL(str3);
        }
    }

    private final String[] x(String[] strArr) {
        String[] q10 = q(strArr);
        for (String str : q10) {
            Map map = this.f5528d;
            Locale US = Locale.US;
            t.f(US, "US");
            String lowerCase = str.toLowerCase(US);
            t.f(lowerCase, "this as java.lang.String).toLowerCase(locale)");
            if (!map.containsKey(lowerCase)) {
                throw new IllegalArgumentException(("There is no table with name " + str).toString());
            }
        }
        return q10;
    }

    public void c(c observer) {
        int[] R0;
        C0140d c0140d;
        t.g(observer, "observer");
        String[] q10 = q(observer.a());
        ArrayList arrayList = new ArrayList(q10.length);
        for (String str : q10) {
            Map map = this.f5528d;
            Locale US = Locale.US;
            t.f(US, "US");
            String lowerCase = str.toLowerCase(US);
            t.f(lowerCase, "this as java.lang.String).toLowerCase(locale)");
            Integer num = (Integer) map.get(lowerCase);
            if (num == null) {
                throw new IllegalArgumentException("There is no table with name " + str);
            }
            arrayList.add(Integer.valueOf(num.intValue()));
        }
        R0 = c0.R0(arrayList);
        C0140d c0140d2 = new C0140d(observer, R0, q10);
        synchronized (this.f5536l) {
            c0140d = (C0140d) this.f5536l.m(observer, c0140d2);
        }
        if (c0140d == null && this.f5534j.b(Arrays.copyOf(R0, R0.length))) {
            v();
        }
    }

    public void d(c observer) {
        t.g(observer, "observer");
        c(new e(this, observer));
    }

    public a0 e(String[] tableNames, boolean z10, Callable computeFunction) {
        t.g(tableNames, "tableNames");
        t.g(computeFunction, "computeFunction");
        return this.f5535k.a(x(tableNames), z10, computeFunction);
    }

    public final boolean f() {
        if (!this.f5525a.y()) {
            return false;
        }
        if (!this.f5532h) {
            this.f5525a.n().getWritableDatabase();
        }
        if (this.f5532h) {
            return true;
        }
        Log.e("ROOM", "database is not initialized even though it is open");
        return false;
    }

    public final SupportSQLiteStatement g() {
        return this.f5533i;
    }

    public final r h() {
        return this.f5525a;
    }

    public final q.b i() {
        return this.f5536l;
    }

    public final AtomicBoolean j() {
        return this.f5531g;
    }

    public final Map k() {
        return this.f5528d;
    }

    public final void l(SupportSQLiteDatabase database) {
        t.g(database, "database");
        synchronized (this.f5539o) {
            if (this.f5532h) {
                Log.e("ROOM", "Invalidation tracker is initialized twice :/.");
                return;
            }
            database.execSQL("PRAGMA temp_store = MEMORY;");
            database.execSQL("PRAGMA recursive_triggers='ON';");
            database.execSQL("CREATE TEMP TABLE room_table_modification_log (table_id INTEGER PRIMARY KEY, invalidated INTEGER NOT NULL DEFAULT 0)");
            w(database);
            this.f5533i = database.compileStatement("UPDATE room_table_modification_log SET invalidated = 0 WHERE invalidated = 1");
            this.f5532h = true;
            n0 n0Var = n0.f34904a;
        }
    }

    public final void m(String... tables) {
        t.g(tables, "tables");
        synchronized (this.f5536l) {
            for (Map.Entry entry : this.f5536l) {
                t.f(entry, "(observer, wrapper)");
                c cVar = (c) entry.getKey();
                C0140d c0140d = (C0140d) entry.getValue();
                if (!cVar.b()) {
                    c0140d.c(tables);
                }
            }
            n0 n0Var = n0.f34904a;
        }
    }

    public void o() {
        if (this.f5531g.compareAndSet(false, true)) {
            f5.c cVar = this.f5530f;
            if (cVar != null) {
                cVar.j();
            }
            this.f5525a.o().execute(this.f5540p);
        }
    }

    public void p(c observer) {
        C0140d c0140d;
        t.g(observer, "observer");
        synchronized (this.f5536l) {
            c0140d = (C0140d) this.f5536l.n(observer);
        }
        if (c0140d != null) {
            b bVar = this.f5534j;
            int[] a10 = c0140d.a();
            if (bVar.c(Arrays.copyOf(a10, a10.length))) {
                v();
            }
        }
    }

    public final void r(f5.c autoCloser) {
        t.g(autoCloser, "autoCloser");
        this.f5530f = autoCloser;
        autoCloser.l(new Runnable() { // from class: f5.m
            @Override // java.lang.Runnable
            public final void run() {
                androidx.room.d.this.n();
            }
        });
    }

    public final void s(Context context, String name, Intent serviceIntent) {
        t.g(context, "context");
        t.g(name, "name");
        t.g(serviceIntent, "serviceIntent");
        this.f5537m = new androidx.room.e(context, name, serviceIntent, this, this.f5525a.o());
    }

    public final void v() {
        if (this.f5525a.y()) {
            w(this.f5525a.n().getWritableDatabase());
        }
    }

    public final void w(SupportSQLiteDatabase database) {
        t.g(database, "database");
        if (database.inTransaction()) {
            return;
        }
        try {
            Lock l10 = this.f5525a.l();
            l10.lock();
            try {
                synchronized (this.f5538n) {
                    int[] a10 = this.f5534j.a();
                    if (a10 == null) {
                        return;
                    }
                    f5523q.a(database);
                    try {
                        int length = a10.length;
                        int i10 = 0;
                        int i11 = 0;
                        while (i10 < length) {
                            int i12 = a10[i10];
                            int i13 = i11 + 1;
                            if (i12 == 1) {
                                t(database, i11);
                            } else if (i12 == 2) {
                                u(database, i11);
                            }
                            i10++;
                            i11 = i13;
                        }
                        database.setTransactionSuccessful();
                        database.endTransaction();
                        n0 n0Var = n0.f34904a;
                    } catch (Throwable th2) {
                        database.endTransaction();
                        throw th2;
                    }
                }
            } finally {
                l10.unlock();
            }
        } catch (SQLiteException e10) {
            Log.e("ROOM", "Cannot run invalidation tracker. Is the db closed?", e10);
        } catch (IllegalStateException e11) {
            Log.e("ROOM", "Cannot run invalidation tracker. Is the db closed?", e11);
        }
    }
}
