refactor: Migrate SQLCipher Android to new API (#4874)

Co-authored-by: Benoit Marty <benoitm@element.io>
This commit is contained in:
夜坂雅
2025-06-23 15:29:44 +08:00
committed by GitHub
parent 7fab4edd41
commit 9248b6cfdf
3 changed files with 5 additions and 8 deletions

View File

@@ -178,7 +178,7 @@ matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose",
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
sqldelight-driver-jvm = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
sqldelight-coroutines = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
sqlcipher = "net.zetetic:android-database-sqlcipher:4.5.4"
sqlcipher = "net.zetetic:sqlcipher-android:4.9.0"
sqlite = "androidx.sqlite:sqlite-ktx:2.5.2"
unifiedpush = "org.unifiedpush.android:connector:3.0.10"
otaliastudios_transcoder = "com.otaliastudios:transcoder:0.11.2"

View File

@@ -19,7 +19,3 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# Prevent ProGuard from renaming internal SQLCipher classes, which breaks the library.
# From https://github.com/sqlcipher/android-database-sqlcipher#proguard
-keep class net.sqlcipher.** { *; }

View File

@@ -13,10 +13,10 @@ import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlSchema
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import io.element.encrypteddb.passphrase.PassphraseProvider
import net.sqlcipher.database.SupportFactory
import net.zetetic.database.sqlcipher.SupportOpenHelperFactory
/**
* Creates an encrypted version of the [SqlDriver] using SQLCipher's [SupportFactory].
* Creates an encrypted version of the [SqlDriver] using SQLCipher's [SupportOpenHelperFactory].
* @param passphraseProvider Provides the passphrase needed to use the SQLite database with SQLCipher.
*/
class SqlCipherDriverFactory(
@@ -29,8 +29,9 @@ class SqlCipherDriverFactory(
* @param context Android [Context], used to instantiate the driver.
*/
fun create(schema: SqlSchema<QueryResult.Value<Unit>>, name: String, context: Context): SqlDriver {
System.loadLibrary("sqlcipher")
val passphrase = passphraseProvider.getPassphrase()
val factory = SupportFactory(passphrase)
val factory = SupportOpenHelperFactory(passphrase)
return AndroidSqliteDriver(schema = schema, context = context, name = name, factory = factory)
}
}