Compare commits
4 commits
peter-dev
...
peter-dev-
Author | SHA1 | Date | |
---|---|---|---|
a50b50938e | |||
1f2420b38b | |||
259b0e69ad | |||
5e39d45d9a |
1 changed files with 40 additions and 23 deletions
|
@ -11,6 +11,8 @@ import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.telecom.CallAudioState;
|
import android.telecom.CallAudioState;
|
||||||
import android.telecom.Connection;
|
import android.telecom.Connection;
|
||||||
import android.telecom.ConnectionRequest;
|
import android.telecom.ConnectionRequest;
|
||||||
|
@ -54,6 +56,8 @@ import eu.siacs.conversations.xmpp.jingle.Media;
|
||||||
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
||||||
|
|
||||||
public class ConnectionService extends android.telecom.ConnectionService {
|
public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
public XmppConnectionService xmppConnectionService = null;
|
public XmppConnectionService xmppConnectionService = null;
|
||||||
protected ServiceConnection mConnection = new ServiceConnection() {
|
protected ServiceConnection mConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,7 +117,7 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
|
|
||||||
Account account = xmppConnectionService.findAccountByJid(Jid.of(gateway[0]));
|
Account account = xmppConnectionService.findAccountByJid(Jid.of(gateway[0]));
|
||||||
Jid with = Jid.ofLocalAndDomain(tel, gateway[1]);
|
Jid with = Jid.ofLocalAndDomain(tel, gateway[1]);
|
||||||
CheogramConnection connection = new CheogramConnection(account, with, postDial);
|
CheogramConnection connection = new CheogramConnection(account, with, postDial, null);
|
||||||
|
|
||||||
PermissionManager permissionManager = PermissionManager.getInstance(this);
|
PermissionManager permissionManager = PermissionManager.getInstance(this);
|
||||||
permissionManager.setNotificationSettings(
|
permissionManager.setNotificationSettings(
|
||||||
|
@ -163,7 +167,10 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
|
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
|
||||||
Jid with = Jid.of(withJid);
|
Jid with = Jid.of(withJid);
|
||||||
|
|
||||||
CheogramConnection connection = new CheogramConnection(account, with, null);
|
CheogramConnection connection = new CheogramConnection(
|
||||||
|
account, with, null,
|
||||||
|
xmppConnectionService.getJingleConnectionManager().findJingleRtpConnection(account, with, sessionId)
|
||||||
|
);
|
||||||
connection.setSessionId(sessionId);
|
connection.setSessionId(sessionId);
|
||||||
connection.setAddress(
|
connection.setAddress(
|
||||||
Uri.fromParts("tel", with.getLocal(), null),
|
Uri.fromParts("tel", with.getLocal(), null),
|
||||||
|
@ -182,12 +189,13 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
protected String sessionId = null;
|
protected String sessionId = null;
|
||||||
protected Stack<String> postDial = new Stack<>();
|
protected Stack<String> postDial = new Stack<>();
|
||||||
protected Icon gatewayIcon;
|
protected Icon gatewayIcon;
|
||||||
protected WeakReference<JingleRtpConnection> rtpConnection = null;
|
protected WeakReference<JingleRtpConnection> rtpConnection;
|
||||||
|
|
||||||
CheogramConnection(Account account, Jid with, String postDialString) {
|
CheogramConnection(Account account, Jid with, String postDialString, WeakReference<JingleRtpConnection> rtpConnection) {
|
||||||
super();
|
super();
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.with = with;
|
this.with = with;
|
||||||
|
this.rtpConnection = rtpConnection;
|
||||||
|
|
||||||
gatewayIcon = Icon.createWithBitmap(xmppConnectionService.getAvatarService().get(
|
gatewayIcon = Icon.createWithBitmap(xmppConnectionService.getAvatarService().get(
|
||||||
account.getRoster().getContact(Jid.of(with.getDomain())),
|
account.getRoster().getContact(Jid.of(with.getDomain())),
|
||||||
|
@ -267,32 +275,39 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnswer() {
|
public void onAnswer() {
|
||||||
// For incoming calls, a connection update may not have been triggered before answering
|
mHandler.post(() -> {
|
||||||
// so we have to acquire the rtp connection object here
|
|
||||||
this.rtpConnection = xmppConnectionService.getJingleConnectionManager().findJingleRtpConnection(account, with, sessionId);
|
|
||||||
|
|
||||||
rtpConnection.get().acceptCall();
|
rtpConnection.get().acceptCall();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReject() {
|
public void onReject() {
|
||||||
this.rtpConnection = xmppConnectionService.getJingleConnectionManager().findJingleRtpConnection(account, with, sessionId);
|
mHandler.post(() -> {
|
||||||
rtpConnection.get().rejectCall();
|
rtpConnection.get().rejectCall();
|
||||||
setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStateChanged(int state) {
|
||||||
|
if (state == STATE_DISCONNECTED) {
|
||||||
|
mHandler.post(() -> {
|
||||||
|
destroy();
|
||||||
|
xmppConnectionService.setDiallerIntegrationActive(false);
|
||||||
|
xmppConnectionService.removeRtpConnectionUpdateListener(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect() {
|
public void onDisconnect() {
|
||||||
|
mHandler.post(() -> {
|
||||||
if (rtpConnection == null || rtpConnection.get() == null) {
|
if (rtpConnection == null || rtpConnection.get() == null) {
|
||||||
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
|
xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
|
||||||
|
setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
|
||||||
} else {
|
} else {
|
||||||
rtpConnection.get().endCall();
|
rtpConnection.get().endCall();
|
||||||
}
|
}
|
||||||
destroy();
|
});
|
||||||
xmppConnectionService.setDiallerIntegrationActive(false);
|
|
||||||
xmppConnectionService.removeRtpConnectionUpdateListener(
|
|
||||||
(XmppConnectionService.OnJingleRtpConnectionUpdate) this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -302,7 +317,9 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayDtmfTone(char c) {
|
public void onPlayDtmfTone(char c) {
|
||||||
|
mHandler.post(() -> {
|
||||||
rtpConnection.get().applyDtmfTone("" + c);
|
rtpConnection.get().applyDtmfTone("" + c);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue