diff --git a/app/src/main/java/org/linphone/telecom/TelecomConnectionService.kt b/app/src/main/java/org/linphone/telecom/TelecomConnectionService.kt index b74aea297..c983af135 100644 --- a/app/src/main/java/org/linphone/telecom/TelecomConnectionService.kt +++ b/app/src/main/java/org/linphone/telecom/TelecomConnectionService.kt @@ -109,7 +109,20 @@ class TelecomConnectionService : ConnectionService() { } val connection = NativeCallWrapper(callId) - connection.setDialing() + val call = coreContext.core.calls.find { it.callLog.callId == callId } + if (call != null) { + val callState = call.state + Log.i("[Telecom Connection Service] Found outgoing call from ID [$callId] with state [$callState]") + when (callState) { + Call.State.OutgoingEarlyMedia, Call.State.OutgoingInit, Call.State.OutgoingProgress, Call.State.OutgoingRinging -> connection.setDialing() + Call.State.Paused, Call.State.PausedByRemote, Call.State.Pausing -> connection.setOnHold() + Call.State.End, Call.State.Error, Call.State.Released -> connection.setDisconnected(DisconnectCause(DisconnectCause.ERROR)) + else -> connection.setActive() + } + } else { + Log.w("[Telecom Connection Service] Outgoing call not found for cal ID [$callId], assuming it's state is dialing") + connection.setDialing() + } val providedHandle = request.address connection.setAddress(providedHandle, TelecomManager.PRESENTATION_ALLOWED) @@ -153,7 +166,20 @@ class TelecomConnectionService : ConnectionService() { Log.i("[Telecom Connection Service] Incoming connection is for call [$callId] with display name [$displayName]") val connection = NativeCallWrapper(callId) - connection.setRinging() + val call = coreContext.core.calls.find { it.callLog.callId == callId } + if (call != null) { + val callState = call.state + Log.i("[Telecom Connection Service] Found incoming call from ID [$callId] with state [$callState]") + when (callState) { + Call.State.IncomingEarlyMedia, Call.State.IncomingReceived -> connection.setRinging() + Call.State.Paused, Call.State.PausedByRemote, Call.State.Pausing -> connection.setOnHold() + Call.State.End, Call.State.Error, Call.State.Released -> connection.setDisconnected(DisconnectCause(DisconnectCause.ERROR)) + else -> connection.setActive() + } + } else { + Log.w("[Telecom Connection Service] Incoming call not found for cal ID [$callId], assuming it's state is ringing") + connection.setRinging() + } val providedHandle = incomingExtras?.getParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS)