fix app locked on splash

This commit is contained in:
valere 2023-01-25 14:01:04 +01:00
parent 4ee53ad9d0
commit 6b3d1f185d
3 changed files with 21 additions and 3 deletions

View file

@ -49,7 +49,9 @@ class FdroidFcmHelper @Inject constructor(
override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) {
// try to stop all regardless of background mode
activeSessionHolder.getSafeActiveSession()?.syncService()?.stopAnyBackgroundSync()
activeSessionHolder.getSafeActiveSessionAsync {
it?.syncService()?.stopAnyBackgroundSync()
}
AlarmSyncBroadcastReceiver.cancelAlarm(context)
}

View file

@ -190,9 +190,12 @@ class VectorApplication :
override fun onResume(owner: LifecycleOwner) {
Timber.i("App entered foreground")
fcmHelper.onEnterForeground(activeSessionHolder)
activeSessionHolder.getSafeActiveSession()?.also {
it.syncService().stopAnyBackgroundSync()
activeSessionHolder.getSafeActiveSessionAsync {
it?.syncService()?.stopAnyBackgroundSync()
}
// activeSessionHolder.getSafeActiveSession()?.also {
// it.syncService().stopAnyBackgroundSync()
// }
}
override fun onPause(owner: LifecycleOwner) {

View file

@ -18,6 +18,7 @@ package im.vector.app.core.di
import android.content.Context
import im.vector.app.ActiveSessionDataSource
import im.vector.app.core.dispatchers.CoroutineDispatchers
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.core.session.ConfigureAndStartSessionUseCase
@ -26,7 +27,10 @@ import im.vector.app.features.crypto.keysrequest.KeyRequestHandler
import im.vector.app.features.crypto.verification.IncomingVerificationRequestHandler
import im.vector.app.features.notifications.PushRuleTriggerListener
import im.vector.app.features.session.SessionListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Optional
@ -51,6 +55,8 @@ class ActiveSessionHolder @Inject constructor(
private val authenticationService: AuthenticationService,
private val configureAndStartSessionUseCase: ConfigureAndStartSessionUseCase,
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
private val applicationCoroutineScope: CoroutineScope,
private val coroutineDispatchers: CoroutineDispatchers,
) {
private var activeSessionReference: AtomicReference<Session?> = AtomicReference()
@ -96,6 +102,13 @@ class ActiveSessionHolder @Inject constructor(
return runBlocking { getOrInitializeSession() }
}
fun getSafeActiveSessionAsync(withSession: ((Session?) -> Unit)) {
applicationCoroutineScope.launch(coroutineDispatchers.io) {
val session = getOrInitializeSession()
withSession(session)
}
}
fun getActiveSession(): Session {
return getSafeActiveSession()
?: throw IllegalStateException("You should authenticate before using this")