From 9f7a9498f941327132774e9c96f689cb64c57bba Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Jul 2022 12:46:31 -0500 Subject: [PATCH] Support mute during dialler integration calls --- .../cheogram/android/ConnectionService.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cheogram/java/com/cheogram/android/ConnectionService.java b/src/cheogram/java/com/cheogram/android/ConnectionService.java index 0f5dfa172..9f02369a1 100644 --- a/src/cheogram/java/com/cheogram/android/ConnectionService.java +++ b/src/cheogram/java/com/cheogram/android/ConnectionService.java @@ -197,6 +197,7 @@ public class ConnectionService extends android.telecom.ConnectionService { protected String sessionId = null; protected Stack postDial = new Stack<>(); protected Icon gatewayIcon; + protected CallAudioState pendingState = null; protected WeakReference rtpConnection = null; CheogramConnection(Account account, Jid with, String postDialString) { @@ -222,7 +223,8 @@ public class ConnectionService extends android.telecom.ConnectionService { ); setAudioModeIsVoip(true); setConnectionCapabilities( - Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION + Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION | + Connection.CAPABILITY_MUTE ); } @@ -271,6 +273,8 @@ public class ConnectionService extends android.telecom.ConnectionService { public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set availableAudioDevices) { if (Build.VERSION.SDK_INT < 26) return; + if (pendingState != null) onCallAudioStateChanged(pendingState); + switch(selectedAudioDevice) { case SPEAKER_PHONE: setAudioRoute(CallAudioState.ROUTE_SPEAKER); @@ -285,6 +289,22 @@ public class ConnectionService extends android.telecom.ConnectionService { } } + @Override + public void onCallAudioStateChanged(CallAudioState state) { + pendingState = null; + if (rtpConnection == null || rtpConnection.get() == null) { + pendingState = state; + return; + } + + try { + rtpConnection.get().setMicrophoneEnabled(!state.isMuted()); + } catch (final IllegalStateException e) { + pendingState = state; + Log.w("com.cheogram.android.CheogramConnection", "Could not set microphone mute to " + (state.isMuted() ? "true" : "false") + ": " + e.toString()); + } + } + @Override public void onAnswer() { // For incoming calls, a connection update may not have been triggered before answering -- 2.45.2