package h5;

import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.os.CancellationSignal;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteQuery;
import f5.r;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.List;
import kotlin.jvm.internal.t;
import kotlin.text.y;
import rm.n0;

/* loaded from: classes.dex */
public abstract class b {
    public static final void a(SupportSQLiteDatabase db2) {
        List c10;
        List<String> a10;
        boolean P;
        t.g(db2, "db");
        c10 = sm.t.c();
        Cursor query = db2.query("SELECT name FROM sqlite_master WHERE type = 'trigger'");
        while (query.moveToNext()) {
            try {
                c10.add(query.getString(0));
            } finally {
            }
        }
        n0 n0Var = n0.f34904a;
        bn.c.a(query, null);
        a10 = sm.t.a(c10);
        for (String triggerName : a10) {
            t.f(triggerName, "triggerName");
            P = y.P(triggerName, "room_fts_content_sync_", false, 2, null);
            if (P) {
                db2.execSQL("DROP TRIGGER IF EXISTS " + triggerName);
            }
        }
    }

    public static final Cursor b(r db2, SupportSQLiteQuery sqLiteQuery, boolean z10, CancellationSignal cancellationSignal) {
        t.g(db2, "db");
        t.g(sqLiteQuery, "sqLiteQuery");
        Cursor z11 = db2.z(sqLiteQuery, cancellationSignal);
        if (!z10 || !(z11 instanceof AbstractWindowedCursor)) {
            return z11;
        }
        AbstractWindowedCursor abstractWindowedCursor = (AbstractWindowedCursor) z11;
        int count = abstractWindowedCursor.getCount();
        return (abstractWindowedCursor.hasWindow() ? abstractWindowedCursor.getWindow().getNumRows() : count) < count ? a.a(z11) : z11;
    }

    public static final int c(File databaseFile) {
        t.g(databaseFile, "databaseFile");
        FileChannel channel = new FileInputStream(databaseFile).getChannel();
        try {
            ByteBuffer allocate = ByteBuffer.allocate(4);
            channel.tryLock(60L, 4L, true);
            channel.position(60L);
            if (channel.read(allocate) != 4) {
                throw new IOException("Bad database header, unable to read 4 bytes at offset 60");
            }
            allocate.rewind();
            int i10 = allocate.getInt();
            bn.c.a(channel, null);
            return i10;
        } catch (Throwable th2) {
            try {
                throw th2;
            } catch (Throwable th3) {
                bn.c.a(channel, th2);
                throw th3;
            }
        }
    }
}
