From b03b6bfc370fe9eb2d5d0e8ad627f0c5bac8d72b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 24 Feb 2020 12:53:18 +0100 Subject: [PATCH] Fix crash discovered thanks to integration tests --- .../internal/crypto/keysbackup/DefaultKeysBackupService.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt index 5206aeedc2..3ec5a2f979 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt @@ -80,6 +80,7 @@ import im.vector.matrix.android.internal.util.JsonCanonicalizer import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.awaitCallback import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.matrix.olm.OlmException @@ -809,7 +810,10 @@ internal class DefaultKeysBackupService @Inject constructor( // new key is sent val delayInMs = Random.nextLong(KEY_BACKUP_WAITING_TIME_TO_SEND_KEY_BACKUP_MILLIS) - uiHandler.postDelayed({ backupKeys() }, delayInMs) + cryptoCoroutineScope.launch { + delay(delayInMs) + uiHandler.post { backupKeys() } + } } else -> { Timber.v("maybeBackupKeys: Skip it because state: $state")