Merge branch 'audio-routing2'

Stephen Paul Weber created

* audio-routing2:
  Support mute during dialler integration calls
  Use a more familiar ringback for north american users

Change summary

src/cheogram/java/com/cheogram/android/ConnectionService.java     | 22 
src/main/java/eu/siacs/conversations/xmpp/jingle/ToneManager.java |  2 
2 files changed, 22 insertions(+), 2 deletions(-)

Detailed changes

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<String> postDial = new Stack<>();
 		protected Icon gatewayIcon;
+		protected CallAudioState pendingState = null;
 		protected WeakReference<JingleRtpConnection> 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<AppRTCAudioManager.AudioDevice> 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

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

@@ -131,7 +131,7 @@ class ToneManager {
 
     private void scheduleWaitingTone() {
         this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(() -> {
-            startTone(ToneGenerator.TONE_CDMA_DIAL_TONE_LITE, 750);
+            startTone(ToneGenerator.TONE_CDMA_NETWORK_USA_RINGBACK, 750);
         }, 0, 3, TimeUnit.SECONDS);
     }