From 851b347171b10e10f5048171c2bd7f78b5dfc52a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 12 May 2021 15:05:12 +0200 Subject: [PATCH] AudioService: fix AVRCP absolute volume reset Reset mAvrcpAbsVolSupported in both AudioService and BtHelper when disconnecting an A2DP device. Bug: 184447729 Test: music playback and volume change over Bluetooth A2DP Change-Id: Ie7df473b16c454398fb14f9b5489d8889bc653d0 --- .../java/com/android/server/audio/AudioDeviceBroker.java | 5 +++++ .../java/com/android/server/audio/AudioDeviceInventory.java | 2 +- .../core/java/com/android/server/audio/AudioService.java | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index 96bb73f3107ce..8961a5a055465 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -1034,6 +1034,11 @@ import java.util.concurrent.atomic.AtomicBoolean; } } + /*package*/ void clearAvrcpAbsoluteVolumeSupported() { + setAvrcpAbsoluteVolumeSupported(false); + mAudioService.setAvrcpAbsoluteVolumeSupported(false); + } + /*package*/ boolean getBluetoothA2dpEnabled() { synchronized (mDeviceStateLock) { return mBluetoothA2dpEnabled; diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index 18d04e94b36f7..5944a63bd5e6a 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1015,7 +1015,7 @@ public class AudioDeviceInventory { } // device to remove was visible by APM, update APM - mDeviceBroker.setAvrcpAbsoluteVolumeSupported(false); + mDeviceBroker.clearAvrcpAbsoluteVolumeSupported(); final int res = mAudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, AudioSystem.DEVICE_STATE_UNAVAILABLE, address, "", a2dpCodec); diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 098ce7cd137ca..0712093bca550 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -7643,8 +7643,12 @@ public class AudioService extends IAudioService.Stub // address is not used for now, but may be used when multiple a2dp devices are supported sVolumeLogger.log(new AudioEventLogger.StringEvent("avrcpSupportsAbsoluteVolume addr=" + address + " support=" + support)); - mAvrcpAbsVolSupported = support; mDeviceBroker.setAvrcpAbsoluteVolumeSupported(support); + setAvrcpAbsoluteVolumeSupported(support); + } + + /*package*/ void setAvrcpAbsoluteVolumeSupported(boolean support) { + mAvrcpAbsVolSupported = support; sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, mStreamStates[AudioSystem.STREAM_MUSIC], 0);