Fixed hanging up call from notification

This commit is contained in:
Sylvain Berfini 2023-11-17 17:01:01 +01:00
parent c7f86311aa
commit c491f18ba5
2 changed files with 14 additions and 19 deletions

View file

@ -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
}

View file

@ -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