From f7f0dc99a7ffde5045a6d67ea6ec1fcbd13a779b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 19 Apr 2020 10:12:33 +0200 Subject: [PATCH] launch calls in new task --- src/main/AndroidManifest.xml | 13 +++++++------ .../conversations/ui/ConversationFragment.java | 6 ++++++ .../siacs/conversations/ui/RtpSessionActivity.java | 10 +++------- .../xmpp/jingle/JingleConnectionManager.java | 5 ++++- src/main/res/values/strings.xml | 1 + 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 29356fb21..95eb5139c 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ - + - + diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 2c6e2c863..0f47f6936 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1273,11 +1273,17 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private void triggerRtpSession(final String action) { + if (activity.xmppConnectionService.getJingleConnectionManager().isBusy()) { + Toast.makeText(getActivity(), R.string.only_one_call_at_a_time, Toast.LENGTH_LONG).show(); + return; + } final Contact contact = conversation.getContact(); final Intent intent = new Intent(activity, RtpSessionActivity.class); intent.setAction(action); intent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, contact.getAccount().getJid().toEscapedString()); intent.putExtra(RtpSessionActivity.EXTRA_WITH, contact.getJid().asBareJid().toEscapedString()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index c3ef71c80..f0cae4e53 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -78,6 +78,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe @Override public void onCreate(Bundle savedInstanceState) { + Log.d(Config.LOGTAG, this.getClass().getName() + ".onCreate()"); super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD @@ -87,12 +88,6 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe setSupportActionBar(binding.toolbar); } - @Override - public void onStart() { - super.onStart(); - Log.d(Config.LOGTAG, "RtpSessionActivity.onStart()"); - } - private void endCall(View view) { endCall(); } @@ -145,7 +140,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe if (isMicrophoneAvailable) { return; } - runOnUiThread(() -> Toast.makeText(this, R.string.microphone_unavailable, Toast.LENGTH_SHORT).show()); + runOnUiThread(() -> Toast.makeText(this, R.string.microphone_unavailable, Toast.LENGTH_LONG).show()); } ).start(); } @@ -206,6 +201,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe @Override public void onNewIntent(final Intent intent) { + Log.d(Config.LOGTAG, this.getClass().getName() + ".onNewIntent()"); super.onNewIntent(intent); setIntent(intent); if (xmppConnectionService == null) { 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 2846fbfaf..0dfb65c97 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -104,7 +104,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { return account.isOnion() || mXmppConnectionService.useTorToConnect(); } - private boolean isBusy() { + public boolean isBusy() { for (AbstractJingleConnection connection : this.connections.values()) { if (connection instanceof JingleRtpConnection) { return true; @@ -403,6 +403,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } } + if (isBusy()) { + throw new IllegalStateException("There is already a running RTP session. This should have been caught by the UI"); + } final RtpSessionProposal proposal = RtpSessionProposal.of(account, with.asBareJid(), media); this.rtpSessionProposals.put(proposal, DeviceDiscoveryState.SEARCHING); mXmppConnectionService.notifyJingleRtpConnectionUpdate( diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 63a991e76..358d768dd 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -915,6 +915,7 @@ Audio call Video call Your microphone is unavailable + You can only have one call at a time. View %1$d Participant View %1$d Participants