From 10efb01ebc63374dbc5c3392a1009af94c327531 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 4 Aug 2025 13:46:07 +0200 Subject: [PATCH] Fixed microphone not recording audio in background if SIP dialog doesn't reach Updating state --- .../notifications/NotificationsManager.kt | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index cdb33e49b..847c6fd83 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -204,27 +204,23 @@ class NotificationsManager ) showCallNotification(call, false) } - Call.State.Connected, - Call.State.StreamsRunning -> { - if (currentState == Call.State.Connected && call.dir == Call.Dir.Incoming) { + Call.State.Connected -> { + if (call.dir == Call.Dir.Incoming) { Log.i( "$TAG Connected call was incoming (so it was answered), removing incoming call notification" ) removeIncomingCallNotification() } - - if (currentState == Call.State.Connected || call.dir == Call.Dir.Incoming) { - Log.i( - "$TAG Showing connected call notification for [${call.remoteAddress.asStringUriOnly()}]" - ) - showCallNotification(call, false) - } + Log.i( + "$TAG Showing connected call notification for [${call.remoteAddress.asStringUriOnly()}]" + ) + showCallNotification(call, false) } - Call.State.Updating -> { + Call.State.StreamsRunning -> { val notifiable = getNotifiableForCall(call) if (notifiable.notificationId == currentInCallServiceNotificationId) { Log.i( - "$TAG Update foreground Service type in case video was enabled/disabled since last time" + "$TAG Update foreground service type in case video was enabled/disabled since last time" ) startInCallForegroundService(call) } @@ -853,7 +849,7 @@ class NotificationsManager if (Compatibility.isPostNotificationsPermissionGranted(context)) { Log.i( - "$TAG Service found, starting it as foreground using notification ID [${notifiable.notificationId}] with type(s) [$mask]" + "$TAG Service found, starting it as foreground using notification ID [${notifiable.notificationId}] with type(s) [${foregroundServiceTypeMaskToString(mask)}]($mask)" ) Compatibility.startServiceForeground( service, @@ -1777,6 +1773,26 @@ class NotificationsManager } } + @AnyThread + fun foregroundServiceTypeMaskToString(mask: Int): String { + var stringBuilder = StringBuilder() + val values = hashMapOf( + "PHONE_CALL" to Compatibility.FOREGROUND_SERVICE_TYPE_PHONE_CALL, + "MICROPHONE" to Compatibility.FOREGROUND_SERVICE_TYPE_MICROPHONE, + "CAMERA" to Compatibility.FOREGROUND_SERVICE_TYPE_CAMERA, + "SPECIAL_USE" to Compatibility.FOREGROUND_SERVICE_TYPE_SPECIAL_USE + ) + for ((key, value) in values) { + if (mask and value == value) { + if (stringBuilder.isNotEmpty()) { + stringBuilder.append(" & ") + } + stringBuilder.append(key) + } + } + return stringBuilder.toString() + } + class Notifiable(val notificationId: Int) { var myself: String? = null