From 17a1fe97ca19d62461990c4ec65951daf7e189a6 Mon Sep 17 00:00:00 2001 From: Curt Brune Date: Tue, 5 Nov 2019 21:44:32 -0800 Subject: [PATCH] Send hangup message when terminating on call errors. When errors occur during a call, attempt to send the remote peer a hangup message before terminating the call. This allows the remote peer to shutdown their side of the call in a timely manner. --- .../securesms/service/WebRtcCallService.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java index 4082afea33..c136fc82e9 100644 --- a/src/org/thoughtcrime/securesms/service/WebRtcCallService.java +++ b/src/org/thoughtcrime/securesms/service/WebRtcCallService.java @@ -464,7 +464,7 @@ public class WebRtcCallService extends Service implements CallConnection.Observe } catch (CallException e) { Log.w(TAG, e); sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled); - terminate(); + hangupAndTerminate(); } } @@ -549,7 +549,7 @@ public class WebRtcCallService extends Service implements CallConnection.Observe } catch (CallException e) { Log.w(TAG, e); sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled); - terminate(); + hangupAndTerminate(); } } @@ -672,13 +672,13 @@ public class WebRtcCallService extends Service implements CallConnection.Observe intent.putExtra(EXTRA_CALL_ID, callId); intent.putExtra(EXTRA_REMOTE_RECIPIENT, recipient.getId()); handleCallConnected(intent); + activateCallMedia(); } catch (CallException e) { Log.w(TAG, e); sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled); - terminate(); + hangupAndTerminate(); } - activateCallMedia(); } private void handleDenyCall(Intent intent) { @@ -770,7 +770,8 @@ public class WebRtcCallService extends Service implements CallConnection.Observe } catch (CallException e) { Log.w(TAG, e); sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled); - terminate(); + hangupAndTerminate(); + return; } } @@ -890,7 +891,7 @@ public class WebRtcCallService extends Service implements CallConnection.Observe sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled); break; } - terminate(); + hangupAndTerminate(); } @@ -934,6 +935,22 @@ public class WebRtcCallService extends Service implements CallConnection.Observe CallNotificationBuilder.getCallInProgressNotification(this, type, recipient)); } + private void hangupAndTerminate() { + if (callConnection != null && callId != null) { + accountManager.cancelInFlightRequests(); + messageSender.cancelInFlightRequests(); + + try { + callConnection.hangUp(); + } catch (CallException e) { + Log.w(TAG, e); + } + + } + + terminate(); + } + private synchronized void terminate() { Log.i(TAG, "terminate()");