From 259b0e69ad1175b7e099d29e2e9eaae486703b6a Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 12 Mar 2022 21:38:12 -0500 Subject: [PATCH] ConnectionService: handle disconnection correctly onDisconnect() is only called when the user *requests* to hang up. If the state is changed by setDisconnected(), then only onStateChanged() will be called. Handle this correctly, otherwise the connection state could be inconsistent (e.g. call is ended by the other side but the Connection object is still around) --- .../cheogram/android/ConnectionService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cheogram/java/com/cheogram/android/ConnectionService.java b/src/cheogram/java/com/cheogram/android/ConnectionService.java index c66889a47..c46560caa 100644 --- a/src/cheogram/java/com/cheogram/android/ConnectionService.java +++ b/src/cheogram/java/com/cheogram/android/ConnectionService.java @@ -290,6 +290,17 @@ public class ConnectionService extends android.telecom.ConnectionService { }); } + @Override + public void onStateChanged(int state) { + if (state == STATE_DISCONNECTED) { + mHandler.post(() -> { + destroy(); + xmppConnectionService.setDiallerIntegrationActive(false); + xmppConnectionService.removeRtpConnectionUpdateListener(this); + }); + } + } + @Override public void onDisconnect() { mHandler.post(() -> { @@ -298,11 +309,8 @@ public class ConnectionService extends android.telecom.ConnectionService { } else { rtpConnection.get().endCall(); } - destroy(); - xmppConnectionService.setDiallerIntegrationActive(false); - xmppConnectionService.removeRtpConnectionUpdateListener( - (XmppConnectionService.OnJingleRtpConnectionUpdate) this - ); + + setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); }); }