Integrate Valere's remarks - step 2: Stop using (or at least reduce usage of) GlobalScope
This commit is contained in:
parent
a6541481bf
commit
e67e472025
@ -38,9 +38,8 @@ import im.vector.matrix.android.internal.auth.data.LoginFlowResponse
|
||||
import im.vector.matrix.android.internal.auth.data.RiotConfig
|
||||
import im.vector.matrix.android.internal.auth.db.PendingSessionData
|
||||
import im.vector.matrix.android.internal.auth.login.DefaultLoginWizard
|
||||
import im.vector.matrix.android.internal.auth.registration.DefaultRegistrationWizard
|
||||
import im.vector.matrix.android.internal.auth.login.DirectLoginTask
|
||||
import im.vector.matrix.android.internal.wellknown.GetWellknownTask
|
||||
import im.vector.matrix.android.internal.auth.registration.DefaultRegistrationWizard
|
||||
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||
import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
@ -50,7 +49,7 @@ import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.android.internal.util.exhaustive
|
||||
import im.vector.matrix.android.internal.util.toCancelable
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import im.vector.matrix.android.internal.wellknown.GetWellknownTask
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
@ -101,7 +100,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable {
|
||||
pendingSessionData = null
|
||||
|
||||
return GlobalScope.launch(coroutineDispatchers.main) {
|
||||
return taskExecutor.executorScope.launch(coroutineDispatchers.main) {
|
||||
pendingSessionStore.delete()
|
||||
|
||||
val result = runCatching {
|
||||
@ -253,7 +252,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
retrofitFactory,
|
||||
coroutineDispatchers,
|
||||
sessionCreator,
|
||||
pendingSessionStore
|
||||
pendingSessionStore,
|
||||
taskExecutor.executorScope
|
||||
).also {
|
||||
currentRegistrationWizard = it
|
||||
}
|
||||
@ -273,7 +273,8 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
retrofitFactory,
|
||||
coroutineDispatchers,
|
||||
sessionCreator,
|
||||
pendingSessionStore
|
||||
pendingSessionStore,
|
||||
taskExecutor.executorScope
|
||||
).also {
|
||||
currentLoginWizard = it
|
||||
}
|
||||
@ -290,7 +291,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
pendingSessionData = pendingSessionData?.homeServerConnectionConfig
|
||||
?.let { PendingSessionData(it) }
|
||||
.also {
|
||||
GlobalScope.launch(coroutineDispatchers.main) {
|
||||
taskExecutor.executorScope.launch(coroutineDispatchers.main) {
|
||||
if (it == null) {
|
||||
// Should not happen
|
||||
pendingSessionStore.delete()
|
||||
@ -307,7 +308,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
|
||||
pendingSessionData = null
|
||||
|
||||
GlobalScope.launch(coroutineDispatchers.main) {
|
||||
taskExecutor.executorScope.launch(coroutineDispatchers.main) {
|
||||
pendingSessionStore.delete()
|
||||
}
|
||||
}
|
||||
@ -315,7 +316,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
override fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
|
||||
credentials: Credentials,
|
||||
callback: MatrixCallback<Session>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
createSessionFromSso(credentials, homeServerConnectionConfig)
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
@ -47,7 +47,8 @@ internal class DefaultLoginWizard(
|
||||
retrofitFactory: RetrofitFactory,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sessionCreator: SessionCreator,
|
||||
private val pendingSessionStore: PendingSessionStore
|
||||
private val pendingSessionStore: PendingSessionStore,
|
||||
private val coroutineScope: CoroutineScope
|
||||
) : LoginWizard {
|
||||
|
||||
private var pendingSessionData: PendingSessionData = pendingSessionStore.getPendingSessionData() ?: error("Pending session data should exist here")
|
||||
@ -59,7 +60,7 @@ internal class DefaultLoginWizard(
|
||||
password: String,
|
||||
deviceName: String,
|
||||
callback: MatrixCallback<Session>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
loginInternal(login, password, deviceName)
|
||||
}
|
||||
}
|
||||
@ -80,7 +81,7 @@ internal class DefaultLoginWizard(
|
||||
}
|
||||
|
||||
override fun resetPassword(email: String, newPassword: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
resetPasswordInternal(email, newPassword)
|
||||
}
|
||||
}
|
||||
@ -108,7 +109,7 @@ internal class DefaultLoginWizard(
|
||||
callback.onFailure(IllegalStateException("developer error, no reset password in progress"))
|
||||
return NoOpCancellable
|
||||
}
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
resetPasswordMailConfirmedInternal(safeResetPasswordData)
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import im.vector.matrix.android.internal.auth.db.PendingSessionData
|
||||
import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||
import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
@ -45,7 +45,8 @@ internal class DefaultRegistrationWizard(
|
||||
private val retrofitFactory: RetrofitFactory,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sessionCreator: SessionCreator,
|
||||
private val pendingSessionStore: PendingSessionStore
|
||||
private val pendingSessionStore: PendingSessionStore,
|
||||
private val coroutineScope: CoroutineScope
|
||||
) : RegistrationWizard {
|
||||
|
||||
private var pendingSessionData: PendingSessionData = pendingSessionStore.getPendingSessionData() ?: error("Pending session data should exist here")
|
||||
@ -72,7 +73,7 @@ internal class DefaultRegistrationWizard(
|
||||
|
||||
override fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): Cancelable {
|
||||
val params = RegistrationParams()
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
performRegistrationRequest(params)
|
||||
}
|
||||
}
|
||||
@ -86,7 +87,7 @@ internal class DefaultRegistrationWizard(
|
||||
password = password,
|
||||
initialDeviceDisplayName = initialDeviceDisplayName
|
||||
)
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
performRegistrationRequest(params)
|
||||
.also {
|
||||
pendingSessionData = pendingSessionData.copy(isRegistrationStarted = true)
|
||||
@ -101,7 +102,7 @@ internal class DefaultRegistrationWizard(
|
||||
return NoOpCancellable
|
||||
}
|
||||
val params = RegistrationParams(auth = AuthParams.createForCaptcha(safeSession, response))
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
performRegistrationRequest(params)
|
||||
}
|
||||
}
|
||||
@ -112,13 +113,13 @@ internal class DefaultRegistrationWizard(
|
||||
return NoOpCancellable
|
||||
}
|
||||
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.TERMS, session = safeSession))
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
performRegistrationRequest(params)
|
||||
}
|
||||
}
|
||||
|
||||
override fun addThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
pendingSessionData = pendingSessionData.copy(currentThreePidData = null)
|
||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||
|
||||
@ -131,7 +132,7 @@ internal class DefaultRegistrationWizard(
|
||||
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
|
||||
return NoOpCancellable
|
||||
}
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
sendThreePid(safeCurrentThreePid)
|
||||
}
|
||||
}
|
||||
@ -177,13 +178,13 @@ internal class DefaultRegistrationWizard(
|
||||
callback.onFailure(IllegalStateException("developer error, no pending three pid"))
|
||||
return NoOpCancellable
|
||||
}
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
performRegistrationRequest(safeParam, delayMillis)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
validateThreePid(code)
|
||||
}
|
||||
}
|
||||
@ -214,7 +215,7 @@ internal class DefaultRegistrationWizard(
|
||||
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
|
||||
return NoOpCancellable
|
||||
}
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return coroutineScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.DUMMY, session = safeSession))
|
||||
performRegistrationRequest(params)
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ import im.vector.matrix.android.internal.crypto.verification.qrcode.generateShar
|
||||
import im.vector.matrix.android.internal.di.DeviceId
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
@ -104,7 +104,8 @@ internal class DefaultVerificationService @Inject constructor(
|
||||
private val verificationTransportRoomMessageFactory: VerificationTransportRoomMessageFactory,
|
||||
private val verificationTransportToDeviceFactory: VerificationTransportToDeviceFactory,
|
||||
private val crossSigningService: CrossSigningService,
|
||||
private val cryptoCoroutineScope: CoroutineScope
|
||||
private val cryptoCoroutineScope: CoroutineScope,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : DefaultVerificationTransaction.Listener, VerificationService {
|
||||
|
||||
private val uiHandler = Handler(Looper.getMainLooper())
|
||||
@ -161,7 +162,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||
}
|
||||
|
||||
fun onRoomEvent(event: Event) {
|
||||
GlobalScope.launch(coroutineDispatchers.crypto) {
|
||||
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
||||
when (event.getClearType()) {
|
||||
EventType.KEY_VERIFICATION_START -> {
|
||||
onRoomStartRequestReceived(event)
|
||||
@ -301,7 +302,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||
// We don't want to block here
|
||||
val otherDeviceId = validRequestInfo.fromDevice
|
||||
|
||||
GlobalScope.launch {
|
||||
cryptoCoroutineScope.launch {
|
||||
if (checkKeysAreDownloaded(senderId, otherDeviceId) == null) {
|
||||
Timber.e("## Verification device $otherDeviceId is not known")
|
||||
}
|
||||
@ -340,7 +341,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||
}
|
||||
|
||||
// We don't want to block here
|
||||
GlobalScope.launch {
|
||||
taskExecutor.executorScope.launch {
|
||||
if (checkKeysAreDownloaded(senderId, validRequestInfo.fromDevice) == null) {
|
||||
Timber.e("## SAS Verification device ${validRequestInfo.fromDevice} is not known")
|
||||
}
|
||||
|
@ -48,10 +48,11 @@ import im.vector.matrix.android.internal.di.SessionId
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.di.WorkManagerProvider
|
||||
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.util.StringProvider
|
||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.util.UUID
|
||||
@ -66,7 +67,8 @@ internal class VerificationTransportRoomMessage(
|
||||
private val userDeviceId: String?,
|
||||
private val roomId: String,
|
||||
private val localEchoEventFactory: LocalEchoEventFactory,
|
||||
private val tx: DefaultVerificationTransaction?
|
||||
private val tx: DefaultVerificationTransaction?,
|
||||
private val coroutineScope: CoroutineScope
|
||||
) : VerificationTransport {
|
||||
|
||||
override fun <T> sendToOther(type: String,
|
||||
@ -131,7 +133,7 @@ internal class VerificationTransportRoomMessage(
|
||||
}
|
||||
|
||||
// TODO listen to DB to get synced info
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
coroutineScope.launch(Dispatchers.Main) {
|
||||
workLiveData.observeForever(observer)
|
||||
}
|
||||
}
|
||||
@ -212,7 +214,7 @@ internal class VerificationTransportRoomMessage(
|
||||
}
|
||||
|
||||
// TODO listen to DB to get synced info
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
coroutineScope.launch(Dispatchers.Main) {
|
||||
workLiveData.observeForever(observer)
|
||||
}
|
||||
}
|
||||
@ -265,7 +267,7 @@ internal class VerificationTransportRoomMessage(
|
||||
}
|
||||
|
||||
// TODO listen to DB to get synced info
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
coroutineScope.launch(Dispatchers.Main) {
|
||||
workLiveData.observeForever(observer)
|
||||
}
|
||||
}
|
||||
@ -384,9 +386,19 @@ internal class VerificationTransportRoomMessageFactory @Inject constructor(
|
||||
private val userId: String,
|
||||
@DeviceId
|
||||
private val deviceId: String?,
|
||||
private val localEchoEventFactory: LocalEchoEventFactory) {
|
||||
private val localEchoEventFactory: LocalEchoEventFactory,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) {
|
||||
|
||||
fun createTransport(roomId: String, tx: DefaultVerificationTransaction?): VerificationTransportRoomMessage {
|
||||
return VerificationTransportRoomMessage(workManagerProvider, stringProvider, sessionId, userId, deviceId, roomId, localEchoEventFactory, tx)
|
||||
return VerificationTransportRoomMessage(workManagerProvider,
|
||||
stringProvider,
|
||||
sessionId,
|
||||
userId,
|
||||
deviceId,
|
||||
roomId,
|
||||
localEchoEventFactory,
|
||||
tx,
|
||||
taskExecutor.executorScope)
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ import im.vector.matrix.android.internal.di.ExternalFilesDirectory
|
||||
import im.vector.matrix.android.internal.di.SessionCacheDirectory
|
||||
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||
import im.vector.matrix.android.internal.extensions.foldToCallback
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.android.internal.util.toCancelable
|
||||
import im.vector.matrix.android.internal.util.writeToFile
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
@ -51,7 +51,9 @@ internal class DefaultFileService @Inject constructor(
|
||||
private val contentUrlResolver: ContentUrlResolver,
|
||||
@Unauthenticated
|
||||
private val okHttpClient: OkHttpClient,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers) : FileService {
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : FileService {
|
||||
|
||||
/**
|
||||
* Download file in the cache folder, and eventually decrypt it
|
||||
@ -63,7 +65,7 @@ internal class DefaultFileService @Inject constructor(
|
||||
url: String?,
|
||||
elementToDecrypt: ElementToDecrypt?,
|
||||
callback: MatrixCallback<File>): Cancelable {
|
||||
return GlobalScope.launch(coroutineDispatchers.main) {
|
||||
return taskExecutor.executorScope.launch(coroutineDispatchers.main) {
|
||||
withContext(coroutineDispatchers.io) {
|
||||
Try {
|
||||
val folder = File(sessionCacheDirectory, "MF")
|
||||
|
@ -56,9 +56,9 @@ import im.vector.matrix.android.internal.session.room.timeline.TimelineEventDecr
|
||||
import im.vector.matrix.android.internal.session.sync.SyncTokenStore
|
||||
import im.vector.matrix.android.internal.session.sync.job.SyncThread
|
||||
import im.vector.matrix.android.internal.session.sync.job.SyncWorker
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@ -103,8 +103,9 @@ internal class DefaultSession @Inject constructor(
|
||||
private val timelineEventDecryptor: TimelineEventDecryptor,
|
||||
private val shieldTrustUpdater: ShieldTrustUpdater,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val defaultIdentityService: DefaultIdentityService)
|
||||
: Session,
|
||||
private val defaultIdentityService: DefaultIdentityService,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : Session,
|
||||
RoomService by roomService.get(),
|
||||
RoomDirectoryService by roomDirectoryService.get(),
|
||||
GroupService by groupService.get(),
|
||||
@ -183,7 +184,7 @@ internal class DefaultSession @Inject constructor(
|
||||
isOpen = false
|
||||
eventBus.unregister(this)
|
||||
shieldTrustUpdater.stop()
|
||||
GlobalScope.launch(coroutineDispatchers.main) {
|
||||
taskExecutor.executorScope.launch(coroutineDispatchers.main) {
|
||||
// This has to be done on main thread
|
||||
defaultIdentityService.stop()
|
||||
}
|
||||
@ -216,7 +217,7 @@ internal class DefaultSession @Inject constructor(
|
||||
if (globalError is GlobalError.InvalidToken
|
||||
&& globalError.softLogout) {
|
||||
// Mark the token has invalid
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
taskExecutor.executorScope.launch(Dispatchers.IO) {
|
||||
sessionParamsStore.setTokenInvalid(sessionId)
|
||||
}
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ import im.vector.matrix.android.internal.session.profile.UnbindThreePidsTask
|
||||
import im.vector.matrix.android.internal.session.sync.model.accountdata.IdentityServerContent
|
||||
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
|
||||
import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import im.vector.matrix.android.internal.util.ensureProtocol
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import timber.log.Timber
|
||||
@ -80,7 +80,8 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
private val identityApiProvider: IdentityApiProvider,
|
||||
private val accountDataDataSource: AccountDataDataSource,
|
||||
private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
|
||||
private val sessionParams: SessionParams
|
||||
private val sessionParams: SessionParams,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : IdentityService {
|
||||
|
||||
private val lifecycleOwner: LifecycleOwner = LifecycleOwner { lifecycleRegistry }
|
||||
@ -138,19 +139,19 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
return NoOpCancellable
|
||||
}
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, false))
|
||||
}
|
||||
}
|
||||
|
||||
override fun cancelBindThreePid(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
identityStore.deletePendingBinding(threePid)
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendAgainValidationCode(threePid: ThreePid, callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
identityRequestTokenForBindingTask.execute(IdentityRequestTokenForBindingTask.Params(threePid, true))
|
||||
}
|
||||
}
|
||||
@ -161,13 +162,13 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
return NoOpCancellable
|
||||
}
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
bindThreePidsTask.execute(BindThreePidsTask.Params(threePid))
|
||||
}
|
||||
}
|
||||
|
||||
override fun submitValidationToken(threePid: ThreePid, code: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
submitTokenForBindingTask.execute(IdentitySubmitTokenForBindingTask.Params(threePid, code))
|
||||
}
|
||||
}
|
||||
@ -178,13 +179,13 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
return NoOpCancellable
|
||||
}
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
unbindThreePidsTask.execute(UnbindThreePidsTask.Params(threePid))
|
||||
}
|
||||
}
|
||||
|
||||
override fun isValidIdentityServer(url: String, callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val api = retrofitFactory.create(unauthenticatedOkHttpClient, url).create(IdentityAuthAPI::class.java)
|
||||
|
||||
identityPingTask.execute(IdentityPingTask.Params(api))
|
||||
@ -192,7 +193,7 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
}
|
||||
|
||||
override fun disconnect(callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
identityDisconnectTask.execute(Unit)
|
||||
|
||||
identityStore.setUrl(null)
|
||||
@ -204,7 +205,7 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
override fun setNewIdentityServer(url: String, callback: MatrixCallback<String>): Cancelable {
|
||||
val urlCandidate = url.ensureProtocol()
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val current = getCurrentIdentityServerUrl()
|
||||
if (urlCandidate == current) {
|
||||
// Nothing to do
|
||||
@ -246,7 +247,7 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
return NoOpCancellable
|
||||
}
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
lookUpInternal(true, threePids)
|
||||
}
|
||||
}
|
||||
@ -257,7 +258,7 @@ internal class DefaultIdentityService @Inject constructor(
|
||||
return NoOpCancellable
|
||||
}
|
||||
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val lookupResult = lookUpInternal(true, threePids)
|
||||
|
||||
threePids.associateWith { threePid ->
|
||||
|
@ -25,7 +25,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultSignOutService @Inject constructor(private val signOutTask: SignOutTask,
|
||||
@ -45,7 +44,7 @@ internal class DefaultSignOutService @Inject constructor(private val signOutTask
|
||||
|
||||
override fun updateCredentials(credentials: Credentials,
|
||||
callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
sessionParamsStore.updateCredentials(credentials)
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ import im.vector.matrix.android.internal.session.openid.GetOpenIdTokenTask
|
||||
import im.vector.matrix.android.internal.session.sync.model.accountdata.AcceptedTermsContent
|
||||
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
|
||||
import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.launchToCallback
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -48,12 +48,13 @@ internal class DefaultTermsService @Inject constructor(
|
||||
private val getOpenIdTokenTask: GetOpenIdTokenTask,
|
||||
private val identityRegisterTask: IdentityRegisterTask,
|
||||
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : TermsService {
|
||||
override fun getTerms(serviceType: TermsService.ServiceType,
|
||||
baseUrl: String,
|
||||
callback: MatrixCallback<GetTermsResponse>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
||||
|
||||
val url = when (serviceType) {
|
||||
@ -74,7 +75,7 @@ internal class DefaultTermsService @Inject constructor(
|
||||
agreedUrls: List<String>,
|
||||
token: String?,
|
||||
callback: MatrixCallback<Unit>): Cancelable {
|
||||
return GlobalScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, callback) {
|
||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
||||
|
||||
val url = when (serviceType) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package im.vector.riotx.features.settings.devtools
|
||||
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.Loading
|
||||
@ -31,7 +32,6 @@ import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.riotx.core.platform.EmptyAction
|
||||
import im.vector.riotx.core.platform.EmptyViewEvents
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class GossipingEventsPaperTrailState(
|
||||
@ -50,7 +50,7 @@ class GossipingEventsPaperTrailViewModel @AssistedInject constructor(@Assisted i
|
||||
setState {
|
||||
copy(events = Loading())
|
||||
}
|
||||
GlobalScope.launch {
|
||||
viewModelScope.launch {
|
||||
session.cryptoService().getGossipingEventsTrail().let {
|
||||
val sorted = it.sortedByDescending { it.ageLocalTs }
|
||||
setState {
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package im.vector.riotx.features.settings.devtools
|
||||
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
@ -31,7 +32,6 @@ import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequest
|
||||
import im.vector.riotx.core.platform.EmptyAction
|
||||
import im.vector.riotx.core.platform.EmptyViewEvents
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class KeyRequestListViewState(
|
||||
@ -48,7 +48,7 @@ class KeyRequestListViewModel @AssistedInject constructor(@Assisted initialState
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
GlobalScope.launch {
|
||||
viewModelScope.launch {
|
||||
session.cryptoService().getOutgoingRoomKeyRequest().let {
|
||||
setState {
|
||||
copy(
|
||||
|
Loading…
x
Reference in New Issue
Block a user