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

@@ -39,6 +39,7 @@ import org.signal.core.util.tracing.Tracer;
import org.signal.glide.SignalGlideCodecs;
import org.signal.ringrtc.CallManager;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.SqlCipherLibraryLoader;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencyProvider;
@@ -128,7 +129,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
Log.i(TAG, "onCreate()");
})
.addBlocking("crash-handling", this::initializeCrashHandling)
.addBlocking("sqlcipher-init", () -> SQLiteDatabase.loadLibs(this))
.addBlocking("sqlcipher-init", () -> SqlCipherLibraryLoader.load(this))
.addBlocking("rx-init", () -> {
RxJavaPlugins.setInitIoSchedulerHandler(schedulerSupplier -> Schedulers.from(SignalExecutors.BOUNDED_IO, true, false));
RxJavaPlugins.setInitComputationSchedulerHandler(schedulerSupplier -> Schedulers.from(SignalExecutors.BOUNDED, true, false));

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
}
}
}
}
}
}