Merge pull request #8674 from vector-im/feature/bma/infiniteRingCall

Ensure Background sync is not stopped when there is an active call.
This commit is contained in:
Benoit Marty 2023-11-23 17:45:20 +01:00 committed by GitHub
commit 0c1f190035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 6 deletions

1
changelog.d/4066.bugfix Normal file
View file

@ -0,0 +1 @@
Stop incoming call ringing if the call is cancelled or answered on another session.

View file

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

View file

@ -139,6 +139,7 @@ class WebRtcCallManager @Inject constructor(
private val rootEglBase by lazy { EglUtils.rootEglBase } private val rootEglBase by lazy { EglUtils.rootEglBase }
private var isInBackground: Boolean = true private var isInBackground: Boolean = true
private var syncStartedWhenInBackground: Boolean = false
override fun onResume(owner: LifecycleOwner) { override fun onResume(owner: LifecycleOwner) {
isInBackground = false isInBackground = false
@ -274,13 +275,15 @@ class WebRtcCallManager @Inject constructor(
peerConnectionFactory = null peerConnectionFactory = null
audioManager.setMode(CallAudioManager.Mode.DEFAULT) audioManager.setMode(CallAudioManager.Mode.DEFAULT)
// did we start background sync? so we should stop it // did we start background sync? so we should stop it
if (isInBackground) { if (syncStartedWhenInBackground) {
if (!unifiedPushHelper.isBackgroundSync()) { if (!unifiedPushHelper.isBackgroundSync()) {
Timber.tag(loggerTag.value).v("Sync started when in background, stop it")
currentSession?.syncService()?.stopAnyBackgroundSync() currentSession?.syncService()?.stopAnyBackgroundSync()
} else { } else {
// for fdroid we should not stop, it should continue syncing // for fdroid we should not stop, it should continue syncing
// maybe we should restore default timeout/delay though? // maybe we should restore default timeout/delay though?
} }
syncStartedWhenInBackground = false
} }
} }
} }
@ -383,6 +386,7 @@ class WebRtcCallManager @Inject constructor(
if (isInBackground) { if (isInBackground) {
if (!unifiedPushHelper.isBackgroundSync()) { if (!unifiedPushHelper.isBackgroundSync()) {
// only for push version as fdroid version is already doing it? // only for push version as fdroid version is already doing it?
syncStartedWhenInBackground = true
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0) currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
} else { } else {
// Maybe increase sync freq? but how to set back to default values? // Maybe increase sync freq? but how to set back to default values?