diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt index a865a6ad5..c618e9b7e 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/ControlsViewModel.kt @@ -90,7 +90,7 @@ class ControlsViewModel : ViewModel() { val somethingClickedEvent = MutableLiveData>() - val chatAllowed = !LinphoneApplication.corePreferences.disableChat + val chatAllowed = !corePreferences.disableChat private val vibrator = coreContext.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator @@ -178,12 +178,15 @@ class ControlsViewModel : ViewModel() { } override fun onAudioDeviceChanged(core: Core, audioDevice: AudioDevice) { + Log.i("[Call] Audio device changed: ${audioDevice.deviceName}") updateSpeakerState() updateBluetoothHeadsetState() } override fun onAudioDevicesListUpdated(core: Core) { + if (core.callsNb == 0) return updateAudioRoutesState() + routeAudioToBluetoothIfAvailable(core.currentCall ?: core.calls[0]) } } @@ -436,6 +439,18 @@ class ControlsViewModel : ViewModel() { isBluetoothHeadsetSelected.value = audioDevice?.type == AudioDevice.Type.Bluetooth } + private fun routeAudioToBluetoothIfAvailable(call: Call) { + for (audioDevice in coreContext.core.audioDevices) { + if (audioDevice.type == AudioDevice.Type.Bluetooth && + audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) { + Log.i("[Call] Found bluetooth audio device [${audioDevice.deviceName}], routing audio to it") + call.outputAudioDevice = audioDevice + return + } + } + Log.w("[Call] Didn't find any bluetooth audio device, keeping current audio route") + } + private fun updateVideoAvailable() { val core = coreContext.core val currentCall = core.currentCall diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index 0fa07f29f..ef5b18a0f 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -160,7 +160,7 @@ class CoreContext(val context: Context, coreConfig: Config) { } } else if (state == Call.State.OutgoingInit) { onOutgoingStarted() - } else if (state == Call.State.OutgoingRinging) { + } else if (state == Call.State.OutgoingProgress) { if (core.callsNb == 1) { routeAudioToBluetoothIfAvailable(call) }