From ef16485eac17bcab55dbf365ad74bfa95ed55822 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 11 Sep 2020 13:30:00 +0300 Subject: [PATCH] Always use loudspeaker while ringing and a headset is not connected. --- CHANGES.md | 1 + .../app/features/call/CallAudioManager.kt | 21 ++++++++++++++++--- .../call/WebRtcPeerConnectionManager.kt | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index eada6082b9..01fd289038 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Improvements 🙌: Bugfix 🐛: - Clear the notification when the event is read elsewhere (#1822) + - Speakerphone is not used for ringback tone (#1644, #1645) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/features/call/CallAudioManager.kt b/vector/src/main/java/im/vector/app/features/call/CallAudioManager.kt index 2a773c2f9b..9b3c42ab5d 100644 --- a/vector/src/main/java/im/vector/app/features/call/CallAudioManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/CallAudioManager.kt @@ -24,6 +24,7 @@ import android.content.pm.PackageManager import android.media.AudioManager import androidx.core.content.getSystemService import im.vector.app.core.services.WiredHeadsetStateReceiver +import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.session.call.MxCall import timber.log.Timber import java.util.concurrent.Executors @@ -116,10 +117,19 @@ class CallAudioManager( // Always disable microphone mute during a WebRTC call. setMicrophoneMute(false) + adjustCurrentSoundDevice(mxCall) + } + + private fun adjustCurrentSoundDevice(mxCall: MxCall) { + val audioManager = audioManager ?: return executor.execute { - // If there are no headset, start video output in speaker - // (you can't watch the video and have the phone close to your ear) - if (mxCall.isVideoCall && !isHeadsetOn()) { + if (mxCall.state == CallState.LocalRinging && !isHeadsetOn()) { + // Always use speaker if incoming call is in ringing state and a headset is not connected + Timber.v("##VOIP: AudioManager default to SPEAKER (it is ringing)") + setCurrentSoundDevice(SoundDevice.SPEAKER) + } else if (mxCall.isVideoCall && !isHeadsetOn()) { + // If there are no headset, start video output in speaker + // (you can't watch the video and have the phone close to your ear) Timber.v("##VOIP: AudioManager default to speaker ") setCurrentSoundDevice(SoundDevice.SPEAKER) } else { @@ -138,6 +148,11 @@ class CallAudioManager( } } + fun onCallConnected(mxCall: MxCall) { + Timber.v("##VOIP: AudioManager call answered, adjusting current sound device") + adjustCurrentSoundDevice(mxCall) + } + fun getAvailableSoundDevices(): List { return ArrayList().apply { if (isBluetoothHeadsetOn()) add(SoundDevice.WIRELESS_HEADSET) diff --git a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt index bb6312a8ce..b53be292c8 100644 --- a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt @@ -858,6 +858,7 @@ class WebRtcPeerConnectionManager @Inject constructor( */ PeerConnection.PeerConnectionState.CONNECTED -> { callContext.mxCall.state = CallState.Connected(newState) + audioManager.onCallConnected(callContext.mxCall) } /** * One or more of the ICE transports on the connection is in the "failed" state.