Fix crash when creating an EncryptedFile in Android 6 (#2853)

This commit is contained in:
Jorge Martin Espinosa
2024-05-15 18:10:16 +02:00
committed by GitHub
parent d103872f42
commit 822705195f
2 changed files with 8 additions and 0 deletions

1
changelog.d/2846.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix a crash when trying to create an `EncryptedFile` in Android 6.

View File

@@ -35,6 +35,13 @@ object SessionStorageModule {
fun provideMatrixDatabase(@ApplicationContext context: Context): SessionDatabase {
val name = "session_database"
val secretFile = context.getDatabasePath("$name.key")
// Make sure the parent directory of the key file exists, otherwise it will crash in older Android versions
val parentDir = secretFile.parentFile
if (parentDir != null && !parentDir.exists()) {
parentDir.mkdirs()
}
val passphraseProvider = RandomSecretPassphraseProvider(context, secretFile)
val driver = SqlCipherDriverFactory(passphraseProvider)
.create(SessionDatabase.Schema, "$name.db", context)