ensure that finishConnection succeeds

This commit is contained in:
Daniel Gultsch 2020-05-27 13:54:35 +02:00
parent 575ada3b27
commit 5e3aab3abe
3 changed files with 20 additions and 5 deletions

View file

@ -412,12 +412,14 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final WeakReference<JingleRtpConnection> 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;
}

View file

@ -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();
}
}

View file

@ -134,7 +134,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
}
}
public 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) {
for (Map.Entry<RtpSessionProposal, DeviceDiscoveryState> 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);
}