From 59d1a2982e503c540971424e9e17fc29eacc30df Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 28 May 2020 09:22:58 +0200 Subject: [PATCH] =?UTF-8?q?RtpSessionActivity:=20throw=20instead=20of=20fi?= =?UTF-8?q?nish=20when=20session=20wasn=E2=80=99t=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conversations/ui/RtpSessionActivity.java | 8 +++----- .../xmpp/jingle/JingleRtpConnection.java | 17 +++++++++++++++++ 2 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 bf691db6c..8c70413a5 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -412,14 +412,12 @@ 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; + throw new IllegalStateException("failed to initialize activity with running rtp session. session not found"); } 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"); + reference.get().throwStateTransitionException(); finish(); return true; } @@ -795,7 +793,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe try { videoTrack.addSink(surfaceViewRenderer); } catch (final IllegalStateException e) { - Log.e(Config.LOGTAG,"possible race condition on trying to display video track. ignoring",e); + Log.e(Config.LOGTAG, "possible race condition on trying to display video track. ignoring", e); } } 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 0af69ca28..0704f695a 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -123,6 +123,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private final ArrayDeque pendingIceCandidates = new ArrayDeque<>(); private final Message message; private State state = State.NULL; + private StateTransitionException stateTransitionException; private Set proposedMedia; private RtpContentMap initiatorRtpContentMap; private RtpContentMap responderRtpContentMap; @@ -771,6 +772,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web xmppConnectionService.sendIqPacket(id.account, jinglePacket.generateResponse(IqPacket.TYPE.RESULT), null); } + public void throwStateTransitionException() { + final StateTransitionException exception = this.stateTransitionException; + if (exception != null) { + throw new IllegalStateException(String.format("Transition to %s did not call finish", exception.state), exception); + } + } + public RtpEndUserState getEndUserState() { switch (this.state) { case PROPOSED: @@ -983,6 +991,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web final Collection validTransitions = VALID_TRANSITIONS.get(this.state); if (validTransitions != null && validTransitions.contains(target)) { this.state = target; + this.stateTransitionException = new StateTransitionException(target); if (runnable != null) { runnable.run(); } @@ -1231,4 +1240,12 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private interface OnIceServersDiscovered { void onIceServersDiscovered(List iceServers); } + + private static class StateTransitionException extends Exception { + private final State state; + + private StateTransitionException(final State state) { + this.state = state; + } + } }