- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
237 lines
8.6 KiB
Java
237 lines
8.6 KiB
Java
package androidx.sqlite.db;
|
|
|
|
import android.content.Context;
|
|
import android.database.sqlite.SQLiteException;
|
|
import android.util.Log;
|
|
import android.util.Pair;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.sqlite.db.SupportSQLiteCompat;
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.jvm.internal.SourceDebugExtension;
|
|
import kotlin.text.StringsKt__StringsJVMKt;
|
|
|
|
/* loaded from: classes.dex */
|
|
public interface SupportSQLiteOpenHelper extends Closeable {
|
|
|
|
public interface Factory {
|
|
SupportSQLiteOpenHelper create(Configuration configuration);
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
void close();
|
|
|
|
String getDatabaseName();
|
|
|
|
SupportSQLiteDatabase getReadableDatabase();
|
|
|
|
SupportSQLiteDatabase getWritableDatabase();
|
|
|
|
@RequiresApi(api = 16)
|
|
void setWriteAheadLoggingEnabled(boolean z);
|
|
|
|
@SourceDebugExtension({"SMAP\nSupportSQLiteOpenHelper.kt\nKotlin\n*S Kotlin\n*F\n+ 1 SupportSQLiteOpenHelper.kt\nandroidx/sqlite/db/SupportSQLiteOpenHelper$Callback\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n+ 4 Strings.kt\nkotlin/text/StringsKt__StringsKt\n*L\n1#1,426:1\n1#2:427\n1855#3,2:428\n107#4:430\n79#4,22:431\n*S KotlinDebug\n*F\n+ 1 SupportSQLiteOpenHelper.kt\nandroidx/sqlite/db/SupportSQLiteOpenHelper$Callback\n*L\n243#1:428,2\n251#1:430\n251#1:431,22\n*E\n"})
|
|
public static abstract class Callback {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String TAG = "SupportSQLite";
|
|
public final int version;
|
|
|
|
public void onConfigure(SupportSQLiteDatabase db) {
|
|
Intrinsics.checkNotNullParameter(db, "db");
|
|
}
|
|
|
|
public abstract void onCreate(SupportSQLiteDatabase supportSQLiteDatabase);
|
|
|
|
public void onOpen(SupportSQLiteDatabase db) {
|
|
Intrinsics.checkNotNullParameter(db, "db");
|
|
}
|
|
|
|
public abstract void onUpgrade(SupportSQLiteDatabase supportSQLiteDatabase, int i, int i2);
|
|
|
|
public Callback(int i) {
|
|
this.version = i;
|
|
}
|
|
|
|
public void onDowngrade(SupportSQLiteDatabase db, int i, int i2) {
|
|
Intrinsics.checkNotNullParameter(db, "db");
|
|
throw new SQLiteException("Can't downgrade database from version " + i + " to " + i2);
|
|
}
|
|
|
|
public void onCorruption(SupportSQLiteDatabase db) {
|
|
Intrinsics.checkNotNullParameter(db, "db");
|
|
Log.e(TAG, "Corruption reported by sqlite on database: " + db + ".path");
|
|
if (!db.isOpen()) {
|
|
String path = db.getPath();
|
|
if (path != null) {
|
|
deleteDatabaseFile(path);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
List<Pair<String, String>> list = null;
|
|
try {
|
|
try {
|
|
list = db.getAttachedDbs();
|
|
} catch (SQLiteException unused) {
|
|
}
|
|
try {
|
|
db.close();
|
|
} catch (IOException unused2) {
|
|
}
|
|
if (list != null) {
|
|
return;
|
|
}
|
|
} finally {
|
|
if (list == null) {
|
|
String path2 = db.getPath();
|
|
if (path2 != null) {
|
|
deleteDatabaseFile(path2);
|
|
}
|
|
} else {
|
|
Iterator<T> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
Object obj = ((Pair) it.next()).second;
|
|
Intrinsics.checkNotNullExpressionValue(obj, "p.second");
|
|
deleteDatabaseFile((String) obj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private final void deleteDatabaseFile(String str) {
|
|
boolean equals;
|
|
equals = StringsKt__StringsJVMKt.equals(str, ":memory:", true);
|
|
if (equals) {
|
|
return;
|
|
}
|
|
int length = str.length() - 1;
|
|
int i = 0;
|
|
boolean z = false;
|
|
while (i <= length) {
|
|
boolean z2 = Intrinsics.compare((int) str.charAt(!z ? i : length), 32) <= 0;
|
|
if (z) {
|
|
if (!z2) {
|
|
break;
|
|
} else {
|
|
length--;
|
|
}
|
|
} else if (z2) {
|
|
i++;
|
|
} else {
|
|
z = true;
|
|
}
|
|
}
|
|
if (str.subSequence(i, length + 1).toString().length() == 0) {
|
|
return;
|
|
}
|
|
Log.w(TAG, "deleting the database file: " + str);
|
|
try {
|
|
SupportSQLiteCompat.Api16Impl.deleteDatabase(new File(str));
|
|
} catch (Exception e) {
|
|
Log.w(TAG, "delete failed: ", e);
|
|
}
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
}
|
|
}
|
|
|
|
public static final class Configuration {
|
|
public static final Companion Companion = new Companion(null);
|
|
public final boolean allowDataLossOnRecovery;
|
|
public final Callback callback;
|
|
public final Context context;
|
|
public final String name;
|
|
public final boolean useNoBackupDirectory;
|
|
|
|
public static final Builder builder(Context context) {
|
|
return Companion.builder(context);
|
|
}
|
|
|
|
public Configuration(Context context, String str, Callback callback, boolean z, boolean z2) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Intrinsics.checkNotNullParameter(callback, "callback");
|
|
this.context = context;
|
|
this.name = str;
|
|
this.callback = callback;
|
|
this.useNoBackupDirectory = z;
|
|
this.allowDataLossOnRecovery = z2;
|
|
}
|
|
|
|
public /* synthetic */ Configuration(Context context, String str, Callback callback, boolean z, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(context, str, callback, (i & 8) != 0 ? false : z, (i & 16) != 0 ? false : z2);
|
|
}
|
|
|
|
public static class Builder {
|
|
private boolean allowDataLossOnRecovery;
|
|
private Callback callback;
|
|
private final Context context;
|
|
private String name;
|
|
private boolean useNoBackupDirectory;
|
|
|
|
public Builder allowDataLossOnRecovery(boolean z) {
|
|
this.allowDataLossOnRecovery = z;
|
|
return this;
|
|
}
|
|
|
|
public Builder callback(Callback callback) {
|
|
Intrinsics.checkNotNullParameter(callback, "callback");
|
|
this.callback = callback;
|
|
return this;
|
|
}
|
|
|
|
public Builder name(String str) {
|
|
this.name = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder noBackupDirectory(boolean z) {
|
|
this.useNoBackupDirectory = z;
|
|
return this;
|
|
}
|
|
|
|
public Builder(Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
this.context = context;
|
|
}
|
|
|
|
public Configuration build() {
|
|
String str;
|
|
Callback callback = this.callback;
|
|
if (callback == null) {
|
|
throw new IllegalArgumentException("Must set a callback to create the configuration.".toString());
|
|
}
|
|
if (this.useNoBackupDirectory && ((str = this.name) == null || str.length() == 0)) {
|
|
throw new IllegalArgumentException("Must set a non-null database name to a configuration that uses the no backup directory.".toString());
|
|
}
|
|
return new Configuration(this.context, this.name, callback, this.useNoBackupDirectory, this.allowDataLossOnRecovery);
|
|
}
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
|
|
public final Builder builder(Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
return new Builder(context);
|
|
}
|
|
}
|
|
}
|
|
}
|