From c491f18ba57b746d27b1e6fc0f75efcc7ed08c1b Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 17 Nov 2023 17:01:01 +0100 Subject: [PATCH] Fixed hanging up call from notification --- .../NotificationBroadcastReceiver.kt | 24 +++++++++---------- .../notifications/NotificationsManager.kt | 9 +++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.kt b/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.kt index e1db4e5f7..91d232f34 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationBroadcastReceiver.kt @@ -40,23 +40,25 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { ) if (intent.action == NotificationsManager.INTENT_ANSWER_CALL_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_HANGUP_CALL_NOTIF_ACTION) { - handleCallIntent(intent) + handleCallIntent(intent, notificationId) } else if (intent.action == NotificationsManager.INTENT_REPLY_MESSAGE_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_MARK_MESSAGE_AS_READ_NOTIF_ACTION) { handleChatIntent(context, intent, notificationId) } } - private fun handleCallIntent(intent: Intent) { - val callId = intent.getStringExtra(NotificationsManager.INTENT_CALL_ID) - if (callId == null) { - Log.e("$TAG Remote SIP address is null for notification") + private fun handleCallIntent(intent: Intent, notificationId: Int) { + val remoteSipAddress = intent.getStringExtra(NotificationsManager.INTENT_REMOTE_ADDRESS) + if (remoteSipAddress == null) { + Log.e("$TAG Remote SIP address is null for call notification ID [$notificationId]") return } coreContext.postOnCoreThread { core -> - val call = core.getCallByCallid(callId) + val call = core.calls.find { + it.remoteAddress.asStringUriOnly() == remoteSipAddress + } if (call == null) { - Log.e("$TAG Couldn't find call from ID [$callId]") + Log.e("$TAG Couldn't find call from remote address [$remoteSipAddress]") } else { if (intent.action == NotificationsManager.INTENT_ANSWER_CALL_NOTIF_ACTION) { coreContext.answerCall(call) @@ -74,16 +76,12 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { private fun handleChatIntent(context: Context, intent: Intent, notificationId: Int) { val remoteSipAddress = intent.getStringExtra(NotificationsManager.INTENT_REMOTE_ADDRESS) if (remoteSipAddress == null) { - Log.e( - "$TAG Remote SIP address is null for notification id $notificationId" - ) + Log.e("$TAG Remote SIP address is null for notification ID [$notificationId]") return } val localIdentity = intent.getStringExtra(NotificationsManager.INTENT_LOCAL_IDENTITY) if (localIdentity == null) { - Log.e( - "$TAG Local identity is null for notification id $notificationId" - ) + Log.e("$TAG Local identity is null for notification ID [$notificationId]") return } diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index f64d7ca3b..44135f5da 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -79,8 +79,6 @@ class NotificationsManager @MainThread constructor(private val context: Context) const val INTENT_ANSWER_CALL_NOTIF_ACTION = "org.linphone.ANSWER_CALL_ACTION" const val INTENT_REPLY_MESSAGE_NOTIF_ACTION = "org.linphone.REPLY_ACTION" const val INTENT_MARK_MESSAGE_AS_READ_NOTIF_ACTION = "org.linphone.MARK_AS_READ_ACTION" - - const val INTENT_CALL_ID = "CALL_ID" const val INTENT_NOTIF_ID = "NOTIFICATION_ID" const val KEY_TEXT_REPLY = "key_text_reply" @@ -640,7 +638,7 @@ class NotificationsManager @MainThread constructor(private val context: Context) var notifiable: Notifiable? = callNotificationsMap[address] if (notifiable == null) { notifiable = Notifiable(getNotificationIdForCall(call)) - notifiable.callId = call.callLog.callId + notifiable.remoteAddress = call.remoteAddress.asStringUriOnly() callNotificationsMap[address] = notifiable } @@ -897,7 +895,7 @@ class NotificationsManager @MainThread constructor(private val context: Context) val hangupIntent = Intent(context, NotificationBroadcastReceiver::class.java) hangupIntent.action = INTENT_HANGUP_CALL_NOTIF_ACTION hangupIntent.putExtra(INTENT_NOTIF_ID, notifiable.notificationId) - hangupIntent.putExtra(INTENT_CALL_ID, notifiable.callId) + hangupIntent.putExtra(INTENT_REMOTE_ADDRESS, notifiable.remoteAddress) return PendingIntent.getBroadcast( context, @@ -912,7 +910,7 @@ class NotificationsManager @MainThread constructor(private val context: Context) val answerIntent = Intent(context, NotificationBroadcastReceiver::class.java) answerIntent.action = INTENT_ANSWER_CALL_NOTIF_ACTION answerIntent.putExtra(INTENT_NOTIF_ID, notifiable.notificationId) - answerIntent.putExtra(INTENT_CALL_ID, notifiable.callId) + answerIntent.putExtra(INTENT_REMOTE_ADDRESS, notifiable.remoteAddress) return PendingIntent.getBroadcast( context, @@ -1096,7 +1094,6 @@ class NotificationsManager @MainThread constructor(private val context: Context) class Notifiable(val notificationId: Int) { var myself: String? = null - var callId: String? = null var localIdentity: String? = null var remoteAddress: String? = null