From c447b2699c8e41d62247c955ed79c6f90ebf11bb Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 16 Jan 2024 14:00:57 +0100 Subject: [PATCH] Changes regarding call notifications --- .../org/linphone/contacts/ContactsManager.kt | 4 +- .../notifications/NotificationsManager.kt | 76 ++++++++++--------- .../telecom/TelecomCallControlCallback.kt | 3 +- .../org/linphone/telecom/TelecomManager.kt | 20 ++++- 4 files changed, 62 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/org/linphone/contacts/ContactsManager.kt b/app/src/main/java/org/linphone/contacts/ContactsManager.kt index bc0892390..49f135515 100644 --- a/app/src/main/java/org/linphone/contacts/ContactsManager.kt +++ b/app/src/main/java/org/linphone/contacts/ContactsManager.kt @@ -473,7 +473,7 @@ class ContactsManager @UiThread constructor() { val identity = account?.params?.identityAddress?.asStringUriOnly() ?: localAddress.asStringUriOnly() personBuilder.setKey(identity) - personBuilder.setImportant(false) + personBuilder.setImportant(true) return personBuilder.build() } @@ -546,7 +546,7 @@ fun Friend.getPerson(): Person { personBuilder.setKey(refKey) personBuilder.setUri(nativeUri) - personBuilder.setImportant(starred) + personBuilder.setImportant(true) return personBuilder.build() } diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 099c873cb..bedf07b11 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -58,6 +58,7 @@ import org.linphone.core.Core import org.linphone.core.CoreForegroundService import org.linphone.core.CoreListenerStub import org.linphone.core.Friend +import org.linphone.core.MediaDirection import org.linphone.core.tools.Log import org.linphone.ui.call.CallActivity import org.linphone.ui.main.MainActivity @@ -797,9 +798,9 @@ class NotificationsManager @MainThread constructor(private val context: Context) val isVideo = if (isConference) { true } else if (isIncoming) { - call.remoteParams?.isVideoEnabled ?: false + call.remoteParams?.isVideoEnabled == true && call.remoteParams?.videoDirection != MediaDirection.Inactive } else { - call.currentParams.isVideoEnabled + call.currentParams.isVideoEnabled && call.currentParams.videoDirection != MediaDirection.Inactive } val smallIcon = if (isConference) { @@ -864,7 +865,6 @@ class NotificationsManager @MainThread constructor(private val context: Context) setVisibility(NotificationCompat.VISIBILITY_PUBLIC) setWhen(System.currentTimeMillis()) setAutoCancel(false) - setShowWhen(true) setOngoing(true) setFullScreenIntent(pendingIntent, true) } @@ -1109,6 +1109,7 @@ class NotificationsManager @MainThread constructor(private val context: Context) AvatarGenerator(context).setInitials(AppUtils.getInitials(displayName)).buildIcon() ) .setKey(displayName) + .setImportant(false) .build() } @@ -1117,13 +1118,14 @@ class NotificationsManager @MainThread constructor(private val context: Context) val id = context.getString(R.string.notification_channel_incoming_call_id) val name = context.getString(R.string.notification_channel_incoming_call_name) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH) - channel.description = name - channel.lightColor = context.getColor(R.color.main1_500) - channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - channel.enableVibration(true) - channel.enableLights(true) - channel.setShowBadge(false) + val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH).apply { + description = name + lightColor = context.getColor(R.color.main1_500) + lockscreenVisibility = Notification.VISIBILITY_PUBLIC + enableVibration(true) + enableLights(true) + setShowBadge(false) + } notificationManager.createNotificationChannel(channel) } @@ -1132,13 +1134,14 @@ class NotificationsManager @MainThread constructor(private val context: Context) val id = context.getString(R.string.notification_channel_missed_call_id) val name = context.getString(R.string.notification_channel_missed_call_name) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH) - channel.description = name - channel.lightColor = context.getColor(R.color.main1_500) - channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - channel.enableVibration(true) - channel.enableLights(true) - channel.setShowBadge(false) + val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH).apply { + description = name + lightColor = context.getColor(R.color.main1_500) + lockscreenVisibility = Notification.VISIBILITY_PUBLIC + enableVibration(true) + enableLights(true) + setShowBadge(false) + } notificationManager.createNotificationChannel(channel) } @@ -1147,12 +1150,13 @@ class NotificationsManager @MainThread constructor(private val context: Context) val id = context.getString(R.string.notification_channel_call_id) val name = context.getString(R.string.notification_channel_call_name) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT) - channel.description = name - channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - channel.enableVibration(false) - channel.enableLights(false) - channel.setShowBadge(false) + val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT).apply { + description = name + lockscreenVisibility = Notification.VISIBILITY_PUBLIC + enableVibration(false) + enableLights(false) + setShowBadge(false) + } notificationManager.createNotificationChannel(channel) } @@ -1161,13 +1165,14 @@ class NotificationsManager @MainThread constructor(private val context: Context) val id = context.getString(R.string.notification_channel_chat_id) val name = context.getString(R.string.notification_channel_chat_name) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH) - channel.description = name - channel.lightColor = context.getColor(R.color.main1_500) - channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC - channel.enableLights(true) - channel.enableVibration(true) - channel.setShowBadge(true) + val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH).apply { + description = name + lightColor = context.getColor(R.color.main1_500) + lockscreenVisibility = Notification.VISIBILITY_PUBLIC + enableLights(true) + enableVibration(true) + setShowBadge(true) + } notificationManager.createNotificationChannel(channel) } @@ -1176,11 +1181,12 @@ class NotificationsManager @MainThread constructor(private val context: Context) val id = context.getString(R.string.notification_channel_service_id) val name = context.getString(R.string.notification_channel_service_name) - val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW) - channel.description = name - channel.enableVibration(false) - channel.enableLights(false) - channel.setShowBadge(false) + val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW).apply { + description = name + enableVibration(false) + enableLights(false) + setShowBadge(false) + } notificationManager.createNotificationChannel(channel) } diff --git a/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt b/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt index 014ac856f..29f46e18d 100644 --- a/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt +++ b/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt @@ -34,6 +34,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.core.AudioDevice import org.linphone.core.Call import org.linphone.core.CallListenerStub +import org.linphone.core.MediaDirection import org.linphone.core.tools.Log import org.linphone.utils.AudioUtils @@ -54,7 +55,7 @@ class TelecomCallControlCallback constructor( Log.i("$TAG Call [${call.remoteAddress.asStringUriOnly()}] state changed [$state]") if (state == Call.State.Connected) { if (call.dir == Call.Dir.Incoming) { - val videoEnabled = call.currentParams.isVideoEnabled + val videoEnabled = call.currentParams.isVideoEnabled && call.currentParams.videoDirection != MediaDirection.Inactive scope.launch { val type = if (videoEnabled) { CallAttributesCompat.CALL_TYPE_VIDEO_CALL diff --git a/app/src/main/java/org/linphone/telecom/TelecomManager.kt b/app/src/main/java/org/linphone/telecom/TelecomManager.kt index 1f61161f4..d87f6765f 100644 --- a/app/src/main/java/org/linphone/telecom/TelecomManager.kt +++ b/app/src/main/java/org/linphone/telecom/TelecomManager.kt @@ -33,6 +33,7 @@ import org.linphone.core.AudioDevice import org.linphone.core.Call import org.linphone.core.Core import org.linphone.core.CoreListenerStub +import org.linphone.core.MediaDirection import org.linphone.core.tools.Log import org.linphone.utils.LinphoneUtils @@ -55,17 +56,26 @@ class TelecomManager @WorkerThread constructor(context: Context) { val address = call.remoteAddress val friend = coreContext.contactsManager.findContactByAddress(address) val displayName = friend?.name ?: LinphoneUtils.getDisplayName(address) + val uri = Uri.parse(address.asStringUriOnly()) + val direction = if (call.dir == Call.Dir.Outgoing) { CallAttributesCompat.DIRECTION_OUTGOING } else { CallAttributesCompat.DIRECTION_INCOMING } - val type = if (core.isVideoEnabled) { + + val params = if (call.dir == Call.Dir.Outgoing) { + call.params + } else { + call.remoteParams + } + val type = if (params?.isVideoEnabled == true && params.videoDirection != MediaDirection.Inactive) { CallAttributesCompat.CALL_TYPE_VIDEO_CALL } else { CallAttributesCompat.CALL_TYPE_AUDIO_CALL } + val capabilities = CallAttributesCompat.SUPPORTS_SET_INACTIVE or CallAttributesCompat.SUPPORTS_TRANSFER val callAttributes = CallAttributesCompat( @@ -138,9 +148,13 @@ class TelecomManager @WorkerThread constructor(context: Context) { init { callsManager.registerAppWithTelecom( - CallsManager.Companion.CAPABILITY_SUPPORTS_VIDEO_CALLING + CallsManager.CAPABILITY_BASELINE or + CallsManager.Companion.CAPABILITY_SUPPORTS_VIDEO_CALLING + ) + val hasTelecomFeature = context.packageManager.hasSystemFeature("android.software.telecom") + Log.i( + "$TAG App has been registered with Telecom, android.software.telecom feature is [${if (hasTelecomFeature) "available" else "not available"}]" ) - Log.i("$TAG App has been registered with Telecom") } @WorkerThread