Fixed service foreground notification preventing incoming call dialog to be displayed

This commit is contained in:
Sylvain Berfini 2022-01-27 10:01:26 +01:00
parent 6c3a5c2b9a
commit eb86ae1573

View file

@ -250,6 +250,7 @@ class NotificationsManager(private val context: Context) {
if (currentForegroundServiceNotificationId > 0) { if (currentForegroundServiceNotificationId > 0) {
notificationManager.cancel(currentForegroundServiceNotificationId) notificationManager.cancel(currentForegroundServiceNotificationId)
currentForegroundServiceNotificationId = 0
} }
for (notifiable in callNotificationsMap.values) { for (notifiable in callNotificationsMap.values) {
@ -300,8 +301,7 @@ class NotificationsManager(private val context: Context) {
val call = coreContext.core.currentCall ?: coreContext.core.calls[0] val call = coreContext.core.currentCall ?: coreContext.core.calls[0]
when (call.state) { when (call.state) {
Call.State.IncomingReceived, Call.State.IncomingEarlyMedia -> { Call.State.IncomingReceived, Call.State.IncomingEarlyMedia -> {
Log.i("[Notifications Manager] Creating incoming call notification to be used as foreground service") Log.i("[Notifications Manager] Waiting for call to be in state Connected before creating service notification")
displayIncomingCallNotification(call, true)
} }
else -> { else -> {
Log.i("[Notifications Manager] Creating call notification to be used as foreground service") Log.i("[Notifications Manager] Creating call notification to be used as foreground service")
@ -425,8 +425,9 @@ class NotificationsManager(private val context: Context) {
val notifiable = getNotifiableForCall(call) val notifiable = getNotifiableForCall(call)
if (notifiable.notificationId == currentForegroundServiceNotificationId) { if (notifiable.notificationId == currentForegroundServiceNotificationId) {
Log.w("[Notifications Manager] Incoming call notification already displayed by foreground service [${notifiable.notificationId}], skipping") Log.e("[Notifications Manager] There is already a Service foreground notification for an incoming call, cancelling it")
return cancel(notifiable.notificationId)
currentForegroundServiceNotificationId = 0
} }
val incomingCallNotificationIntent = Intent(context, IncomingCallActivity::class.java) val incomingCallNotificationIntent = Intent(context, IncomingCallActivity::class.java)
@ -539,7 +540,7 @@ class NotificationsManager(private val context: Context) {
Log.i("[Notifications Manager] Notifying call notification [${notifiable.notificationId}]") Log.i("[Notifications Manager] Notifying call notification [${notifiable.notificationId}]")
notify(notifiable.notificationId, notification) notify(notifiable.notificationId, notification)
if (useAsForeground) { if (useAsForeground || (service != null && currentForegroundServiceNotificationId == 0)) {
Log.i("[Notifications Manager] Notifying call notification for foreground service [${notifiable.notificationId}]") Log.i("[Notifications Manager] Notifying call notification for foreground service [${notifiable.notificationId}]")
startForeground(notifiable.notificationId, notification) startForeground(notifiable.notificationId, notification)
} }