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:
parent
db8b6f2dfb
commit
a230f603c6
3 changed files with 33 additions and 9 deletions
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.telecom
|
package org.linphone.telecom
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.telecom.CallAudioState
|
import android.telecom.CallAudioState
|
||||||
|
@ -31,10 +32,15 @@ import org.linphone.core.Call
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.AudioRouteUtils
|
import org.linphone.utils.AudioRouteUtils
|
||||||
|
|
||||||
|
@TargetApi(29)
|
||||||
class NativeCallWrapper(var callId: String) : Connection() {
|
class NativeCallWrapper(var callId: String) : Connection() {
|
||||||
init {
|
init {
|
||||||
|
val properties = connectionProperties or PROPERTY_SELF_MANAGED
|
||||||
|
connectionProperties = properties
|
||||||
|
|
||||||
val capabilities = connectionCapabilities or CAPABILITY_MUTE or CAPABILITY_SUPPORT_HOLD or CAPABILITY_HOLD
|
val capabilities = connectionCapabilities or CAPABILITY_MUTE or CAPABILITY_SUPPORT_HOLD or CAPABILITY_HOLD
|
||||||
connectionCapabilities = capabilities
|
connectionCapabilities = capabilities
|
||||||
|
|
||||||
audioModeIsVoip = true
|
audioModeIsVoip = true
|
||||||
statusHints = StatusHints(
|
statusHints = StatusHints(
|
||||||
"",
|
"",
|
||||||
|
@ -119,6 +125,10 @@ class NativeCallWrapper(var callId: String) : Connection() {
|
||||||
coreContext.core.stopRinging()
|
coreContext.core.stopRinging()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun stateAsString(): String {
|
||||||
|
return intStateToString(state)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getCall(): Call? {
|
private fun getCall(): Call? {
|
||||||
return coreContext.core.getCallByCallid(callId)
|
return coreContext.core.getCallByCallid(callId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.telecom
|
package org.linphone.telecom
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -31,6 +32,7 @@ import org.linphone.core.Core
|
||||||
import org.linphone.core.CoreListenerStub
|
import org.linphone.core.CoreListenerStub
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
|
||||||
|
@TargetApi(29)
|
||||||
class TelecomConnectionService : ConnectionService() {
|
class TelecomConnectionService : ConnectionService() {
|
||||||
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||||
override fun onCallStateChanged(
|
override fun onCallStateChanged(
|
||||||
|
@ -51,7 +53,8 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
Call.State.Error -> onCallError(call)
|
Call.State.Error -> onCallError(call)
|
||||||
Call.State.End, Call.State.Released -> onCallEnded(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 -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +90,7 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOutgoingConnection(
|
override fun onCreateOutgoingConnection(
|
||||||
connectionManagerPhoneAccount: PhoneAccountHandle,
|
connectionManagerPhoneAccount: PhoneAccountHandle?,
|
||||||
request: ConnectionRequest
|
request: ConnectionRequest
|
||||||
): Connection {
|
): Connection {
|
||||||
if (coreContext.core.callsNb == 0) {
|
if (coreContext.core.callsNb == 0) {
|
||||||
|
@ -149,7 +152,7 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateIncomingConnection(
|
override fun onCreateIncomingConnection(
|
||||||
connectionManagerPhoneAccount: PhoneAccountHandle,
|
connectionManagerPhoneAccount: PhoneAccountHandle?,
|
||||||
request: ConnectionRequest
|
request: ConnectionRequest
|
||||||
): Connection {
|
): Connection {
|
||||||
if (coreContext.core.callsNb == 0) {
|
if (coreContext.core.callsNb == 0) {
|
||||||
|
@ -215,6 +218,7 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TelecomHelper.get().connections.remove(connection)
|
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.setDisconnected(DisconnectCause(DisconnectCause.ERROR))
|
||||||
connection.destroy()
|
connection.destroy()
|
||||||
}
|
}
|
||||||
|
@ -229,11 +233,22 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
|
|
||||||
TelecomHelper.get().connections.remove(connection)
|
TelecomHelper.get().connections.remove(connection)
|
||||||
val reason = call.reason
|
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.setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
||||||
connection.destroy()
|
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) {
|
private fun onCallConnected(call: Call) {
|
||||||
val callId = call.callLog.callId
|
val callId = call.callLog.callId
|
||||||
val connection = TelecomHelper.get().findConnectionForCallId(callId.orEmpty())
|
val connection = TelecomHelper.get().findConnectionForCallId(callId.orEmpty())
|
||||||
|
@ -242,8 +257,7 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection.state != Connection.STATE_HOLDING) {
|
Log.i("[Telecom Connection Service] Setting connection as active, currently in ${connection.stateAsString()}")
|
||||||
connection.setActive()
|
connection.setActive()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ class TelecomHelper private constructor(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onIncomingCall(call: Call) {
|
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)
|
val extras = prepareBundle(call)
|
||||||
telecomManager.addNewIncomingCall(
|
telecomManager.addNewIncomingCall(
|
||||||
|
@ -206,7 +206,7 @@ class TelecomHelper private constructor(context: Context) {
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun onOutgoingCall(call: Call) {
|
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)
|
val extras = prepareBundle(call)
|
||||||
telecomManager.placeCall(
|
telecomManager.placeCall(
|
||||||
|
|
Loading…
Reference in a new issue