From 95a29b83fe69ff320a9e8ab8507f84a7c18f3015 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 20 Dec 2022 13:12:54 +0100 Subject: [PATCH 1/2] ActiveSessionHolder is not supposed to start syncing. Instead, the MainActivity does it, if necessary. Fixes a race condition when clearing cache. --- .../im/vector/app/core/di/ActiveSessionHolder.kt | 16 +++++----------- .../vector/app/core/pushers/VectorPushHandler.kt | 2 +- .../java/im/vector/app/features/MainActivity.kt | 8 ++++++++ .../app/features/start/StartAppViewModel.kt | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt b/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt index fead1e15b1..e698f65bf4 100644 --- a/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt +++ b/vector/src/main/java/im/vector/app/core/di/ActiveSessionHolder.kt @@ -18,7 +18,6 @@ package im.vector.app.core.di import android.content.Context import im.vector.app.ActiveSessionDataSource -import im.vector.app.core.extensions.startSyncing import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase import im.vector.app.core.services.GuardServiceStarter import im.vector.app.core.session.ConfigureAndStartSessionUseCase @@ -72,7 +71,7 @@ class ActiveSessionHolder @Inject constructor( suspend fun clearActiveSession() { // Do some cleanup first - getSafeActiveSession(startSync = false)?.let { + getSafeActiveSession()?.let { Timber.w("clearActiveSession of ${it.myUserId}") it.callSignalingService().removeCallListener(callManager) it.removeListener(sessionListener) @@ -93,8 +92,8 @@ class ActiveSessionHolder @Inject constructor( return activeSessionReference.get() != null || authenticationService.hasAuthenticatedSessions() } - fun getSafeActiveSession(startSync: Boolean = true): Session? { - return runBlocking { getOrInitializeSession(startSync = startSync) } + fun getSafeActiveSession(): Session? { + return runBlocking { getOrInitializeSession() } } fun getActiveSession(): Session { @@ -102,16 +101,11 @@ class ActiveSessionHolder @Inject constructor( ?: throw IllegalStateException("You should authenticate before using this") } - suspend fun getOrInitializeSession(startSync: Boolean): Session? { + suspend fun getOrInitializeSession(): Session? { return activeSessionReference.get() - ?.also { - if (startSync && !it.syncService().isSyncThreadAlive()) { - it.startSyncing(applicationContext) - } - } ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session -> setActiveSession(session) - configureAndStartSessionUseCase.execute(session, startSyncing = startSync) + configureAndStartSessionUseCase.execute(session, startSyncing = false) } } diff --git a/vector/src/main/java/im/vector/app/core/pushers/VectorPushHandler.kt b/vector/src/main/java/im/vector/app/core/pushers/VectorPushHandler.kt index 0d2cd56995..04c71e0412 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/VectorPushHandler.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/VectorPushHandler.kt @@ -118,7 +118,7 @@ class VectorPushHandler @Inject constructor( Timber.tag(loggerTag.value).d("## handleInternal()") } - val session = activeSessionHolder.getOrInitializeSession(startSync = false) + val session = activeSessionHolder.getOrInitializeSession() if (session == null) { Timber.tag(loggerTag.value).w("## Can't sync from push, no current session") diff --git a/vector/src/main/java/im/vector/app/features/MainActivity.kt b/vector/src/main/java/im/vector/app/features/MainActivity.kt index c197cfccf3..8ce375122e 100644 --- a/vector/src/main/java/im/vector/app/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/app/features/MainActivity.kt @@ -174,12 +174,15 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity private fun handleAppStarted() { if (intent.hasExtra(EXTRA_NEXT_INTENT)) { // Start the next Activity + startSyncing() val nextIntent = intent.getParcelableExtraCompat(EXTRA_NEXT_INTENT) startIntentAndFinish(nextIntent) } else if (intent.hasExtra(EXTRA_INIT_SESSION)) { + startSyncing() setResult(RESULT_OK) finish() } else if (intent.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) { + startSyncing() val roomId = intent.getStringExtra(EXTRA_ROOM_ID) if (roomId?.isNotEmpty() == true) { navigator.openRoom(this, roomId, trigger = ViewRoom.Trigger.Shortcut) @@ -194,11 +197,16 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity if (args.clearCache || args.clearCredentials) { doCleanUp() } else { + startSyncing() startNextActivityAndFinish() } } } + private fun startSyncing() { + activeSessionHolder.getSafeActiveSession()?.startSyncing(this) + } + private fun clearNotifications() { // Dismiss all notifications notificationDrawerManager.clearAllEvents() diff --git a/vector/src/main/java/im/vector/app/features/start/StartAppViewModel.kt b/vector/src/main/java/im/vector/app/features/start/StartAppViewModel.kt index 4b2e7bef98..6eb8bf2e80 100644 --- a/vector/src/main/java/im/vector/app/features/start/StartAppViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/start/StartAppViewModel.kt @@ -63,7 +63,7 @@ class StartAppViewModel @AssistedInject constructor( } private suspend fun eagerlyInitializeSession() { - sessionHolder.getOrInitializeSession(startSync = true) + sessionHolder.getOrInitializeSession() } private fun handleLongProcessing() { From 576ea2df55ae0e928e9b8cdc28f12ab151036b70 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 20 Dec 2022 16:44:01 +0100 Subject: [PATCH 2/2] Prepare hotfix 1.5.14 --- CHANGES.md | 8 ++++++++ fastlane/metadata/android/en-US/changelogs/40105140.txt | 2 ++ matrix-sdk-android/build.gradle | 2 +- vector-app/build.gradle | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/40105140.txt diff --git a/CHANGES.md b/CHANGES.md index eb706221dc..cac9ab2608 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +Changes in Element v1.5.14 (2022-12-20) +======================================= + +Bugfixes 🐛 +---------- +- ActiveSessionHolder is not supposed to start syncing. Instead, the MainActivity does it, if necessary. Fixes a race condition when clearing cache. + + Changes in Element v1.5.13 (2022-12-19) ======================================= diff --git a/fastlane/metadata/android/en-US/changelogs/40105140.txt b/fastlane/metadata/android/en-US/changelogs/40105140.txt new file mode 100644 index 0000000000..91c25cf053 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40105140.txt @@ -0,0 +1,2 @@ +Main changes in this version: Thread are now enabled by default. +Full changelog: https://github.com/vector-im/element-android/releases diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 52e4539e8a..4558f4e8b5 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -62,7 +62,7 @@ android { // that the app's state is completely cleared between tests. testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "String", "SDK_VERSION", "\"1.5.13\"" + buildConfigField "String", "SDK_VERSION", "\"1.5.14\"" buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" buildConfigField "String", "GIT_SDK_REVISION_UNIX_DATE", "\"${gitRevisionUnixDate()}\"" diff --git a/vector-app/build.gradle b/vector-app/build.gradle index 11e8c6b3ed..7d1073764d 100644 --- a/vector-app/build.gradle +++ b/vector-app/build.gradle @@ -37,7 +37,7 @@ ext.versionMinor = 5 // Note: even values are reserved for regular release, odd values for hotfix release. // When creating a hotfix, you should decrease the value, since the current value // is the value for the next regular release. -ext.versionPatch = 13 +ext.versionPatch = 14 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct'