From cd772d04345850e160a45613fcf6b86da0dce4cf Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 30 Oct 2013 18:31:07 -0700 Subject: [PATCH] AudioService: fix notifications with A2DP abs volume When A2DP absolute volume is enabled, the music stream software volume is maxed out because the headset applies the volume. We must also max out other streams playing over A2DP otherwise they are attenuated twice and are barely audible. Bug: 11316102. Change-Id: I7e58c74cb683ad1d6f3b68abb0ef967c817fbf4f --- media/java/android/media/AudioService.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 1f5fefd05fffe..b836f50b6b524 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -2913,12 +2913,10 @@ public class AudioService extends IAudioService.Stub { int index; if (isMuted()) { index = 0; - } else if (mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC && - (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && + } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) { index = (mIndexMax + 5)/10; - } - else { + } else { index = (getIndex(device) + 5)/10; } AudioSystem.setStreamVolumeIndex(mStreamType, index, device); @@ -2943,6 +2941,9 @@ public class AudioService extends IAudioService.Stub { if (device != AudioSystem.DEVICE_OUT_DEFAULT) { if (isMuted()) { index = 0; + } else if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && + mAvrcpAbsVolSupported) { + index = (mIndexMax + 5)/10; } else { index = ((Integer)entry.getValue() + 5)/10; } @@ -3215,7 +3216,14 @@ public class AudioService extends IAudioService.Stub { for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { if (streamType != streamState.mStreamType && mStreamVolumeAlias[streamType] == streamState.mStreamType) { - mStreamStates[streamType].applyDeviceVolume(getDeviceForStream(streamType)); + // Make sure volume is also maxed out on A2DP device for aliased stream + // that may have a different device selected + int streamDevice = getDeviceForStream(streamType); + if ((device != streamDevice) && mAvrcpAbsVolSupported && + ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0)) { + mStreamStates[streamType].applyDeviceVolume(device); + } + mStreamStates[streamType].applyDeviceVolume(streamDevice); } } @@ -3843,9 +3851,12 @@ public class AudioService extends IAudioService.Stub { // address is not used for now, but may be used when multiple a2dp devices are supported synchronized (mA2dpAvrcpLock) { mAvrcpAbsVolSupported = support; - VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC]; sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE, - AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, streamState, 0); + AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, + mStreamStates[AudioSystem.STREAM_MUSIC], 0); + sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE, + AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, + mStreamStates[AudioSystem.STREAM_RING], 0); } }