From 1cadbb8eedf7b085f916e68c9dbc694f68b3f978 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 Dec 2019 10:57:19 +0100 Subject: [PATCH] Ensure credentials can be stored, even if they already exist --- .../android/internal/auth/db/RealmSessionParamsStore.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt index dfe35c363b..1b15995ae6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt @@ -22,6 +22,8 @@ import im.vector.matrix.android.internal.database.awaitTransaction import im.vector.matrix.android.internal.di.AuthDatabase import io.realm.Realm import io.realm.RealmConfiguration +import io.realm.exceptions.RealmPrimaryKeyConstraintException +import timber.log.Timber import javax.inject.Inject internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper, @@ -63,7 +65,12 @@ internal class RealmSessionParamsStore @Inject constructor(private val mapper: S awaitTransaction(realmConfiguration) { val entity = mapper.map(sessionParams) if (entity != null) { - it.insert(entity) + try { + it.insert(entity) + } catch (e: RealmPrimaryKeyConstraintException) { + Timber.e(e, "Something wrong happened during previous session creation. Override with new credentials") + it.insertOrUpdate(entity) + } } } }