Fix Exception: java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file.

See for instance https://github.com/matrix-org/element-android-rageshakes/issues/41975
This commit is contained in:
Benoit Marty 2022-08-23 15:33:36 +02:00
parent 203a262c66
commit 58954ed590
2 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.database
import io.realm.DefaultCompactOnLaunchCallback
import javax.inject.Inject
class RealmCompactOnLaunch @Inject constructor() : DefaultCompactOnLaunchCallback() {
/**
* Forces all RealmCompactOnLaunch instances to be equal.
* Avoids Realm throwing when multiple instances of this class are used.
*/
override fun equals(other: Any?) = other is RealmSessionStoreMigration
override fun hashCode() = 0x1000
}

View File

@ -41,6 +41,7 @@ private const val REALM_NAME = "disk_store.realm"
internal class SessionRealmConfigurationFactory @Inject constructor(
private val realmKeysUtils: RealmKeysUtils,
private val realmSessionStoreMigration: RealmSessionStoreMigration,
private val realmCompactOnLaunch: RealmCompactOnLaunch,
@SessionFilesDirectory val directory: File,
@SessionId val sessionId: String,
@UserMd5 val userMd5: String,
@ -64,7 +65,7 @@ internal class SessionRealmConfigurationFactory @Inject constructor(
}
val realmConfiguration = RealmConfiguration.Builder()
.compactOnLaunch()
.compactOnLaunch(realmCompactOnLaunch)
.directory(directory)
.name(REALM_NAME)
.apply {