Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep OngoingCallService always running during call [WPB-10467] #3300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class CallNotificationManager @Inject constructor(
hideIncomingCallNotification()
}

fun hideIncomingCallNotification() {
private fun hideIncomingCallNotification() {
appLogger.i("$TAG: hiding incoming call")

// This delay is just so when the user receives two calling signals one straight after the other [INCOMING -> CANCEL]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.wire.android.notification

import android.os.Build
import androidx.annotation.VisibleForTesting
import com.wire.android.R
import com.wire.android.appLogger
Expand Down Expand Up @@ -270,7 +269,7 @@ class WireNotificationManager @Inject constructor(
// start observing ongoing calls for all users, but only if not yet started
if (observingJobs.ongoingCallJob.get().let { it == null || !it.isActive }) {
val job = scope.launch(dispatcherProvider.default()) {
observeOngoingCalls(currentScreenState)
observeOngoingCalls()
}
observingJobs.ongoingCallJob.set(job)
}
Expand Down Expand Up @@ -405,34 +404,23 @@ class WireNotificationManager @Inject constructor(
/**
* Infinitely listen for the established calls of a current user and run OngoingCall foreground Service
* to show corresponding notification and do not lose a call.
* @param currentScreenState StateFlow that informs which screen is currently visible,
* so we can listen established calls only when the app is in background.
*/
private suspend fun observeOngoingCalls(currentScreenState: StateFlow<CurrentScreen>) {
currentScreenState
.flatMapLatest { currentScreen ->
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE && currentScreen !is CurrentScreen.InBackground) {
flowOf(null)
private suspend fun observeOngoingCalls() {
coreLogic.getGlobalScope().session.currentSessionFlow()
.flatMapLatest {
if (it is CurrentSessionResult.Success && it.accountInfo.isValid()) {
coreLogic.getSessionScope(it.accountInfo.userId).calls.establishedCall()
.map { it.isNotEmpty() }
} else {
coreLogic.getGlobalScope().session.currentSessionFlow()
.flatMapLatest {
if (it is CurrentSessionResult.Success && it.accountInfo.isValid()) {
coreLogic.getSessionScope(it.accountInfo.userId).calls.establishedCall()
.map {
it.firstOrNull()
}
} else {
flowOf(null)
}
}
flowOf(false)
}
}
.distinctUntilChanged()
.onCompletion {
servicesManager.stopOngoingCallService()
}
.collect { call ->
if (call != null) servicesManager.startOngoingCallService()
.collect { isOngoingCall ->
if (isOngoingCall) servicesManager.startOngoingCallService()
else servicesManager.stopOngoingCallService()
}
}
Expand Down Expand Up @@ -492,12 +480,6 @@ class WireNotificationManager @Inject constructor(
}
}

data class MessagesNotificationsData(
val newNotifications: List<LocalNotification>,
val userId: QualifiedID,
val userName: String
)

private data class UserObservingJobs(
val currentScreenJob: Job,
val incomingCallsJob: Job,
Expand Down
Loading
Loading