Initialize database error handler with application instance.

This commit is contained in:
Greyson Parrelli 2025-01-06 10:23:58 -05:00
parent 870f20aa78
commit c3a49766bf
4 changed files with 6 additions and 6 deletions

View file

@ -74,7 +74,7 @@ public class KeyValueDatabase extends SQLiteOpenHelper implements SignalDatabase
}
private KeyValueDatabase(@NonNull Application application, @NonNull DatabaseSecret databaseSecret, @NonNull String name) {
super(application, name, databaseSecret.asString(), null, DATABASE_VERSION, 0, new SqlCipherErrorHandler(name), new SqlCipherDatabaseHook(), true);
super(application, name, databaseSecret.asString(), null, DATABASE_VERSION, 0, new SqlCipherErrorHandler(application, name), new SqlCipherDatabaseHook(), true);
this.application = application;
}

View file

@ -65,7 +65,7 @@ public class MegaphoneDatabase extends SQLiteOpenHelper implements SignalDatabas
}
public MegaphoneDatabase(@NonNull Application application, @NonNull DatabaseSecret databaseSecret) {
super(application, DATABASE_NAME, databaseSecret.asString(), null, DATABASE_VERSION, 0, new SqlCipherErrorHandler(DATABASE_NAME), new SqlCipherDatabaseHook(), true);
super(application, DATABASE_NAME, databaseSecret.asString(), null, DATABASE_VERSION, 0, new SqlCipherErrorHandler(application, DATABASE_NAME), new SqlCipherDatabaseHook(), true);
this.application = application;
}

View file

@ -31,7 +31,7 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
null,
SignalDatabaseMigrations.DATABASE_VERSION,
0,
SqlCipherErrorHandler(name),
SqlCipherErrorHandler(context, name),
SqlCipherDatabaseHook(),
true
),

View file

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.database
import android.app.Application
import android.content.Context
import net.zetetic.database.DatabaseErrorHandler
import net.zetetic.database.sqlcipher.SQLiteConnection
@ -9,7 +10,6 @@ import org.signal.core.util.CursorUtil
import org.signal.core.util.ExceptionUtil
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.crypto.DatabaseSecretProvider
import org.thoughtcrime.securesms.dependencies.AppDependencies
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicReference
* The default error handler wipes the file. This one instead prints some diagnostics and then crashes so the original corrupt file isn't lost.
*/
@Suppress("ClassName")
class SqlCipherErrorHandler(private val databaseName: String) : DatabaseErrorHandler {
class SqlCipherErrorHandler(private val application: Application, private val databaseName: String) : DatabaseErrorHandler {
companion object {
private val TAG = Log.tag(SqlCipherErrorHandler::class.java)
@ -32,7 +32,7 @@ class SqlCipherErrorHandler(private val databaseName: String) : DatabaseErrorHan
}
try {
val result: DiagnosticResults = runDiagnostics(AppDependencies.application, db)
val result: DiagnosticResults = runDiagnostics(application, db)
var lines: List<String> = result.logs.split("\n")
lines = listOf("Database '$databaseName' corrupted!", "[sqlite] $message", "Diagnostics results:") + lines