Prevent creating Telecom Manager Connection after a call has ended
This commit is contained in:
parent
68152b5b3e
commit
6454a368b2
2 changed files with 36 additions and 15 deletions
|
@ -23,6 +23,7 @@ import android.graphics.drawable.Icon
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.telecom.CallAudioState
|
import android.telecom.CallAudioState
|
||||||
import android.telecom.Connection
|
import android.telecom.Connection
|
||||||
|
import android.telecom.DisconnectCause
|
||||||
import android.telecom.StatusHints
|
import android.telecom.StatusHints
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
@ -49,18 +50,18 @@ class NativeCallWrapper(var callId: String) : Connection() {
|
||||||
|
|
||||||
override fun onAnswer(videoState: Int) {
|
override fun onAnswer(videoState: Int) {
|
||||||
Log.i("[Connection] Answering telecom call with id: $callId")
|
Log.i("[Connection] Answering telecom call with id: $callId")
|
||||||
getCall()?.accept()
|
getCall()?.accept() ?: selfDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onHold() {
|
override fun onHold() {
|
||||||
Log.i("[Connection] Pausing telecom call with id: $callId")
|
Log.i("[Connection] Pausing telecom call with id: $callId")
|
||||||
getCall()?.pause()
|
getCall()?.pause() ?: selfDestroy()
|
||||||
setOnHold()
|
setOnHold()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUnhold() {
|
override fun onUnhold() {
|
||||||
Log.i("[Connection] Resuming telecom call with id: $callId")
|
Log.i("[Connection] Resuming telecom call with id: $callId")
|
||||||
getCall()?.resume()
|
getCall()?.resume() ?: selfDestroy()
|
||||||
setActive()
|
setActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,36 +69,48 @@ class NativeCallWrapper(var callId: String) : Connection() {
|
||||||
Log.i("[Connection] Audio state changed: $state")
|
Log.i("[Connection] Audio state changed: $state")
|
||||||
|
|
||||||
val call = getCall()
|
val call = getCall()
|
||||||
call?.microphoneMuted = state.isMuted
|
if (call != null) {
|
||||||
when (state.route) {
|
call.microphoneMuted = state.isMuted
|
||||||
CallAudioState.ROUTE_EARPIECE -> AudioRouteUtils.routeAudioToEarpiece(call)
|
when (state.route) {
|
||||||
CallAudioState.ROUTE_SPEAKER -> AudioRouteUtils.routeAudioToSpeaker(call)
|
CallAudioState.ROUTE_EARPIECE -> AudioRouteUtils.routeAudioToEarpiece(call)
|
||||||
CallAudioState.ROUTE_BLUETOOTH -> AudioRouteUtils.routeAudioToBluetooth(call)
|
CallAudioState.ROUTE_SPEAKER -> AudioRouteUtils.routeAudioToSpeaker(call)
|
||||||
CallAudioState.ROUTE_WIRED_HEADSET -> AudioRouteUtils.routeAudioToHeadset(call)
|
CallAudioState.ROUTE_BLUETOOTH -> AudioRouteUtils.routeAudioToBluetooth(call)
|
||||||
|
CallAudioState.ROUTE_WIRED_HEADSET -> AudioRouteUtils.routeAudioToHeadset(call)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selfDestroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlayDtmfTone(c: Char) {
|
override fun onPlayDtmfTone(c: Char) {
|
||||||
Log.i("[Connection] Sending DTMF [$c] in telecom call with id: $callId")
|
Log.i("[Connection] Sending DTMF [$c] in telecom call with id: $callId")
|
||||||
getCall()?.sendDtmf(c)
|
getCall()?.sendDtmf(c) ?: selfDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisconnect() {
|
override fun onDisconnect() {
|
||||||
Log.i("[Connection] Terminating telecom call with id: $callId")
|
Log.i("[Connection] Terminating telecom call with id: $callId")
|
||||||
getCall()?.terminate()
|
getCall()?.terminate() ?: selfDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAbort() {
|
override fun onAbort() {
|
||||||
Log.i("[Connection] Aborting telecom call with id: $callId")
|
Log.i("[Connection] Aborting telecom call with id: $callId")
|
||||||
getCall()?.terminate()
|
getCall()?.terminate() ?: selfDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReject() {
|
override fun onReject() {
|
||||||
Log.i("[Connection] Rejecting telecom call with id: $callId")
|
Log.i("[Connection] Rejecting telecom call with id: $callId")
|
||||||
getCall()?.terminate()
|
getCall()?.terminate() ?: selfDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCall(): Call? {
|
private fun getCall(): Call? {
|
||||||
return coreContext.core.getCallByCallid(callId)
|
return coreContext.core.getCallByCallid(callId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selfDestroy() {
|
||||||
|
if (coreContext.core.callsNb == 0) {
|
||||||
|
Log.e("[Connection] No call in Core, destroy connection")
|
||||||
|
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
||||||
|
destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,13 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
connectionManagerPhoneAccount: PhoneAccountHandle,
|
connectionManagerPhoneAccount: PhoneAccountHandle,
|
||||||
request: ConnectionRequest
|
request: ConnectionRequest
|
||||||
): Connection {
|
): Connection {
|
||||||
|
if (coreContext.core.callsNb == 0) {
|
||||||
|
Log.w("[Telecom Connection Service] No call in Core, aborting outgoing connection!")
|
||||||
|
return Connection.createCanceledConnection()
|
||||||
|
}
|
||||||
|
|
||||||
val accountHandle = request.accountHandle
|
val accountHandle = request.accountHandle
|
||||||
val componentName = ComponentName(applicationContext, this.javaClass)
|
val componentName = ComponentName(applicationContext, this.javaClass)
|
||||||
|
|
||||||
return if (accountHandle != null && componentName == accountHandle.componentName) {
|
return if (accountHandle != null && componentName == accountHandle.componentName) {
|
||||||
Log.i("[Telecom Connection Service] Creating outgoing connection")
|
Log.i("[Telecom Connection Service] Creating outgoing connection")
|
||||||
|
|
||||||
|
@ -118,9 +122,13 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
connectionManagerPhoneAccount: PhoneAccountHandle,
|
connectionManagerPhoneAccount: PhoneAccountHandle,
|
||||||
request: ConnectionRequest
|
request: ConnectionRequest
|
||||||
): Connection {
|
): Connection {
|
||||||
|
if (coreContext.core.callsNb == 0) {
|
||||||
|
Log.w("[Telecom Connection Service] No call in Core, aborting incoming connection!")
|
||||||
|
return Connection.createCanceledConnection()
|
||||||
|
}
|
||||||
|
|
||||||
val accountHandle = request.accountHandle
|
val accountHandle = request.accountHandle
|
||||||
val componentName = ComponentName(applicationContext, this.javaClass)
|
val componentName = ComponentName(applicationContext, this.javaClass)
|
||||||
|
|
||||||
return if (accountHandle != null && componentName == accountHandle.componentName) {
|
return if (accountHandle != null && componentName == accountHandle.componentName) {
|
||||||
Log.i("[Telecom Connection Service] Creating incoming connection")
|
Log.i("[Telecom Connection Service] Creating incoming connection")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue