delaying the first sync until the first process onStart event
- fixes push notifications starting the polling sync thread when the application is created due to push
This commit is contained in:
parent
7088e5cf54
commit
b7a54ead68
@ -43,6 +43,7 @@ import im.vector.app.core.di.DaggerVectorComponent
|
|||||||
import im.vector.app.core.di.HasVectorInjector
|
import im.vector.app.core.di.HasVectorInjector
|
||||||
import im.vector.app.core.di.VectorComponent
|
import im.vector.app.core.di.VectorComponent
|
||||||
import im.vector.app.core.extensions.configureAndStart
|
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.core.rx.RxConfig
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.configuration.VectorConfiguration
|
import im.vector.app.features.configuration.VectorConfiguration
|
||||||
@ -162,11 +163,15 @@ class VectorApplication :
|
|||||||
// Do not display the name change popup
|
// Do not display the name change popup
|
||||||
doNotShowDisclaimerDialog(this)
|
doNotShowDisclaimerDialog(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authenticationService.hasAuthenticatedSessions() && !activeSessionHolder.hasActiveSession()) {
|
if (authenticationService.hasAuthenticatedSessions() && !activeSessionHolder.hasActiveSession()) {
|
||||||
val lastAuthenticatedSession = authenticationService.getLastAuthenticatedSession()!!
|
val lastAuthenticatedSession = authenticationService.getLastAuthenticatedSession()!!
|
||||||
activeSessionHolder.setActiveSession(lastAuthenticatedSession)
|
activeSessionHolder.setActiveSession(lastAuthenticatedSession)
|
||||||
lastAuthenticatedSession.configureAndStart(applicationContext)
|
lastAuthenticatedSession.configureAndStart(applicationContext, startSyncing = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProcessLifecycleOwner.get().lifecycle.addObserver(startSyncOnFirstStart)
|
||||||
|
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(object : LifecycleObserver {
|
ProcessLifecycleOwner.get().lifecycle.addObserver(object : LifecycleObserver {
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
fun entersForeground() {
|
fun entersForeground() {
|
||||||
@ -199,6 +204,15 @@ class VectorApplication :
|
|||||||
EmojiManager.install(GoogleEmojiProvider())
|
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() {
|
private fun enableStrictModeIfNeeded() {
|
||||||
if (BuildConfig.ENABLE_STRICT_MODE_LOGS) {
|
if (BuildConfig.ENABLE_STRICT_MODE_LOGS) {
|
||||||
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
|
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 org.matrix.android.sdk.api.session.sync.FilterService
|
||||||
import timber.log.Timber
|
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")
|
Timber.i("Configure and start session for $myUserId")
|
||||||
open()
|
open()
|
||||||
setFilter(FilterService.FilterPreset.ElementFilter)
|
setFilter(FilterService.FilterPreset.ElementFilter)
|
||||||
startSyncing(context)
|
if (startSyncing) {
|
||||||
|
startSyncing(context)
|
||||||
|
}
|
||||||
refreshPushers()
|
refreshPushers()
|
||||||
context.vectorComponent().webRtcCallManager().checkForProtocolsSupportIfNeeded()
|
context.vectorComponent().webRtcCallManager().checkForProtocolsSupportIfNeeded()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user