Prevent outgoing calls to be routed on speaker while ringing

This commit is contained in:
Sylvain Berfini 2024-12-16 14:36:52 +01:00
parent 3fb5d8a97b
commit 967fb0563d
5 changed files with 48 additions and 25 deletions

View file

@ -1038,13 +1038,8 @@ class NotificationsManager
val answerIntent = getCallAnswerPendingIntent(notifiable) val answerIntent = getCallAnswerPendingIntent(notifiable)
val remoteAddress = call.callLog.remoteAddress val remoteAddress = call.callLog.remoteAddress
val remoteContactAddress = call.remoteContactAddress
val conferenceInfo = if (remoteContactAddress != null) {
call.core.findConferenceInformationFromUri(remoteContactAddress) ?: call.callLog.conferenceInfo
} else {
call.callLog.conferenceInfo
}
val conference = call.conference val conference = call.conference
val conferenceInfo = LinphoneUtils.getConferenceInfoIfAny(call)
val isConference = conference != null || conferenceInfo != null val isConference = conference != null || conferenceInfo != null
val caller = if (isConference) { val caller = if (isConference) {
@ -1066,13 +1061,7 @@ class NotificationsManager
getPerson(contact, displayName) getPerson(contact, displayName)
} }
val isVideo = if (isConference) { val isVideo = LinphoneUtils.isVideoEnabled(call)
true
} else if (isIncoming) {
call.remoteParams?.isVideoEnabled == true && call.remoteParams?.videoDirection != MediaDirection.Inactive
} else {
call.currentParams.isVideoEnabled && call.currentParams.videoDirection != MediaDirection.Inactive
}
val smallIcon = if (isConference) { val smallIcon = if (isConference) {
R.drawable.video_conference R.drawable.video_conference

View file

@ -58,8 +58,14 @@ class TelecomCallControlCallback(
if (state == Call.State.Connected) { if (state == Call.State.Connected) {
if (call.dir == Call.Dir.Incoming) { if (call.dir == Call.Dir.Incoming) {
scope.launch { scope.launch {
Log.i("$TAG Answering call") val isVideo = LinphoneUtils.isVideoEnabled(call)
callControl.answer(CallAttributesCompat.CALL_TYPE_AUDIO_CALL) Log.i("$TAG Answering ${if (isVideo) "video" else "audio"} call")
val type = if (isVideo) {
CallAttributesCompat.Companion.CALL_TYPE_VIDEO_CALL
} else {
CallAttributesCompat.Companion.CALL_TYPE_AUDIO_CALL
}
callControl.answer(type)
} }
} else { } else {
scope.launch { scope.launch {

View file

@ -91,9 +91,6 @@ class TelecomManager
Log.i("$TAG Call to [${call.remoteAddress.asStringUriOnly()}] created") Log.i("$TAG Call to [${call.remoteAddress.asStringUriOnly()}] created")
val address = call.callLog.remoteAddress val address = call.callLog.remoteAddress
val friend = coreContext.contactsManager.findContactByAddress(address)
val displayName = friend?.name ?: LinphoneUtils.getDisplayName(address)
val uri = Uri.parse(address.asStringUriOnly()) val uri = Uri.parse(address.asStringUriOnly())
val direction = if (call.dir == Call.Dir.Outgoing) { val direction = if (call.dir == Call.Dir.Outgoing) {
@ -102,9 +99,19 @@ class TelecomManager
CallAttributesCompat.DIRECTION_INCOMING CallAttributesCompat.DIRECTION_INCOMING
} }
val type = CallAttributesCompat.CALL_TYPE_AUDIO_CALL or CallAttributesCompat.CALL_TYPE_VIDEO_CALL val conferenceInfo = LinphoneUtils.getConferenceInfoIfAny(call)
val capabilities = CallAttributesCompat.SUPPORTS_SET_INACTIVE or CallAttributesCompat.SUPPORTS_TRANSFER val capabilities = CallAttributesCompat.SUPPORTS_SET_INACTIVE or CallAttributesCompat.SUPPORTS_TRANSFER
val displayName = if (call.conference != null || conferenceInfo != null) {
conferenceInfo?.subject ?: call.conference?.subject ?: LinphoneUtils.getDisplayName(address)
} else {
val friend = coreContext.contactsManager.findContactByAddress(address)
friend?.name ?: LinphoneUtils.getDisplayName(address)
}
// When call is created, it is ringing (incoming or outgoing, do not set video)
val type = CallAttributesCompat.Companion.CALL_TYPE_AUDIO_CALL
val callAttributes = CallAttributesCompat( val callAttributes = CallAttributesCompat(
displayName, displayName,
uri, uri,

View file

@ -1064,12 +1064,7 @@ class CurrentCallViewModel
updateEncryption() updateEncryption()
} }
val remoteContactAddress = call.remoteContactAddress val conferenceInfo = LinphoneUtils.getConferenceInfoIfAny(call)
val conferenceInfo = if (remoteContactAddress != null) {
call.core.findConferenceInformationFromUri(remoteContactAddress)
} else {
call.callLog.conferenceInfo
}
if (call.conference != null || conferenceInfo != null) { if (call.conference != null || conferenceInfo != null) {
val subject = call.conference?.subject ?: conferenceInfo?.subject val subject = call.conference?.subject ?: conferenceInfo?.subject
Log.i("$TAG Conference [$subject] found, going to conference fragment") Log.i("$TAG Conference [$subject] found, going to conference fragment")

View file

@ -48,6 +48,7 @@ import org.linphone.core.ConferenceScheduler
import org.linphone.core.Core import org.linphone.core.Core
import org.linphone.core.Factory import org.linphone.core.Factory
import org.linphone.core.Friend import org.linphone.core.Friend
import org.linphone.core.MediaDirection
import org.linphone.core.Reason import org.linphone.core.Reason
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
import org.linphone.ui.main.contacts.model.ContactAvatarModel import org.linphone.ui.main.contacts.model.ContactAvatarModel
@ -216,6 +217,31 @@ class LinphoneUtils {
return core.defaultAccount?.params?.audioVideoConferenceFactoryAddress != null return core.defaultAccount?.params?.audioVideoConferenceFactoryAddress != null
} }
@WorkerThread
fun isVideoEnabled(call: Call): Boolean {
val conference = call.conference
val isConference = conference != null
val isIncoming = isCallIncoming(call.state)
return if (isConference || getConferenceInfoIfAny(call) != null) {
true
} else if (isIncoming) {
call.remoteParams?.isVideoEnabled == true && call.remoteParams?.videoDirection != MediaDirection.Inactive
} else {
call.currentParams.isVideoEnabled && call.currentParams.videoDirection != MediaDirection.Inactive
}
}
@WorkerThread
fun getConferenceInfoIfAny(call: Call): ConferenceInfo? {
val remoteContactAddress = call.remoteContactAddress
return if (remoteContactAddress != null) {
call.core.findConferenceInformationFromUri(remoteContactAddress) ?: call.callLog.conferenceInfo
} else {
call.callLog.conferenceInfo
}
}
@WorkerThread @WorkerThread
fun createConferenceScheduler(account: Account?): ConferenceScheduler { fun createConferenceScheduler(account: Account?): ConferenceScheduler {
if (!account?.params?.ccmpServerUrl.isNullOrEmpty()) { if (!account?.params?.ccmpServerUrl.isNullOrEmpty()) {