back button rejects or ends call

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java           | 10 
src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java | 12 
2 files changed, 20 insertions(+), 2 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java 🔗

@@ -68,6 +68,10 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
     }
 
     private void endCall(View view) {
+        endCall();
+    }
+
+    private void endCall() {
         if (this.rtpConnectionReference == null) {
             final Intent intent = getIntent();
             final Account account = extractAccount(intent);
@@ -165,6 +169,12 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
         }
     }
 
+    @Override
+    public void onBackPressed() {
+        endCall();
+        super.onBackPressed();
+    }
+
 
     private void initializeActivityWithRunningRapSession(final Account account, Jid with, String sessionId) {
         final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()

src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java 🔗

@@ -639,6 +639,10 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
     }
 
     public void endCall() {
+        if (isInState(State.PROPOSED) && !isInitiator()) {
+            rejectCallFromProposed();
+            return;
+        }
         if (isInState(State.PROCEED)) {
             Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ending call while in state PROCEED just means ending the connection");
             webRTCWrapper.close();
@@ -651,12 +655,16 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
             sendSessionTerminate(Reason.CANCEL);
             return;
         }
-        if (isInState(State.SESSION_INITIALIZED, State.SESSION_INITIALIZED_PRE_APPROVED, State.SESSION_ACCEPTED)) {
+        if (isInState(State.SESSION_INITIALIZED)) {
+            rejectCallFromSessionInitiate();
+            return;
+        }
+        if (isInState(State.SESSION_INITIALIZED_PRE_APPROVED, State.SESSION_ACCEPTED)) {
             webRTCWrapper.close();
             sendSessionTerminate(Reason.SUCCESS);
             return;
         }
-        throw new IllegalStateException("called 'endCall' while in state " + this.state);
+        throw new IllegalStateException("called 'endCall' while in state " + this.state + ". isInitiator=" + isInitiator());
     }
 
     private void setupWebRTC(final List<PeerConnection.IceServer> iceServers) throws WebRTCWrapper.InitializationException {