From a1ddd73d7d10711bef5fc461a8d2cbea88659717 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 1 Jul 2019 18:55:40 +0200 Subject: [PATCH 1/2] Fix / signout sign-in not working --- .../java/im/vector/matrix/android/api/session/Session.kt | 3 --- .../vector/matrix/android/internal/session/DefaultSession.kt | 5 +---- .../java/im/vector/riotredesign/features/MainActivity.kt | 5 +++++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt index d947e59326..864a9d6f57 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt @@ -81,13 +81,11 @@ interface Session : /** * This method start the sync thread. */ - @MainThread fun startSync() /** * This method stop the sync thread. */ - @MainThread fun stopSync() /** @@ -99,7 +97,6 @@ interface Session : /** * This method allow to close a session. It does stop some services. */ - @MainThread fun close() /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index e77cfd3c2f..bd25efaa89 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -102,7 +102,6 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se SyncWorker.stopAnyBackgroundSync(context) } - @MainThread override fun startSync() { assert(isOpen) if (!syncThread.isAlive) { @@ -113,16 +112,14 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se } } - @MainThread override fun stopSync() { assert(isOpen) syncThread.kill() } - @MainThread override fun close() { - assertMainThread() assert(isOpen) + stopSync() liveEntityObservers.forEach { it.dispose() } cryptoService.close() if (monarchy.isMonarchyThreadOpen) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt index f67663ac8a..2384828128 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt @@ -19,6 +19,7 @@ package im.vector.riotredesign.features import android.app.Activity import android.content.Intent import android.os.Bundle +import androidx.work.WorkManager import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.Authenticator @@ -66,6 +67,10 @@ class MainActivity : VectorBaseActivity() { override fun onSuccess(data: Unit) { Timber.w("SIGN_OUT: success, start app") sessionHolder.clearActiveSession() + WorkManager.getInstance(applicationContext).also { + it.cancelAllWork() + it.pruneWork() + } start() } }) From 95d64008aa4fb02d3599e567336a77955386f532 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 1 Jul 2019 20:12:05 +0200 Subject: [PATCH 2/2] Move to sdk --- .../matrix/android/internal/session/DefaultSession.kt | 6 ++++++ .../java/im/vector/riotredesign/features/MainActivity.kt | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index bd25efaa89..e98b459a49 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -20,6 +20,7 @@ import android.content.Context import android.os.Looper import androidx.annotation.MainThread import androidx.lifecycle.LiveData +import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.data.SessionParams @@ -150,6 +151,11 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se override fun onSuccess(data: Unit) { Timber.w("SIGN_OUT: clear cache -> SUCCESS: clear crypto cache") cryptoService.clearCryptoCache(MatrixCallbackDelegate(callback)) + + WorkManager.getInstance(context).also { + it.cancelAllWork() + it.pruneWork() + } } override fun onFailure(failure: Throwable) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt index 2384828128..f67663ac8a 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt @@ -19,7 +19,6 @@ package im.vector.riotredesign.features import android.app.Activity import android.content.Intent import android.os.Bundle -import androidx.work.WorkManager import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.Authenticator @@ -67,10 +66,6 @@ class MainActivity : VectorBaseActivity() { override fun onSuccess(data: Unit) { Timber.w("SIGN_OUT: success, start app") sessionHolder.clearActiveSession() - WorkManager.getInstance(applicationContext).also { - it.cancelAllWork() - it.pruneWork() - } start() } })