Use relinker in rare cases when ndk sql lib is not loaded

This commit is contained in:
Rafał Kobyłko 2023-05-06 13:49:50 +02:00
parent b80926f7f6
commit daa747b7f3
3 changed files with 11 additions and 1 deletions

View File

@ -112,6 +112,7 @@ securityCrypto = "androidx.security:security-crypto:1.1.0-alpha05"
secureStorage = "de.adorsys.android:securestoragelibrary:1.2.4"
roomRx = { module = "androidx.room:room-rxjava2", version.ref = "room" }
sqlCipher = "net.zetetic:android-database-sqlcipher:4.5.4"
reLinker = "com.getkeepsafe.relinker:relinker:1.4.5"
apacheCommonsCodec = "commons-codec:commons-codec:1.15"
[bundles]

View File

@ -25,5 +25,6 @@ dependencies {
implementation(project(":core:common"))
implementation(libs.bundles.room)
implementation(libs.reLinker)
kapt(libs.roomCompiler)
}

View File

@ -1,6 +1,7 @@
package com.twofasapp.persistence
import androidx.room.Room
import com.getkeepsafe.relinker.ReLinker
import com.twofasapp.common.environment.AppBuild
import com.twofasapp.di.KoinModule
import com.twofasapp.persistence.cipher.DatabaseKeyGenerator
@ -20,9 +21,10 @@ class PersistenceModule : KoinModule {
singleOf(::GetDatabaseMasterKey)
single<AppDatabase> {
val context = androidContext()
val builder = Room.databaseBuilder(
androidContext(),
context,
AppDatabase::class.java, "database-2fas"
).addMigrations(
MIGRATION_1_2,
@ -35,6 +37,12 @@ class PersistenceModule : KoinModule {
MIGRATION_10_11,
)
SQLiteDatabase.loadLibs(context) { libraries: Array<String?> ->
libraries.forEach { library ->
ReLinker.loadLibrary(context, library)
}
}
if (get<AppBuild>().isDebuggable.not()) {
val factory = SupportFactory(SQLiteDatabase.getBytes(get<GetDatabaseMasterKey>().execute().toCharArray()))
builder.openHelperFactory(factory)