From 7088c1f507d7fcc2b35ea3b47f74340e184f97bb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 17 Apr 2024 11:29:08 +0200 Subject: [PATCH] delay legacy audio routing until after call has been accepted fixes #249 --- .../services/AppRTCAudioManager.java | 7 +++++-- .../services/CallIntegration.java | 18 +++++++++--------- .../xmpp/jingle/JingleConnectionManager.java | 2 ++ .../xmpp/jingle/JingleRtpConnection.java | 2 ++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/AppRTCAudioManager.java b/src/main/java/eu/siacs/conversations/services/AppRTCAudioManager.java index 0aa0c0cd0..21e2389c3 100644 --- a/src/main/java/eu/siacs/conversations/services/AppRTCAudioManager.java +++ b/src/main/java/eu/siacs/conversations/services/AppRTCAudioManager.java @@ -88,15 +88,18 @@ public class AppRTCAudioManager { AppRTCUtils.logDeviceInfo(Config.LOGTAG); } + public void setAudioManagerEvents(final AudioManagerEvents audioManagerEvents) { + this.audioManagerEvents = audioManagerEvents; + } + @SuppressWarnings("deprecation") - public void start(final AudioManagerEvents audioManagerEvents) { + public void start() { Log.d(Config.LOGTAG, AppRTCAudioManager.class.getName() + ".start()"); ThreadUtils.checkIsOnMainThread(); if (amState == AudioManagerState.RUNNING) { Log.e(Config.LOGTAG, "AudioManager is already active"); return; } - this.audioManagerEvents = audioManagerEvents; amState = AudioManagerState.RUNNING; // Store current audio state so we can restore it when stop() is called. savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn(); diff --git a/src/main/java/eu/siacs/conversations/services/CallIntegration.java b/src/main/java/eu/siacs/conversations/services/CallIntegration.java index 339268fa3..ec9aa784b 100644 --- a/src/main/java/eu/siacs/conversations/services/CallIntegration.java +++ b/src/main/java/eu/siacs/conversations/services/CallIntegration.java @@ -15,7 +15,6 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; -import androidx.core.content.ContextCompat; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -70,8 +69,7 @@ public class CallIntegration extends Connection { this.appRTCAudioManager = null; } else { this.appRTCAudioManager = new AppRTCAudioManager(context); - ContextCompat.getMainExecutor(context) - .execute(() -> this.appRTCAudioManager.start(this::onAudioDeviceChanged)); + this.appRTCAudioManager.setAudioManagerEvents(this::onAudioDeviceChanged); } setRingbackRequested(true); } @@ -490,17 +488,19 @@ public class CallIntegration extends Connection { public void setInitialAudioDevice(final AudioDevice audioDevice) { Log.d(Config.LOGTAG, "setInitialAudioDevice(" + audioDevice + ")"); this.initialAudioDevice = audioDevice; + } + + public void startLegacyAudioRouting() { if (selfManaged()) { - // once the 'CallIntegration' gets added to the system we receive calls to update audio - // state return; } final var audioManager = requireAppRtcAudioManager(); audioManager.executeOnMain( - () -> - this.onAudioDeviceChanged( - audioManager.getSelectedAudioDevice(), - audioManager.getAudioDevices())); + () -> { + audioManager.start(); + this.onAudioDeviceChanged( + audioManager.getSelectedAudioDevice(), audioManager.getAudioDevices()); + }); } private void destroyCallIntegration() { 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 f1ebe864e..6a1779f3a 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -736,6 +736,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid()); rtpConnection.setProposedMedia(media); + rtpConnection.getCallIntegration().startLegacyAudioRouting(); this.connections.put(id, rtpConnection); rtpConnection.sendSessionInitiate(); return rtpConnection; @@ -776,6 +777,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { ? VideoProfile.STATE_AUDIO_ONLY : VideoProfile.STATE_BIDIRECTIONAL); callIntegration.setInitialAudioDevice(CallIntegration.initialAudioDevice(media)); + callIntegration.startLegacyAudioRouting(); final RtpSessionProposal proposal = RtpSessionProposal.of(account, with.asBareJid(), media, callIntegration); callIntegration.setCallback(new ProposalStateCallback(proposal)); 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 1abdcc89a..f3f5af684 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -2329,6 +2329,7 @@ public class JingleRtpConnection extends AbstractJingleConnection private void acceptCallFromProposed() { transitionOrThrow(State.PROCEED); xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); + this.callIntegration.startLegacyAudioRouting(); this.sendJingleMessage("accept", id.account.getJid().asBareJid()); this.sendJingleMessage("proceed"); } @@ -2397,6 +2398,7 @@ public class JingleRtpConnection extends AbstractJingleConnection private void acceptCallFromSessionInitialized() { xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); + this.callIntegration.startLegacyAudioRouting(); sendSessionAccept(); }