From 1ae7d6be1602cdbda6cb55f3a9bb4142b1c3f9df Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 1 Aug 2020 09:50:51 +0200 Subject: [PATCH] recover from pre-jingle connection states (discover etc) into full fledged jingle connection fixes #3847 --- .../conversations/ui/RtpSessionActivity.java | 12 +++++++-- .../xmpp/jingle/JingleConnectionManager.java | 27 +++++++++++++++++++ .../xmpp/jingle/JingleRtpConnection.java | 5 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 33835119f..0fd9ee187 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -371,15 +371,23 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe binding.with.setText(account.getRoster().getContact(with).getDisplayName()); } else if (Intent.ACTION_VIEW.equals(action)) { final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE); - if (extraLastState != null) { + final RtpEndUserState state = extraLastState == null ? null : RtpEndUserState.valueOf(extraLastState); + if (state != null) { Log.d(Config.LOGTAG, "restored last state from intent extra"); - RtpEndUserState state = RtpEndUserState.valueOf(extraLastState); updateButtonConfiguration(state); updateStateDisplay(state); updateProfilePicture(state); invalidateOptionsMenu(); } binding.with.setText(account.getRoster().getContact(with).getDisplayName()); + if (xmppConnectionService.getJingleConnectionManager().fireJingleRtpConnectionStateUpdates()) { + return; + } + if (END_CARD.contains(state) || xmppConnectionService.getJingleConnectionManager().hasMatchingProposal(account, with)) { + return; + } + Log.d(Config.LOGTAG, "restored state (" + state + ") was not an end card. finishing"); + finish(); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 03bafb275..67ff221b7 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -456,6 +456,21 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } + public boolean fireJingleRtpConnectionStateUpdates() { + boolean firedUpdates = false; + for (final AbstractJingleConnection connection : this.connections.values()) { + if (connection instanceof JingleRtpConnection) { + final JingleRtpConnection jingleRtpConnection = (JingleRtpConnection) connection; + if (jingleRtpConnection.isTerminated()) { + continue; + } + jingleRtpConnection.fireStateUpdate(); + firedUpdates = true; + } + } + return firedUpdates; + } + void getPrimaryCandidate(final Account account, final boolean initiator, final OnPrimaryCandidateFound listener) { if (Config.DISABLE_PROXY_LOOKUP) { listener.onPrimaryCandidateFound(false, null); @@ -576,6 +591,18 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } + public boolean hasMatchingProposal(final Account account, final Jid with) { + synchronized (this.rtpSessionProposals) { + for (Map.Entry entry : this.rtpSessionProposals.entrySet()) { + final RtpSessionProposal proposal = entry.getKey(); + if (proposal.account == account && with.asBareJid().equals(proposal.with)) { + return true; + } + } + } + return false; + } + public void deliverIbbPacket(Account account, IqPacket packet) { final String sid; final Element payload; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index efc6d6b49..ec4c67d64 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -1263,6 +1263,11 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web this.proposedMedia = media; } + public void fireStateUpdate() { + final RtpEndUserState endUserState = getEndUserState(); + xmppConnectionService.notifyJingleRtpConnectionUpdate(id.account, id.with, id.sessionId, endUserState); + } + private interface OnIceServersDiscovered { void onIceServersDiscovered(List iceServers); }