From e3946c89454994983701cbcfb863439f9393b6fe Mon Sep 17 00:00:00 2001 From: Ajay Panicker Date: Mon, 26 Feb 2018 16:04:15 -0800 Subject: [PATCH] AudioManager: Use setAvrcpAbsoluteVolume in adjustStreamVolume Use setAvrcpAbsoluteVolume() instead of adjustAvrcpAbsoluteVolume in adjust stream volume in order to better sync device volume and remote Bluetooth device volume. This will allow Bluetooth to avoid calculating its own volume step size. Bug: 68812037 Test: Connect to device that supports Absolute Volume and see that volume changed occur when changing volume on device. Change-Id: I26d5812ee1a5953b6527561ce5ad1c5d944c244d --- .../android/server/audio/AudioService.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 503dfe9a41cb3..cb96bacac9142 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -1494,17 +1494,6 @@ public class AudioService extends IAudioService.Stub if (adjustVolume && (direction != AudioManager.ADJUST_SAME)) { mAudioHandler.removeMessages(MSG_UNMUTE_STREAM); - // Check if volume update should be send to AVRCP - if (streamTypeAlias == AudioSystem.STREAM_MUSIC && - (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && - (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) { - synchronized (mA2dpAvrcpLock) { - if (mA2dp != null && mAvrcpAbsVolSupported) { - mA2dp.adjustAvrcpAbsoluteVolume(direction); - } - } - } - if (isMuteAdjust) { boolean state; if (direction == AudioManager.ADJUST_TOGGLE_MUTE) { @@ -1553,8 +1542,20 @@ public class AudioService extends IAudioService.Stub 0); } - // Check if volume update should be sent to Hdmi system audio. int newIndex = mStreamStates[streamType].getIndex(device); + + // Check if volume update should be send to AVRCP + if (streamTypeAlias == AudioSystem.STREAM_MUSIC && + (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && + (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) { + synchronized (mA2dpAvrcpLock) { + if (mA2dp != null && mAvrcpAbsVolSupported) { + mA2dp.setAvrcpAbsoluteVolume(newIndex / 10); + } + } + } + + // Check if volume update should be sent to Hdmi system audio. if (streamTypeAlias == AudioSystem.STREAM_MUSIC) { setSystemAudioVolume(oldIndex, newIndex, getStreamMaxVolume(streamType), flags); }