From 6a6c9fb3bf5d8cbf6571d32dfb62886578ae395b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 9 Jul 2020 19:14:28 +0200 Subject: [PATCH] ignore race condition when toggling fixes #3822 --- .../siacs/conversations/ui/RtpSessionActivity.java | 14 ++++++++------ .../xmpp/jingle/JingleRtpConnection.java | 4 ++-- .../conversations/xmpp/jingle/WebRTCWrapper.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 5db8dfc6d..9bff9ff98 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -910,15 +910,17 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } private void disableMicrophone(View view) { - JingleRtpConnection rtpConnection = requireRtpConnection(); - rtpConnection.setMicrophoneEnabled(false); - updateInCallButtonConfiguration(); + final JingleRtpConnection rtpConnection = requireRtpConnection(); + if (rtpConnection.setMicrophoneEnabled(false)) { + updateInCallButtonConfiguration(); + } } private void enableMicrophone(View view) { - JingleRtpConnection rtpConnection = requireRtpConnection(); - rtpConnection.setMicrophoneEnabled(true); - updateInCallButtonConfiguration(); + final JingleRtpConnection rtpConnection = requireRtpConnection(); + if (rtpConnection.setMicrophoneEnabled(true)) { + updateInCallButtonConfiguration(); + } } private void switchToEarpiece(View view) { 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 28f7c738b..830695831 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -1085,8 +1085,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web return webRTCWrapper.isMicrophoneEnabled(); } - public void setMicrophoneEnabled(final boolean enabled) { - webRTCWrapper.setMicrophoneEnabled(enabled); + public boolean setMicrophoneEnabled(final boolean enabled) { + return webRTCWrapper.setMicrophoneEnabled(enabled); } public boolean isVideoEnabled() { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index ff7e6a677..98ce37a4e 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -370,12 +370,19 @@ public class WebRTCWrapper { } } - void setMicrophoneEnabled(final boolean enabled) { + boolean setMicrophoneEnabled(final boolean enabled) { final AudioTrack audioTrack = this.localAudioTrack; if (audioTrack == null) { throw new IllegalStateException("Local audio track does not exist (yet)"); } - audioTrack.setEnabled(enabled); + try { + audioTrack.setEnabled(enabled); + return true; + } catch (final IllegalStateException e) { + Log.d(Config.LOGTAG, "unable to toggle microphone", e); + //ignoring race condition in case MediaStreamTrack has been disposed + return false; + } } boolean isVideoEnabled() {