Merge pull request #4225 from vector-im/feature/adm/delaying-first-sync-until-foreground

Fixing unexpected sync occurring in background
This commit is contained in:
Benoit Marty 2021-10-12 14:31:57 +02:00 committed by GitHub
commit b6c483fff0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

1
changelog.d/4167.bugfix Normal file
View file

@ -0,0 +1 @@
Fixing push notifications starting the looping background sync when the push notification causes the application to be created.

View file

@ -44,6 +44,7 @@ import im.vector.app.core.di.DaggerVectorComponent
import im.vector.app.core.di.HasVectorInjector
import im.vector.app.core.di.VectorComponent
import im.vector.app.core.extensions.configureAndStart
import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.rx.RxConfig
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.configuration.VectorConfiguration
@ -163,11 +164,15 @@ class VectorApplication :
// Do not display the name change popup
doNotShowDisclaimerDialog(this)
}
if (authenticationService.hasAuthenticatedSessions() && !activeSessionHolder.hasActiveSession()) {
val lastAuthenticatedSession = authenticationService.getLastAuthenticatedSession()!!
activeSessionHolder.setActiveSession(lastAuthenticatedSession)
lastAuthenticatedSession.configureAndStart(applicationContext)
lastAuthenticatedSession.configureAndStart(applicationContext, startSyncing = false)
}
ProcessLifecycleOwner.get().lifecycle.addObserver(startSyncOnFirstStart)
ProcessLifecycleOwner.get().lifecycle.addObserver(object : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun entersForeground() {
@ -200,6 +205,15 @@ class VectorApplication :
EmojiManager.install(GoogleEmojiProvider())
}
private val startSyncOnFirstStart = object : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
Timber.i("App process started")
authenticationService.getLastAuthenticatedSession()?.startSyncing(appContext)
ProcessLifecycleOwner.get().lifecycle.removeObserver(this)
}
}
private fun enableStrictModeIfNeeded() {
if (BuildConfig.ENABLE_STRICT_MODE_LOGS) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()

View file

@ -26,11 +26,13 @@ import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupState
import org.matrix.android.sdk.api.session.sync.FilterService
import timber.log.Timber
fun Session.configureAndStart(context: Context) {
fun Session.configureAndStart(context: Context, startSyncing: Boolean = true) {
Timber.i("Configure and start session for $myUserId")
open()
setFilter(FilterService.FilterPreset.ElementFilter)
startSyncing(context)
if (startSyncing) {
startSyncing(context)
}
refreshPushers()
context.vectorComponent().webRtcCallManager().checkForProtocolsSupportIfNeeded()
}