Auto switch to bluetooth during a call if available

This commit is contained in:
Sylvain Berfini 2020-12-17 12:07:11 +01:00
parent 111bcd092f
commit 62083bc5c0
2 changed files with 17 additions and 2 deletions

View file

@ -90,7 +90,7 @@ class ControlsViewModel : ViewModel() {
val somethingClickedEvent = MutableLiveData<Event<Boolean>>()
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

View file

@ -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)
}