From 84158ece370d543c32718f5a4a669b1323953b79 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 7 Nov 2023 16:35:12 +0100 Subject: [PATCH] Ensure Background sync is not stopped when there is an active call. It was happening since the application is foregrounded when VectorCallActivity is displayed. --- changelog.d/4066.bugfix | 1 + .../java/im/vector/app/VectorApplication.kt | 24 +++++++++++++++---- .../features/call/webrtc/WebRtcCallManager.kt | 6 ++++- 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 changelog.d/4066.bugfix diff --git a/changelog.d/4066.bugfix b/changelog.d/4066.bugfix new file mode 100644 index 0000000000..7c97993511 --- /dev/null +++ b/changelog.d/4066.bugfix @@ -0,0 +1 @@ +Stop incoming call ringing if the call is cancelled or answered on another session. diff --git a/vector-app/src/main/java/im/vector/app/VectorApplication.kt b/vector-app/src/main/java/im/vector/app/VectorApplication.kt index 8d12292524..deb3d8d3aa 100644 --- a/vector-app/src/main/java/im/vector/app/VectorApplication.kt +++ b/vector-app/src/main/java/im/vector/app/VectorApplication.kt @@ -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) diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt index 1eb4134a87..c432e7ebd4 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt @@ -139,6 +139,7 @@ class WebRtcCallManager @Inject constructor( private val rootEglBase by lazy { EglUtils.rootEglBase } private var isInBackground: Boolean = true + private var syncStartedWhenInBackground: Boolean = false override fun onResume(owner: LifecycleOwner) { isInBackground = false @@ -274,13 +275,15 @@ class WebRtcCallManager @Inject constructor( peerConnectionFactory = null audioManager.setMode(CallAudioManager.Mode.DEFAULT) // did we start background sync? so we should stop it - if (isInBackground) { + if (syncStartedWhenInBackground) { if (!unifiedPushHelper.isBackgroundSync()) { + Timber.tag(loggerTag.value).v("Sync started when in background, stop it") currentSession?.syncService()?.stopAnyBackgroundSync() } else { // for fdroid we should not stop, it should continue syncing // maybe we should restore default timeout/delay though? } + syncStartedWhenInBackground = false } } } @@ -383,6 +386,7 @@ class WebRtcCallManager @Inject constructor( if (isInBackground) { if (!unifiedPushHelper.isBackgroundSync()) { // only for push version as fdroid version is already doing it? + syncStartedWhenInBackground = true currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0) } else { // Maybe increase sync freq? but how to set back to default values?