Clean up zombie TelecomManager connections if any
This commit is contained in:
parent
d14fce09fc
commit
a0a39b3884
1 changed files with 32 additions and 7 deletions
|
@ -42,6 +42,7 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
Call.State.OutgoingProgress -> {
|
Call.State.OutgoingProgress -> {
|
||||||
for (connection in TelecomHelper.get().connections) {
|
for (connection in TelecomHelper.get().connections) {
|
||||||
if (connection.callId.isEmpty()) {
|
if (connection.callId.isEmpty()) {
|
||||||
|
Log.i("[Telecom Connection Service] Updating connection with call ID: ${call.callLog.callId}")
|
||||||
connection.callId = core.currentCall?.callLog?.callId ?: ""
|
connection.callId = core.currentCall?.callLog?.callId ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +52,18 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
Call.State.Connected -> onCallConnected(call)
|
Call.State.Connected -> onCallConnected(call)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLastCallEnded(core: Core) {
|
||||||
|
val connectionsCount = TelecomHelper.get().connections.size
|
||||||
|
if (connectionsCount > 0) {
|
||||||
|
Log.w("[Telecom Connection Service] Last call ended, there is $connectionsCount connections still alive")
|
||||||
|
for (connection in TelecomHelper.get().connections) {
|
||||||
|
Log.w("[Telecom Connection Service] Destroying zombie connection ${connection.callId}")
|
||||||
|
connection.setDisconnected(DisconnectCause(DisconnectCause.OTHER))
|
||||||
|
connection.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
@ -162,8 +175,12 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCallError(call: Call) {
|
private fun onCallError(call: Call) {
|
||||||
val connection = TelecomHelper.get().findConnectionForCallId(call.callLog.callId)
|
val callId = call.callLog.callId
|
||||||
connection ?: return
|
val connection = TelecomHelper.get().findConnectionForCallId(callId)
|
||||||
|
if (connection == null) {
|
||||||
|
Log.e("[Telecom Connection Service] Failed to find connection for call id: $callId")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
TelecomHelper.get().connections.remove(connection)
|
TelecomHelper.get().connections.remove(connection)
|
||||||
connection.setDisconnected(DisconnectCause(DisconnectCause.ERROR))
|
connection.setDisconnected(DisconnectCause(DisconnectCause.ERROR))
|
||||||
|
@ -171,19 +188,27 @@ class TelecomConnectionService : ConnectionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCallEnded(call: Call) {
|
private fun onCallEnded(call: Call) {
|
||||||
val connection = TelecomHelper.get().findConnectionForCallId(call.callLog.callId)
|
val callId = call.callLog.callId
|
||||||
connection ?: return
|
val connection = TelecomHelper.get().findConnectionForCallId(callId)
|
||||||
|
if (connection == null) {
|
||||||
|
Log.e("[Telecom Connection Service] Failed to find connection for call id: $callId")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
TelecomHelper.get().connections.remove(connection)
|
TelecomHelper.get().connections.remove(connection)
|
||||||
val reason = call.reason
|
val reason = call.reason
|
||||||
Log.i("[Telecom Connection Service] Call ended with reason: $reason")
|
Log.i("[Telecom Connection Service] Call [$callId] ended with reason: $reason, destroying connection")
|
||||||
connection.setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
connection.setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
|
||||||
connection.destroy()
|
connection.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCallConnected(call: Call) {
|
private fun onCallConnected(call: Call) {
|
||||||
val connection = TelecomHelper.get().findConnectionForCallId(call.callLog.callId)
|
val callId = call.callLog.callId
|
||||||
connection ?: return
|
val connection = TelecomHelper.get().findConnectionForCallId(callId)
|
||||||
|
if (connection == null) {
|
||||||
|
Log.e("[Telecom Connection Service] Failed to find connection for call id: $callId")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (connection.state != Connection.STATE_HOLDING) {
|
if (connection.state != Connection.STATE_HOLDING) {
|
||||||
connection.setActive()
|
connection.setActive()
|
||||||
|
|
Loading…
Reference in a new issue