Display incoming group call notification properly

This commit is contained in:
Sylvain Berfini 2022-05-18 11:24:55 +02:00
parent 3a56969158
commit 52247c38d5
6 changed files with 110 additions and 30 deletions

View file

@ -113,12 +113,6 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) {
displayableAddress.value = clone.asStringUriOnly()
update()
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(call.remoteAddress)
if (conferenceInfo != null) {
Log.i("[Call] Found matching conference info with subject: ${conferenceInfo.subject}")
remoteConferenceSubject.value = conferenceInfo.subject
}
}
override fun destroy() {
@ -228,6 +222,7 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) {
val conference = call.conference
isInRemoteConference.value = conference != null
if (conference != null) {
Log.d("[Call] Found conference attached to call")
remoteConferenceSubject.value = if (conference.subject.isNullOrEmpty()) {
if (conference.me.isFocus) {
AppUtils.getString(R.string.conference_local_title)
@ -238,6 +233,15 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) {
conference.subject
}
Log.d("[Call] Found conference related to this call with subject [${remoteConferenceSubject.value}]")
} else {
val remoteContact = call.remoteContact
Log.d("[Call] Call's remote contact is $remoteContact")
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo != null) {
Log.d("[Call] Found matching conference info with subject: ${conferenceInfo.subject}")
remoteConferenceSubject.value = conferenceInfo.subject
}
}
}

View file

@ -149,15 +149,36 @@ class Api26Compatibility {
pendingIntent: PendingIntent,
notificationsManager: NotificationsManager
): Notification {
val contact: Friend? = coreContext.contactsManager.findContactByAddress(call.remoteAddress)
val roundPicture = ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
val displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
val address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
val contact: Friend?
val roundPicture: Bitmap?
val displayName: String
val address: String
val info: String
val remoteContact = call.remoteContact
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo == null) {
Log.i("[Notifications Manager] No conference info found for remote contact address $remoteContact")
contact = coreContext.contactsManager.findContactByAddress(call.remoteAddress)
roundPicture =
ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
info = context.getString(R.string.incoming_call_notification_title)
} else {
contact = null
displayName = conferenceInfo.subject ?: context.getString(R.string.conference)
address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
roundPicture = BitmapFactory.decodeResource(context.resources, R.drawable.voip_multiple_contacts_avatar_alt)
info = context.getString(R.string.incoming_group_call_notification_title)
Log.i("[Notifications Manager] Displaying incoming group call notification with subject $displayName for remote contact address $remoteContact")
}
val notificationLayoutHeadsUp = RemoteViews(context.packageName, R.layout.call_incoming_notification_heads_up)
notificationLayoutHeadsUp.setTextViewText(R.id.caller, displayName)
notificationLayoutHeadsUp.setTextViewText(R.id.sip_uri, address)
notificationLayoutHeadsUp.setTextViewText(R.id.incoming_call_info, context.getString(R.string.incoming_call_notification_title))
notificationLayoutHeadsUp.setTextViewText(R.id.incoming_call_info, info)
if (roundPicture != null) {
notificationLayoutHeadsUp.setImageViewBitmap(R.id.caller_picture, roundPicture)
@ -203,7 +224,9 @@ class Api26Compatibility {
val title: String
val person: Person
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(call.remoteAddress)
val remoteContact = call.remoteContact
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo == null) {
val contact: Friend? =
coreContext.contactsManager.findContactByAddress(call.remoteAddress)

View file

@ -51,18 +51,37 @@ class Api31Compatibility {
pendingIntent: PendingIntent,
notificationsManager: NotificationsManager
): Notification {
val contact = coreContext.contactsManager.findContactByAddress(call.remoteAddress)
val roundPicture = ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
val displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
val remoteContact = call.remoteContact
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo != null) {
Log.i("[Notifications Manager] Displaying incoming group call notification with subject ${conferenceInfo.subject} and remote contact address $remoteContact")
} else {
Log.i("[Notifications Manager] No conference info found for remote contact address $remoteContact")
}
val person = notificationsManager.getPerson(contact, displayName, roundPicture)
val caller = Person.Builder()
.setName(person.name)
.setIcon(person.icon?.toIcon(context))
.setUri(person.uri)
.setKey(person.key)
.setImportant(person.isImportant)
.build()
val caller = if (conferenceInfo == null) {
val contact =
coreContext.contactsManager.findContactByAddress(call.remoteAddress)
val roundPicture =
ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
val displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
val person = notificationsManager.getPerson(contact, displayName, roundPicture)
Person.Builder()
.setName(person.name)
.setIcon(person.icon?.toIcon(context))
.setUri(person.uri)
.setKey(person.key)
.setImportant(person.isImportant)
.build()
} else {
Person.Builder()
.setName(conferenceInfo.subject)
.setIcon(coreContext.contactsManager.groupAvatar.toIcon(context))
.setImportant(false)
.build()
}
val declineIntent = notificationsManager.getCallDeclinePendingIntent(notifiable)
val answerIntent = notificationsManager.getCallAnswerPendingIntent(notifiable)
@ -98,7 +117,15 @@ class Api31Compatibility {
channel: String,
notificationsManager: NotificationsManager
): Notification {
val conferenceInfo = coreContext.core.findConferenceInformationFromUri(call.remoteAddress)
val remoteContact = call.remoteContact
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo != null) {
Log.i("[Notifications Manager] Displaying incoming group call notification with subject ${conferenceInfo.subject} and remote contact address $remoteContact")
} else {
Log.i("[Notifications Manager] No conference info found for remote contact address $remoteContact")
}
val caller = if (conferenceInfo == null) {
val contact =
coreContext.contactsManager.findContactByAddress(call.remoteAddress)

View file

@ -22,6 +22,7 @@ package org.linphone.compatibility
import android.annotation.TargetApi
import android.app.*
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
@ -30,6 +31,8 @@ import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.contact.getThumbnailUri
import org.linphone.core.Call
import org.linphone.core.Friend
import org.linphone.core.tools.Log
import org.linphone.notifications.Notifiable
import org.linphone.notifications.NotificationsManager
import org.linphone.utils.ImageUtils
@ -45,10 +48,31 @@ class XiaomiCompatibility {
pendingIntent: PendingIntent,
notificationsManager: NotificationsManager
): Notification {
val contact = coreContext.contactsManager.findContactByAddress(call.remoteAddress)
val roundPicture = ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
val displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
val address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
val contact: Friend?
val roundPicture: Bitmap?
val displayName: String
val address: String
val info: String
val remoteContact = call.remoteContact
val conferenceAddress = if (remoteContact != null) coreContext.core.interpretUrl(remoteContact) else null
val conferenceInfo = if (conferenceAddress != null) coreContext.core.findConferenceInformationFromUri(conferenceAddress) else null
if (conferenceInfo == null) {
Log.i("[Notifications Manager] No conference info found for remote contact address $remoteContact")
contact = coreContext.contactsManager.findContactByAddress(call.remoteAddress)
roundPicture =
ImageUtils.getRoundBitmapFromUri(context, contact?.getThumbnailUri())
displayName = contact?.name ?: LinphoneUtils.getDisplayName(call.remoteAddress)
address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
info = context.getString(R.string.incoming_call_notification_title)
} else {
contact = null
displayName = conferenceInfo.subject ?: context.getString(R.string.conference)
address = LinphoneUtils.getDisplayableAddress(call.remoteAddress)
roundPicture = BitmapFactory.decodeResource(context.resources, R.drawable.voip_multiple_contacts_avatar_alt)
info = context.getString(R.string.incoming_group_call_notification_title)
Log.i("[Notifications Manager] Displaying incoming group call notification with subject $displayName and remote contact address $remoteContact")
}
val builder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_incoming_call_id))
.addPerson(notificationsManager.getPerson(contact, displayName, roundPicture))
@ -56,7 +80,7 @@ class XiaomiCompatibility {
.setLargeIcon(roundPicture ?: BitmapFactory.decodeResource(context.resources, R.drawable.voip_single_contact_avatar_alt))
.setContentTitle(displayName)
.setContentText(address)
.setSubText(context.getString(R.string.incoming_call_notification_title))
.setSubText(info)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_HIGH)

View file

@ -722,4 +722,5 @@
<string name="conference_group_call_subject_hint">Sujet de l\'appel de groupe</string>
<string name="conference_group_call_summary">Informations de l\'appel de groupe</string>
<string name="conference_group_call_create">Démarrer l\'appel de groupe</string>
<string name="incoming_group_call_notification_title">Appel de groupe entrant</string>
</resources>

View file

@ -681,7 +681,8 @@
<string name="notification_channel_missed_call_name">&appName; missed calls notifications</string>
<string name="notification_channel_incoming_call_name">&appName; incoming calls notifications</string>
<string name="notification_channel_chat_name">&appName; instant messages notifications</string>
<string name="incoming_call_notification_title">Call incoming</string>
<string name="incoming_call_notification_title">Incoming call</string>
<string name="incoming_group_call_notification_title">Incoming group call</string>
<string name="incoming_call_notification_hangup_action_label">Hangup</string>
<string name="incoming_call_notification_answer_action_label">Answer</string>
<string name="received_chat_notification_reply_label">Reply</string>