Improvements on use of Telecom Manager APIs to prevent dialog asking to terminate call when trying to add a new call to an existing conference

This commit is contained in:
Sylvain Berfini 2022-10-05 16:16:47 +02:00
parent db8b6f2dfb
commit a230f603c6
3 changed files with 33 additions and 9 deletions

View file

@ -19,6 +19,7 @@
*/
package org.linphone.telecom
import android.annotation.TargetApi
import android.graphics.drawable.Icon
import android.os.Bundle
import android.telecom.CallAudioState
@ -31,10 +32,15 @@ import org.linphone.core.Call
import org.linphone.core.tools.Log
import org.linphone.utils.AudioRouteUtils
@TargetApi(29)
class NativeCallWrapper(var callId: String) : Connection() {
init {
val properties = connectionProperties or PROPERTY_SELF_MANAGED
connectionProperties = properties
val capabilities = connectionCapabilities or CAPABILITY_MUTE or CAPABILITY_SUPPORT_HOLD or CAPABILITY_HOLD
connectionCapabilities = capabilities
audioModeIsVoip = true
statusHints = StatusHints(
"",
@ -119,6 +125,10 @@ class NativeCallWrapper(var callId: String) : Connection() {
coreContext.core.stopRinging()
}
fun stateAsString(): String {
return intStateToString(state)
}
private fun getCall(): Call? {
return coreContext.core.getCallByCallid(callId)
}

View file

@ -19,6 +19,7 @@
*/
package org.linphone.telecom
import android.annotation.TargetApi
import android.content.ComponentName
import android.content.Intent
import android.net.Uri
@ -31,6 +32,7 @@ import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
@TargetApi(29)
class TelecomConnectionService : ConnectionService() {
private val listener: CoreListenerStub = object : CoreListenerStub() {
override fun onCallStateChanged(
@ -51,7 +53,8 @@ class TelecomConnectionService : ConnectionService() {
}
Call.State.Error -> onCallError(call)
Call.State.End, Call.State.Released -> onCallEnded(call)
Call.State.Connected -> onCallConnected(call)
Call.State.Paused, Call.State.Pausing, Call.State.PausedByRemote -> onCallPaused(call)
Call.State.Connected, Call.State.StreamsRunning -> onCallConnected(call)
else -> {}
}
}
@ -87,7 +90,7 @@ class TelecomConnectionService : ConnectionService() {
}
override fun onCreateOutgoingConnection(
connectionManagerPhoneAccount: PhoneAccountHandle,
connectionManagerPhoneAccount: PhoneAccountHandle?,
request: ConnectionRequest
): Connection {
if (coreContext.core.callsNb == 0) {
@ -149,7 +152,7 @@ class TelecomConnectionService : ConnectionService() {
}
override fun onCreateIncomingConnection(
connectionManagerPhoneAccount: PhoneAccountHandle,
connectionManagerPhoneAccount: PhoneAccountHandle?,
request: ConnectionRequest
): Connection {
if (coreContext.core.callsNb == 0) {
@ -215,6 +218,7 @@ class TelecomConnectionService : ConnectionService() {
}
TelecomHelper.get().connections.remove(connection)
Log.i("[Telecom Connection Service] Call [$callId] is in error, destroying connection currently in ${connection.stateAsString()}")
connection.setDisconnected(DisconnectCause(DisconnectCause.ERROR))
connection.destroy()
}
@ -229,11 +233,22 @@ class TelecomConnectionService : ConnectionService() {
TelecomHelper.get().connections.remove(connection)
val reason = call.reason
Log.i("[Telecom Connection Service] Call [$callId] ended with reason: $reason, destroying connection")
Log.i("[Telecom Connection Service] Call [$callId] ended with reason: $reason, destroying connection currently in ${connection.stateAsString()}")
connection.setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
connection.destroy()
}
private fun onCallPaused(call: Call) {
val callId = call.callLog.callId
val connection = TelecomHelper.get().findConnectionForCallId(callId.orEmpty())
if (connection == null) {
Log.e("[Telecom Connection Service] Failed to find connection for call id: $callId")
return
}
Log.i("[Telecom Connection Service] Setting connection as on hold, currently in ${connection.stateAsString()}")
connection.setOnHold()
}
private fun onCallConnected(call: Call) {
val callId = call.callLog.callId
val connection = TelecomHelper.get().findConnectionForCallId(callId.orEmpty())
@ -242,8 +257,7 @@ class TelecomConnectionService : ConnectionService() {
return
}
if (connection.state != Connection.STATE_HOLDING) {
connection.setActive()
}
Log.i("[Telecom Connection Service] Setting connection as active, currently in ${connection.stateAsString()}")
connection.setActive()
}
}

View file

@ -192,7 +192,7 @@ class TelecomHelper private constructor(context: Context) {
}
private fun onIncomingCall(call: Call) {
Log.i("[Telecom Helper] Incoming call received from ${call.remoteAddress.asStringUriOnly()}")
Log.i("[Telecom Helper] Incoming call received from ${call.remoteAddress.asStringUriOnly()}, using account handle ${account.accountHandle}")
val extras = prepareBundle(call)
telecomManager.addNewIncomingCall(
@ -206,7 +206,7 @@ class TelecomHelper private constructor(context: Context) {
@SuppressLint("MissingPermission")
private fun onOutgoingCall(call: Call) {
Log.i("[Telecom Helper] Outgoing call started to ${call.remoteAddress.asStringUriOnly()}")
Log.i("[Telecom Helper] Outgoing call started to ${call.remoteAddress.asStringUriOnly()}, using account handle ${account.accountHandle}")
val extras = prepareBundle(call)
telecomManager.placeCall(