terminate jingle call when regular call starts

This commit is contained in:
Daniel Gultsch 2020-08-24 12:47:54 +02:00
parent 91e94db747
commit d158eeaf72
3 changed files with 27 additions and 1 deletions

View File

@ -268,7 +268,10 @@ public class XmppConnectionService extends Service {
private final PhoneStateListener phoneStateListener = new PhoneStateListener() { private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override @Override
public void onCallStateChanged(final int state, final String phoneNumber) { public void onCallStateChanged(final int state, final String phoneNumber) {
isPhoneInCall.set(state != 0); isPhoneInCall.set(state != TelephonyManager.CALL_STATE_IDLE);
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
mJingleConnectionManager.notifyPhoneCallStarted();
}
} }
}; };

View File

@ -14,6 +14,7 @@ import com.google.common.collect.ImmutableSet;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -137,6 +138,18 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
} }
public void notifyPhoneCallStarted() {
for (AbstractJingleConnection connection : connections.values()) {
if (connection instanceof JingleRtpConnection) {
final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
if (rtpConnection.isTerminated()) {
continue;
}
rtpConnection.notifyPhoneCall();
}
}
}
private Optional<RtpSessionProposal> findMatchingSessionProposal(final Account account, final Jid with, final Set<Media> media) { private Optional<RtpSessionProposal> findMatchingSessionProposal(final Account account, final Jid with, final Set<Media> media) {
synchronized (this.rtpSessionProposals) { synchronized (this.rtpSessionProposals) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) { for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> entry : this.rtpSessionProposals.entrySet()) {

View File

@ -901,6 +901,16 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
public void notifyPhoneCall() {
Log.d(Config.LOGTAG, "a phone call has just been started. killing jingle rtp connections");
if (Arrays.asList(State.PROPOSED, State.SESSION_INITIALIZED).contains(this.state)) {
rejectCall();
} else {
endCall();
}
}
public synchronized void rejectCall() { public synchronized void rejectCall() {
if (isTerminated()) { if (isTerminated()) {
Log.w(Config.LOGTAG, id.account.getJid().asBareJid() + ": received rejectCall() when session has already been terminated. nothing to do"); Log.w(Config.LOGTAG, id.account.getJid().asBareJid() + ": received rejectCall() when session has already been terminated. nothing to do");