From dcfe66fda17b8644bd7af9b25a5c4550b02cb2cc Mon Sep 17 00:00:00 2001 From: Yan Han Date: Thu, 5 May 2022 15:36:37 +0200 Subject: [PATCH 1/2] Clear listeners when adding a new one in AudioDeviceVolumeManager Currently, multiple absolute volume listeners from the same controller can be notified of volume change events because old ones are not removed from AudioDeviceVolumeManager. This CL removes existing listeners for a device when a new one is added. We also no longer forbid re-adding a listener currently in AudioDeviceVolumeManager's list, as it might have been removed from AudioService. Bug: 231433390 Test: manual; atest android.hdmicec.cts.playback.HdmiCecAvcToTvTest Change-Id: If7ecd58880001b955565e0f65ede9f0787e1be49 --- media/java/android/media/AudioDeviceVolumeManager.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/media/java/android/media/AudioDeviceVolumeManager.java b/media/java/android/media/AudioDeviceVolumeManager.java index 11cacd01f53da..44b4662cdca5d 100644 --- a/media/java/android/media/AudioDeviceVolumeManager.java +++ b/media/java/android/media/AudioDeviceVolumeManager.java @@ -235,13 +235,7 @@ public class AudioDeviceVolumeManager { mDeviceVolumeDispatcherStub = new DeviceVolumeDispatcherStub(); } } else { - for (ListenerInfo info : mDeviceVolumeListeners) { - if (info.mListener == vclistener) { - throw new IllegalArgumentException( - "attempt to call setDeviceAbsoluteMultiVolumeBehavior() " - + "on a previously registered listener"); - } - } + mDeviceVolumeListeners.removeIf(info -> info.mDevice.equalTypeAddress(device)); } mDeviceVolumeListeners.add(listenerInfo); mDeviceVolumeDispatcherStub.register(true, device, volumes, handlesVolumeAdjustment); From a8bff8e07daef141207e3ebeb6109bc74c720a25 Mon Sep 17 00:00:00 2001 From: Yan Han Date: Fri, 6 May 2022 14:32:05 +0200 Subject: [PATCH 2/2] Enable volume UI for TVs using Absolute Volume Control. HdmiControlService now sets FLAG_SHOW_UI when calling AudioService APIs on a TV using Absolute Volume Control. With UI being shown when using Absolute Volume Control, hiding volume UI is only necessary when system audio mode is enabled, but Absolute Volume Control is not. This is covered by the check for full volume behavior in AudioService#sendVolumeUpdate, so the other TV-specific checks can be removed. Bug: 231430528 Test: manual Change-Id: I0579b3af77abe2559b64574e162021320cfb9100 --- .../com/android/server/audio/AudioService.java | 15 ++------------- .../android/server/hdmi/HdmiControlService.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index aed63ce5b2c6e..8c0e2ddd8f3c2 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -4146,19 +4146,8 @@ public class AudioService extends IAudioService.Stub { streamType = mStreamVolumeAlias[streamType]; - if (streamType == AudioSystem.STREAM_MUSIC) { - flags = updateFlagsForTvPlatform(flags); - synchronized (mHdmiClientLock) { - // Don't display volume UI on a TV Playback device when using absolute volume - if (mHdmiCecVolumeControlEnabled && mHdmiPlaybackClient != null - && (isAbsoluteVolumeDevice(device) - || isA2dpAbsoluteVolumeDevice(device))) { - flags &= ~AudioManager.FLAG_SHOW_UI; - } - } - if (isFullVolumeDevice(device)) { - flags &= ~AudioManager.FLAG_SHOW_UI; - } + if (streamType == AudioSystem.STREAM_MUSIC && isFullVolumeDevice(device)) { + flags &= ~AudioManager.FLAG_SHOW_UI; } mVolumeController.postVolumeChanged(streamType, flags); } diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java index 9824b4e6c43ae..f8a74f4f3f554 100644 --- a/services/core/java/com/android/server/hdmi/HdmiControlService.java +++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java @@ -4176,7 +4176,11 @@ public class HdmiControlService extends SystemService { List streamMusicDevices = getAudioManager().getDevicesForAttributes(STREAM_MUSIC_ATTRIBUTES); if (streamMusicDevices.contains(getAvcAudioOutputDevice())) { - setStreamMusicVolume(volume, AudioManager.FLAG_ABSOLUTE_VOLUME); + int flags = AudioManager.FLAG_ABSOLUTE_VOLUME; + if (isTvDevice()) { + flags |= AudioManager.FLAG_SHOW_UI; + } + setStreamMusicVolume(volume, flags); } } @@ -4190,8 +4194,11 @@ public class HdmiControlService extends SystemService { getAudioManager().getDevicesForAttributes(STREAM_MUSIC_ATTRIBUTES); if (streamMusicDevices.contains(getAvcAudioOutputDevice())) { int direction = mute ? AudioManager.ADJUST_MUTE : AudioManager.ADJUST_UNMUTE; - getAudioManager().adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, - AudioManager.FLAG_ABSOLUTE_VOLUME); + int flags = AudioManager.FLAG_ABSOLUTE_VOLUME; + if (isTvDevice()) { + flags |= AudioManager.FLAG_SHOW_UI; + } + getAudioManager().adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, flags); } }