From bf14251c3df752d7f8837354251f9f60b5f6edc3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 14 May 2021 14:43:28 +0200 Subject: [PATCH] Remove usage of GlobalScope --- .../crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt | 4 ++-- .../crypto/recover/BootstrapSaveRecoveryKeyFragment.kt | 4 ++-- .../crypto/verification/VerificationBottomSheetViewModel.kt | 2 +- .../java/im/vector/app/features/home/HomeActivityViewModel.kt | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt index 9a3b5fa874..8833702e35 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt @@ -25,6 +25,7 @@ import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.core.view.isVisible +import androidx.lifecycle.lifecycleScope import arrow.core.Try import com.google.android.material.bottomsheet.BottomSheetDialog import im.vector.app.R @@ -37,7 +38,6 @@ import im.vector.app.core.utils.startSharePlainTextIntent import im.vector.app.databinding.FragmentKeysBackupSetupStep3Binding import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.IOException @@ -163,7 +163,7 @@ class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment if (activityResult.resultCode == Activity.RESULT_OK) { val uri = activityResult.data?.data ?: return@registerStartForActivityResult - GlobalScope.launch(Dispatchers.IO) { + lifecycleScope.launch(Dispatchers.IO) { try { sharedViewModel.handle(BootstrapActions.SaveKeyToUri(requireContext().contentResolver!!.openOutputStream(uri)!!)) } catch (failure: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt index a67cb96d37..8aa3d5423e 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheetViewModel.kt @@ -427,7 +427,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor( } private fun tentativeRestoreBackup(res: Map?) { - GlobalScope.launch(Dispatchers.IO) { + viewModelScope.launch(Dispatchers.IO) { try { val secret = res?.get(KEYBACKUP_SECRET_SSSS_NAME) ?: return@launch Unit.also { Timber.v("## Keybackup secret not restored from SSSS") diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index 447a567cf4..bfedbd6f52 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -27,9 +27,9 @@ import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.extensions.exhaustive import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.login.ReAuthHelper +import im.vector.app.features.session.coroutineScope import im.vector.app.features.settings.VectorPreferences import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.UIABaseAuth @@ -184,7 +184,7 @@ class HomeActivityViewModel @AssistedInject constructor( private fun maybeBootstrapCrossSigningAfterInitialSync() { // We do not use the viewModel context because we do not want to tie this action to activity view model - GlobalScope.launch(Dispatchers.IO) { + activeSessionHolder.getSafeActiveSession()?.coroutineScope?.launch(Dispatchers.IO) { val session = activeSessionHolder.getSafeActiveSession() ?: return@launch tryOrNull("## MaybeBootstrapCrossSigning: Failed to download keys") {