From 7ceaa5ce070010e9f7447ccf0c401bf6a23ed7fa Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 23 Jun 2022 23:32:27 +0000 Subject: [PATCH 1/2] AudioService: conditional logging of hearing aid volume To avoid confusion when reading audio dumpsys, do not log hearing aid volume changes when a DEVICE_OUT_HEARING_AID is not connected. Bug: 236983951 Test: adb shell dumpsys audio | grep HEARING_AID Merged-In: I36f39e88e11f4e8ed644b54bfb15308f08a3d698 Change-Id: I36f39e88e11f4e8ed644b54bfb15308f08a3d698 (cherry picked from commit 7ea873b0dceb9916a973c34d1d5a65e461cebb98) --- .../android/server/audio/AudioDeviceBroker.java | 3 ++- .../server/audio/AudioDeviceInventory.java | 16 ++++++++++++++++ .../java/com/android/server/audio/BtHelper.java | 10 +++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index 0d08db91f35ee..736914ace2155 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -1365,7 +1365,8 @@ import java.util.concurrent.atomic.AtomicBoolean; break; case MSG_II_SET_HEARING_AID_VOLUME: synchronized (mDeviceStateLock) { - mBtHelper.setHearingAidVolume(msg.arg1, msg.arg2); + mBtHelper.setHearingAidVolume(msg.arg1, msg.arg2, + mDeviceInventory.isHearingAidConnected()); } break; case MSG_II_SET_LE_AUDIO_OUT_VOLUME: { diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index ee0d79f49af72..e90bfe85fc89e 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1161,6 +1161,22 @@ public class AudioDeviceInventory { .record(); } + /** + * Returns whether a device of type DEVICE_OUT_HEARING_AID is connected. + * Visibility by APM plays no role + * @return true if a DEVICE_OUT_HEARING_AID is connected, false otherwise. + */ + boolean isHearingAidConnected() { + synchronized (mDevicesLock) { + for (DeviceInfo di : mConnectedDevices.values()) { + if (di.mDeviceType == AudioSystem.DEVICE_OUT_HEARING_AID) { + return true; + } + } + return false; + } + } + @GuardedBy("mDevicesLock") private void makeLeAudioDeviceAvailable(String address, String name, int streamType, int volumeIndex, int device, String eventSource) { diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java index d0f5470a73040..6cd42f87aedeb 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -424,7 +424,8 @@ public class BtHelper { mLeAudio.setVolume(volume); } - /*package*/ synchronized void setHearingAidVolume(int index, int streamType) { + /*package*/ synchronized void setHearingAidVolume(int index, int streamType, + boolean isHeadAidConnected) { if (mHearingAid == null) { if (AudioService.DEBUG_VOL) { Log.i(TAG, "setHearingAidVolume: null mHearingAid"); @@ -441,8 +442,11 @@ public class BtHelper { Log.i(TAG, "setHearingAidVolume: calling mHearingAid.setVolume idx=" + index + " gain=" + gainDB); } - AudioService.sVolumeLogger.log(new AudioServiceEvents.VolumeEvent( - AudioServiceEvents.VolumeEvent.VOL_SET_HEARING_AID_VOL, index, gainDB)); + // do not log when hearing aid is not connected to avoid confusion when reading dumpsys + if (isHeadAidConnected) { + AudioService.sVolumeLogger.log(new AudioServiceEvents.VolumeEvent( + AudioServiceEvents.VolumeEvent.VOL_SET_HEARING_AID_VOL, index, gainDB)); + } mHearingAid.setVolume(gainDB); } From 0cc6f636ae6ce9d237bbf55e2eb1aef0c676f4ec Mon Sep 17 00:00:00 2001 From: Jakub Tyszkowski Date: Wed, 21 Sep 2022 22:13:15 +0000 Subject: [PATCH 2/2] BleAudioVolume: Fix calculation for the activated device Fixes the following: - invalid volume level value set for the newly activated BLE device (additional patch for Bluetooth is also provided) - audio FW not being notified about the new volume level when switching to phone call mode Bug: 243334827 Bug: 241501978 Tag: #feature Test: tested manually Change-Id: I46b2004d205ecdec470b84d1403cbd99af734626 Merged-In: I46b2004d205ecdec470b84d1403cbd99af734626 (cherry picked from commit 0be0ffc86db4919519a0a070e447cc9e9c9f6938) --- .../com/android/server/audio/AudioDeviceInventory.java | 3 ++- .../core/java/com/android/server/audio/AudioService.java | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index e90bfe85fc89e..35da73ef58c05 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -377,7 +377,8 @@ public class AudioDeviceInventory { makeLeAudioDeviceUnavailable(address, btInfo.mAudioSystemDevice); } else if (switchToAvailable) { makeLeAudioDeviceAvailable(address, BtHelper.getName(btInfo.mDevice), - streamType, btInfo.mVolume, btInfo.mAudioSystemDevice, + streamType, btInfo.mVolume == -1 ? -1 : btInfo.mVolume * 10, + btInfo.mAudioSystemDevice, "onSetBtActiveDevice"); } break; diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 0b6b89074cfce..182778113c365 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -4011,7 +4011,7 @@ public class AudioService extends IAudioService.Stub } } - private void setLeAudioVolumeOnModeUpdate(int mode) { + private void setLeAudioVolumeOnModeUpdate(int mode, int streamType, int device) { switch (mode) { case AudioSystem.MODE_IN_COMMUNICATION: case AudioSystem.MODE_IN_CALL: @@ -4025,8 +4025,6 @@ public class AudioService extends IAudioService.Stub 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); @@ -4037,6 +4035,7 @@ public class AudioService extends IAudioService.Stub + index + " maxIndex=" + maxIndex + " streamType=" + streamType); } mDeviceBroker.postSetLeAudioVolumeIndex(index, maxIndex, streamType); + mDeviceBroker.postApplyVolumeOnDevice(streamType, device, "setLeAudioVolumeOnModeUpdate"); } private void setStreamVolume(int streamType, int index, int flags, @@ -5417,7 +5416,7 @@ public class AudioService extends IAudioService.Stub // 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); + setLeAudioVolumeOnModeUpdate(mode, streamType, 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