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 09bfc820e4
commit 69d5b564da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)