From 5e3aab3abe140ebebbd64c1ebd23132861d44e1b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 27 May 2020 13:54:35 +0200 Subject: [PATCH] ensure that finishConnection succeeds --- .../siacs/conversations/ui/RtpSessionActivity.java | 2 ++ .../xmpp/jingle/AbstractJingleConnection.java | 14 ++++++++++++-- .../xmpp/jingle/JingleConnectionManager.java | 9 ++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index a6ac2ba1b..4a68d1b03 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -412,12 +412,14 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe final WeakReference reference = xmppConnectionService.getJingleConnectionManager() .findJingleRtpConnection(account, with, sessionId); if (reference == null || reference.get() == null) { + Log.e(Config.LOGTAG,"failed to initialize activity with running rtp session. session not found"); finish(); return true; } this.rtpConnectionReference = reference; final RtpEndUserState currentState = requireRtpConnection().getEndUserState(); if (currentState == RtpEndUserState.ENDED) { + Log.e(Config.LOGTAG,"failed to initialize activity with running rtp session. session had ended"); finish(); return true; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java index ef28a2eb3..d95019048 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/AbstractJingleConnection.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.xmpp.jingle; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.base.Preconditions; @@ -78,14 +79,14 @@ public abstract class AbstractJingleConnection { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Id id = (Id) o; - return Objects.equal(account.getJid(), id.account.getJid()) && + return Objects.equal(account.getUuid(), id.account.getUuid()) && Objects.equal(with, id.with) && Objects.equal(sessionId, id.sessionId); } @Override public int hashCode() { - return Objects.hashCode(account.getJid(), with, sessionId); + return Objects.hashCode(account.getUuid(), with, sessionId); } @Override @@ -102,6 +103,15 @@ public abstract class AbstractJingleConnection { public String getSessionId() { return sessionId; } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("account", account.getJid()) + .add("with", with) + .add("sessionId", sessionId) + .toString(); + } } 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 d8be779ef..0e161bd5a 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -134,7 +134,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } - public Optional findMatchingSessionProposal(final Account account, final Jid with, final Set media) { + private Optional findMatchingSessionProposal(final Account account, final Jid with, final Set media) { synchronized (this.rtpSessionProposals) { for (Map.Entry entry : this.rtpSessionProposals.entrySet()) { final RtpSessionProposal proposal = entry.getKey(); @@ -446,7 +446,10 @@ public class JingleConnectionManager extends AbstractConnectionManager { } void finishConnection(final AbstractJingleConnection connection) { - this.connections.remove(connection.getId()); + final AbstractJingleConnection.Id id = connection.getId(); + if (this.connections.remove(id) == null) { + throw new IllegalStateException(String.format("Unable to finish connection with id=%s", id.toString())); + } } void getPrimaryCandidate(final Account account, final boolean initiator, final OnPrimaryCandidateFound listener) { @@ -667,7 +670,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { throw e; } - public void endSession(AbstractJingleConnection.Id id, final AbstractJingleConnection.State state) { + void endSession(AbstractJingleConnection.Id id, final AbstractJingleConnection.State state) { this.endedSessions.put(PersistableSessionId.of(id), state); }