From ac83c5cb14097220a0d4c04da1ef95e6fd58ddb2 Mon Sep 17 00:00:00 2001 From: Hyundo Moon Date: Wed, 20 Jul 2022 21:19:00 +0900 Subject: Set LE audio volume when audio mode is changed Bug: 230643532 Test: Checked the volume is changed when entering call mode Change-Id: Iae20b03e998a8a6064a85d6e7cf4858c85448618 --- .../com/android/server/audio/AudioService.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 490f84456823..1a999fbf579c 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3584,6 +3584,36 @@ public class AudioService extends IAudioService.Stub } } + private void setLeAudioVolumeOnModeUpdate(int mode) { + switch (mode) { + case AudioSystem.MODE_IN_COMMUNICATION: + case AudioSystem.MODE_IN_CALL: + case AudioSystem.MODE_NORMAL: + break; + case AudioSystem.MODE_RINGTONE: + // not changing anything for ringtone + return; + case AudioSystem.MODE_CURRENT: + case AudioSystem.MODE_INVALID: + default: + // don't know what to do in this case, better bail + return; + } + + int streamType = getBluetoothContextualVolumeStream(mode); + + // 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(); + + if (DEBUG_VOL) { + Log.d(TAG, "setLeAudioVolumeOnModeUpdate postSetLeAudioVolumeIndex index=" + + index + " maxIndex=" + maxIndex + " streamType=" + streamType); + } + mDeviceBroker.postSetLeAudioVolumeIndex(index, maxIndex, streamType); + } + private void setStreamVolume(int streamType, int index, int flags, String callingPackage, String caller, int uid, boolean hasModifyAudioSettings) { if (DEBUG_VOL) { @@ -4915,6 +4945,10 @@ 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); + // when entering RINGTONE, IN_CALL or IN_COMMUNICATION mode, clear all SCO // connections not started by the application changing the mode when pid changes mDeviceBroker.postSetModeOwnerPid(pid, mode); -- cgit v1.2.3-59-g8ed1b