ConnectionService: handle connection events on the main thread
Not handling these events on the main thread could leave the connection in an inconsistent state.
This commit is contained in:
parent
d8d49e03a0
commit
5e39d45d9a
|
@ -11,6 +11,8 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.telecom.CallAudioState;
|
||||
import android.telecom.Connection;
|
||||
import android.telecom.ConnectionRequest;
|
||||
|
@ -54,6 +56,8 @@ import eu.siacs.conversations.xmpp.jingle.Media;
|
|||
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
||||
|
||||
public class ConnectionService extends android.telecom.ConnectionService {
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public XmppConnectionService xmppConnectionService = null;
|
||||
protected ServiceConnection mConnection = new ServiceConnection() {
|
||||
@Override
|
||||
|
@ -271,18 +275,24 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
|||
// so we have to acquire the rtp connection object here
|
||||
this.rtpConnection = xmppConnectionService.getJingleConnectionManager().findJingleRtpConnection(account, with, sessionId);
|
||||
|
||||
mHandler.post(() -> {
|
||||
rtpConnection.get().acceptCall();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReject() {
|
||||
this.rtpConnection = xmppConnectionService.getJingleConnectionManager().findJingleRtpConnection(account, with, sessionId);
|
||||
|
||||
mHandler.post(() -> {
|
||||
rtpConnection.get().rejectCall();
|
||||
setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect() {
|
||||
mHandler.post(() -> {
|
||||
if (rtpConnection == null || rtpConnection.get() == null) {
|
||||
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
|
||||
} else {
|
||||
|
@ -293,6 +303,7 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
|||
xmppConnectionService.removeRtpConnectionUpdateListener(
|
||||
(XmppConnectionService.OnJingleRtpConnectionUpdate) this
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -302,7 +313,9 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
|||
|
||||
@Override
|
||||
public void onPlayDtmfTone(char c) {
|
||||
mHandler.post(() -> {
|
||||
rtpConnection.get().applyDtmfTone("" + c);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue