1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-05 15:52:47 +02:00

Ensure Background sync is not stopped when there is an active call.

It was happening since the application is foregrounded when VectorCallActivity is displayed.
This commit is contained in:
Benoit Marty
2023-11-07 16:35:12 +01:00
committed by Benoit Marty
parent 63ef40f58b
commit 84158ece37
3 changed files with 25 additions and 6 deletions

View File

@@ -108,6 +108,7 @@ class VectorApplication :
@Inject lateinit var buildMeta: BuildMeta
@Inject lateinit var leakDetector: LeakDetector
@Inject lateinit var vectorLocale: VectorLocale
@Inject lateinit var webRtcCallManager: WebRtcCallManager
// font thread handler
private var fontThreadHandler: Handler? = null
@@ -167,20 +168,33 @@ class VectorApplication :
notificationUtils.createNotificationChannels()
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
private var stopBackgroundSync = false
override fun onResume(owner: LifecycleOwner) {
Timber.i("App entered foreground")
fcmHelper.onEnterForeground(activeSessionHolder)
activeSessionHolder.getSafeActiveSessionAsync {
it?.syncService()?.stopAnyBackgroundSync()
if (webRtcCallManager.currentCall.get() == null) {
Timber.i("App entered foreground and no active call: stop any background sync")
activeSessionHolder.getSafeActiveSessionAsync {
it?.syncService()?.stopAnyBackgroundSync()
}
} else {
Timber.i("App entered foreground: there is an active call, set stopBackgroundSync to true")
stopBackgroundSync = true
}
// activeSessionHolder.getSafeActiveSession()?.also {
// it.syncService().stopAnyBackgroundSync()
// }
}
override fun onPause(owner: LifecycleOwner) {
Timber.i("App entered background")
fcmHelper.onEnterBackground(activeSessionHolder)
if (stopBackgroundSync) {
Timber.i("App entered background: stop any background sync")
activeSessionHolder.getSafeActiveSessionAsync {
it?.syncService()?.stopAnyBackgroundSync()
}
stopBackgroundSync = false
}
}
})
ProcessLifecycleOwner.get().lifecycle.addObserver(spaceStateHandler)