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)
This commit is contained in:
Peter Cai 2022-03-12 21:38:12 -05:00
parent 5e39d45d9a
commit 259b0e69ad
1 changed files with 13 additions and 5 deletions

View File

@ -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));
});
}