From bd05f936e5aa5b185835eeab445ae2ac2c1b63a4 Mon Sep 17 00:00:00 2001 From: Jakub Tyszkowski Date: Wed, 12 Oct 2022 18:46:50 +0000 Subject: [PATCH] AudioService: Use proper stream context for Le Audio stream volume When volume level is restored after mode change from incoming call back to normal mode (media playback) invalid contextual stream was used to calculate volume level. Should use getBluetoothContextualVolumeStream() instead. Additonally, the workaround for some cases where we don't get the proper LE Audio device was moved into the 'setLeAudioVolumeOnModeUpdate()'. Bug: 241501978 Tag: #feature Test: verified manually, missed and placed call scenario, check restored volume value Change-Id: Ibc1b92c8ea053ccab3cf4c66afce6e6e9c5c9e53 Merged-In: Ibc1b92c8ea053ccab3cf4c66afce6e6e9c5c9e53 (cherry picked from commit 86806df3f1c8db1b6c0c50a3680e4ab53494d006) --- .../android/server/audio/AudioService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 745555cd895f0..d2ba9c6dbfe49 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -4018,7 +4018,7 @@ public class AudioService extends IAudioService.Stub } } - private void setLeAudioVolumeOnModeUpdate(int mode, int streamType, int device) { + private void setLeAudioVolumeOnModeUpdate(int mode, int device) { switch (mode) { case AudioSystem.MODE_IN_COMMUNICATION: case AudioSystem.MODE_IN_CALL: @@ -4032,10 +4032,16 @@ public class AudioService extends IAudioService.Stub return; } - // Currently, DEVICE_OUT_BLE_HEADSET is the only output type for LE_AUDIO profile. - // (See AudioDeviceBroker#createBtDeviceInfo()) - int index = mStreamStates[streamType].getIndex(AudioSystem.DEVICE_OUT_BLE_HEADSET); - int maxIndex = mStreamStates[streamType].getMaxIndex(); + // Forcefully set LE audio volume as a workaround, since in some cases + // (like the outgoing call) the value of 'device' is not DEVICE_OUT_BLE_* + // even when BLE is connected. + if (!AudioSystem.isLeAudioDeviceType(device)) { + device = AudioSystem.DEVICE_OUT_BLE_HEADSET; + } + + final int streamType = getBluetoothContextualVolumeStream(mode); + final int index = mStreamStates[streamType].getIndex(device); + final int maxIndex = mStreamStates[streamType].getMaxIndex(); if (DEBUG_VOL) { Log.d(TAG, "setLeAudioVolumeOnModeUpdate postSetLeAudioVolumeIndex index=" @@ -5421,9 +5427,7 @@ public class AudioService extends IAudioService.Stub // change of mode may require volume to be re-applied on some devices updateAbsVolumeMultiModeDevices(previousMode, mode); - // Forcefully set LE audio volume as a workaround, since the value of 'device' - // is not DEVICE_OUT_BLE_* even when BLE is connected. - setLeAudioVolumeOnModeUpdate(mode, streamType, device); + setLeAudioVolumeOnModeUpdate(mode, device); // when entering RINGTONE, IN_CALL or IN_COMMUNICATION mode, clear all SCO // connections not started by the application changing the mode when pid changes