diff options
| author | 2022-06-23 23:32:27 +0000 | |
|---|---|---|
| committer | 2022-07-06 19:24:56 +0000 | |
| commit | d6c098fe2daee74154aa16e69f6df8e748314020 (patch) | |
| tree | 10655bb83774ce3acc573887a1923b3bc81a37ad | |
| parent | e42213b55030e2fafe333c530581ee0e5a58fa46 (diff) | |
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
Change-Id: I36f39e88e11f4e8ed644b54bfb15308f08a3d698
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 03dcc8d711d3..b3aff65afb1f 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -1323,7 +1323,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 dbe4fb8c8795..1312d082a832 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1158,6 +1158,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 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 73e4cf23c347..d9037fe7aca7 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -423,7 +423,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"); @@ -440,8 +441,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); } |