package p037.p109.p111;

import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.os.Build;
import android.os.CancellationSignal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import p037.p109.AbstractC2401;
import p037.p115.p116.InterfaceC2442;
import p037.p115.p116.InterfaceC2448;
import p037.p115.p116.p117.C2449;
import p138.p139.p143.p144.C2803;

/* JADX INFO: renamed from: މ.ސ.ޏ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2421 {
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static int m4503(File file) {
        FileChannel fileChannel = null;
        try {
            ByteBuffer byteBufferAllocate = ByteBuffer.allocate(4);
            FileChannel channel = new FileInputStream(file).getChannel();
            channel.tryLock(60L, 4L, true);
            channel.position(60L);
            if (channel.read(byteBufferAllocate) != 4) {
                throw new IOException("Bad database header, unable to read 4 bytes at offset 60");
            }
            byteBufferAllocate.rewind();
            int i = byteBufferAllocate.getInt();
            channel.close();
            return i;
        } catch (Throwable th) {
            if (0 != 0) {
                fileChannel.close();
            }
            throw th;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Cursor m4504(AbstractC2401 abstractC2401, InterfaceC2448 interfaceC2448, boolean z, CancellationSignal cancellationSignal) {
        Cursor cursorM4474 = abstractC2401.m4474(interfaceC2448, cancellationSignal);
        if (z && (cursorM4474 instanceof AbstractWindowedCursor)) {
            AbstractWindowedCursor abstractWindowedCursor = (AbstractWindowedCursor) cursorM4474;
            int count = abstractWindowedCursor.getCount();
            int numRows = abstractWindowedCursor.hasWindow() ? abstractWindowedCursor.getWindow().getNumRows() : count;
            if (Build.VERSION.SDK_INT < 23 || numRows < count) {
                try {
                    MatrixCursor matrixCursor = new MatrixCursor(abstractWindowedCursor.getColumnNames(), abstractWindowedCursor.getCount());
                    while (abstractWindowedCursor.moveToNext()) {
                        Object[] objArr = new Object[abstractWindowedCursor.getColumnCount()];
                        for (int i = 0; i < abstractWindowedCursor.getColumnCount(); i++) {
                            int type = abstractWindowedCursor.getType(i);
                            if (type == 0) {
                                objArr[i] = null;
                            } else if (type == 1) {
                                objArr[i] = Long.valueOf(abstractWindowedCursor.getLong(i));
                            } else if (type == 2) {
                                objArr[i] = Double.valueOf(abstractWindowedCursor.getDouble(i));
                            } else if (type == 3) {
                                objArr[i] = abstractWindowedCursor.getString(i);
                            } else {
                                if (type != 4) {
                                    throw new IllegalStateException();
                                }
                                objArr[i] = abstractWindowedCursor.getBlob(i);
                            }
                        }
                        matrixCursor.addRow(objArr);
                    }
                    return matrixCursor;
                } finally {
                    abstractWindowedCursor.close();
                }
            }
        }
        return cursorM4474;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static void m4505(InterfaceC2442 interfaceC2442) {
        ArrayList<String> arrayList = new ArrayList();
        C2449 c2449 = (C2449) interfaceC2442;
        Cursor cursorM4527 = c2449.m4527("SELECT name FROM sqlite_master WHERE type = 'trigger'");
        while (cursorM4527.moveToNext()) {
            try {
                arrayList.add(cursorM4527.getString(0));
            } catch (Throwable th) {
                cursorM4527.close();
                throw th;
            }
        }
        cursorM4527.close();
        for (String str : arrayList) {
            if (str.startsWith("room_fts_content_sync_")) {
                c2449.f7741.execSQL(C2803.m4879("DROP TRIGGER IF EXISTS ", str));
            }
        }
    }
}
