discord-jadx/app/src/main/java/androidx/room/util/DBUtil.java

91 lines
3.3 KiB
Java

package androidx.room.util;
import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.os.Build;
import android.os.CancellationSignal;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteQuery;
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 java.util.Iterator;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public class DBUtil {
private DBUtil() {
}
@Nullable
public static CancellationSignal createCancellationSignal() {
return new CancellationSignal();
}
/* JADX INFO: finally extract failed */
public static void dropFtsSyncTriggers(SupportSQLiteDatabase supportSQLiteDatabase) {
ArrayList arrayList = new ArrayList();
Cursor query = supportSQLiteDatabase.query("SELECT name FROM sqlite_master WHERE type = 'trigger'");
while (query.moveToNext()) {
try {
arrayList.add(query.getString(0));
} catch (Throwable th) {
query.close();
throw th;
}
}
query.close();
Iterator it = arrayList.iterator();
while (it.hasNext()) {
String str = (String) it.next();
if (str.startsWith("room_fts_content_sync_")) {
supportSQLiteDatabase.execSQL("DROP TRIGGER IF EXISTS " + str);
}
}
}
@NonNull
@Deprecated
public static Cursor query(RoomDatabase roomDatabase, SupportSQLiteQuery supportSQLiteQuery, boolean z2) {
return query(roomDatabase, supportSQLiteQuery, z2, null);
}
@NonNull
public static Cursor query(@NonNull RoomDatabase roomDatabase, @NonNull SupportSQLiteQuery supportSQLiteQuery, boolean z2, @Nullable CancellationSignal cancellationSignal) {
Cursor query = roomDatabase.query(supportSQLiteQuery, cancellationSignal);
if (!z2 || !(query instanceof AbstractWindowedCursor)) {
return query;
}
AbstractWindowedCursor abstractWindowedCursor = (AbstractWindowedCursor) query;
int count = abstractWindowedCursor.getCount();
return (Build.VERSION.SDK_INT < 23 || (abstractWindowedCursor.hasWindow() ? abstractWindowedCursor.getWindow().getNumRows() : count) < count) ? CursorUtil.copyAndClose(abstractWindowedCursor) : query;
}
public static int readVersion(@NonNull File file) throws IOException {
FileChannel fileChannel = null;
try {
ByteBuffer allocate = ByteBuffer.allocate(4);
FileChannel channel = new FileInputStream(file).getChannel();
channel.tryLock(60, 4, true);
channel.position(60L);
if (channel.read(allocate) == 4) {
allocate.rewind();
int i = allocate.getInt();
channel.close();
return i;
}
throw new IOException("Bad database header, unable to read 4 bytes at offset 60");
} catch (Throwable th) {
if (0 != 0) {
fileChannel.close();
}
throw th;
}
}
}