Skip to content

Commit 0c1f190

Browse files
authored
Merge pull request #8674 from vector-im/feature/bma/infiniteRingCall
Ensure Background sync is not stopped when there is an active call.
2 parents 63ef40f + 8d85d04 commit 0c1f190

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

changelog.d/4066.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stop incoming call ringing if the call is cancelled or answered on another session.

vector-app/src/main/java/im/vector/app/VectorApplication.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class VectorApplication :
108108
@Inject lateinit var buildMeta: BuildMeta
109109
@Inject lateinit var leakDetector: LeakDetector
110110
@Inject lateinit var vectorLocale: VectorLocale
111+
@Inject lateinit var webRtcCallManager: WebRtcCallManager
111112

112113
// font thread handler
113114
private var fontThreadHandler: Handler? = null
@@ -167,20 +168,37 @@ class VectorApplication :
167168
notificationUtils.createNotificationChannels()
168169

169170
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
171+
private var stopBackgroundSync = false
172+
170173
override fun onResume(owner: LifecycleOwner) {
171174
Timber.i("App entered foreground")
172175
fcmHelper.onEnterForeground(activeSessionHolder)
173-
activeSessionHolder.getSafeActiveSessionAsync {
174-
it?.syncService()?.stopAnyBackgroundSync()
176+
if (webRtcCallManager.currentCall.get() == null) {
177+
Timber.i("App entered foreground and no active call: stop any background sync")
178+
activeSessionHolder.getSafeActiveSessionAsync {
179+
it?.syncService()?.stopAnyBackgroundSync()
180+
}
181+
} else {
182+
Timber.i("App entered foreground: there is an active call, set stopBackgroundSync to true")
183+
stopBackgroundSync = true
175184
}
176-
// activeSessionHolder.getSafeActiveSession()?.also {
177-
// it.syncService().stopAnyBackgroundSync()
178-
// }
179185
}
180186

181187
override fun onPause(owner: LifecycleOwner) {
182188
Timber.i("App entered background")
183189
fcmHelper.onEnterBackground(activeSessionHolder)
190+
191+
if (stopBackgroundSync) {
192+
if (webRtcCallManager.currentCall.get() == null) {
193+
Timber.i("App entered background: stop any background sync")
194+
activeSessionHolder.getSafeActiveSessionAsync {
195+
it?.syncService()?.stopAnyBackgroundSync()
196+
}
197+
stopBackgroundSync = false
198+
} else {
199+
Timber.i("App entered background: there is an active call do not stop background sync")
200+
}
201+
}
184202
}
185203
})
186204
ProcessLifecycleOwner.get().lifecycle.addObserver(spaceStateHandler)

vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class WebRtcCallManager @Inject constructor(
139139
private val rootEglBase by lazy { EglUtils.rootEglBase }
140140

141141
private var isInBackground: Boolean = true
142+
private var syncStartedWhenInBackground: Boolean = false
142143

143144
override fun onResume(owner: LifecycleOwner) {
144145
isInBackground = false
@@ -274,13 +275,15 @@ class WebRtcCallManager @Inject constructor(
274275
peerConnectionFactory = null
275276
audioManager.setMode(CallAudioManager.Mode.DEFAULT)
276277
// did we start background sync? so we should stop it
277-
if (isInBackground) {
278+
if (syncStartedWhenInBackground) {
278279
if (!unifiedPushHelper.isBackgroundSync()) {
280+
Timber.tag(loggerTag.value).v("Sync started when in background, stop it")
279281
currentSession?.syncService()?.stopAnyBackgroundSync()
280282
} else {
281283
// for fdroid we should not stop, it should continue syncing
282284
// maybe we should restore default timeout/delay though?
283285
}
286+
syncStartedWhenInBackground = false
284287
}
285288
}
286289
}
@@ -383,6 +386,7 @@ class WebRtcCallManager @Inject constructor(
383386
if (isInBackground) {
384387
if (!unifiedPushHelper.isBackgroundSync()) {
385388
// only for push version as fdroid version is already doing it?
389+
syncStartedWhenInBackground = true
386390
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
387391
} else {
388392
// Maybe increase sync freq? but how to set back to default values?

0 commit comments

Comments
 (0)