mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 04:08:44 +03:00
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:
commit
b6c483fff0
3 changed files with 20 additions and 3 deletions
1
changelog.d/4167.bugfix
Normal file
1
changelog.d/4167.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fixing push notifications starting the looping background sync when the push notification causes the application to be created.
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue