Ensure SQLCipher libraries are loaded.

This commit is contained in:
Greyson Parrelli
2021-07-16 13:37:03 -04:00
parent 4a0e6a3eb2
commit 71613d9db1
3 changed files with 32 additions and 1 deletions

View File

@@ -227,6 +227,8 @@ public class DatabaseFactory {
}
private DatabaseFactory(@NonNull Context context) {
SqlCipherLibraryLoader.load(context);
DatabaseSecret databaseSecret = DatabaseSecretProvider.getOrCreateDatabaseSecret(context);
AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();

View File

@@ -0,0 +1,28 @@
package org.thoughtcrime.securesms.database
import android.content.Context
import net.sqlcipher.database.SQLiteDatabase
/**
* A simple wrapper to load SQLCipher libs exactly once. The exact entry point of database access is non-deterministic because content providers run before
* Application#onCreate().
*/
class SqlCipherLibraryLoader {
companion object {
private var loaded = false
private val LOCK = Object()
@JvmStatic
fun load(context: Context) {
if (!loaded) {
synchronized(LOCK) {
if (!loaded) {
SQLiteDatabase.loadLibs(context)
loaded = true
}
}
}
}
}
}