From 9ce379aef155e0c21b5d82d8dc713c62792e4f30 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Tue, 16 Feb 2010 06:00:26 -0800 Subject: [PATCH] Fix issue 2440226: Car dock volume synchronization. AudioService now sends intent AudioManager.VOLUME_CHANGED_ACTION when the volume is changed on any stream type (previously the intent was sent only for STREAM_BLUETOOTH_SCO stream). A new extra for previous volume value is added to the intent. --- media/java/android/media/AudioManager.java | 9 ++++++++- media/java/android/media/AudioService.java | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 70c27c25a1f61..32c5c23fd9765 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -87,10 +87,11 @@ public class AudioManager { /** * @hide Broadcast intent when the volume for a particular stream type changes. - * Includes the stream and the new volume + * Includes the stream, the new volume and previous volumes * * @see #EXTRA_VOLUME_STREAM_TYPE * @see #EXTRA_VOLUME_STREAM_VALUE + * @see #EXTRA_PREV_VOLUME_STREAM_VALUE */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String VOLUME_CHANGED_ACTION = "android.media.VOLUME_CHANGED_ACTION"; @@ -126,6 +127,12 @@ public class AudioManager { public static final String EXTRA_VOLUME_STREAM_VALUE = "android.media.EXTRA_VOLUME_STREAM_VALUE"; + /** + * @hide The previous volume associated with the stream for the volume changed intent. + */ + public static final String EXTRA_PREV_VOLUME_STREAM_VALUE = + "android.media.EXTRA_PREV_VOLUME_STREAM_VALUE"; + /** The audio stream for phone calls */ public static final int STREAM_VOICE_CALL = AudioSystem.STREAM_VOICE_CALL; /** The audio stream for system sounds */ diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index bde8a473cfcec..668917e6ef8d9 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -403,30 +403,34 @@ public class AudioService extends IAudioService.Stub { // UI mVolumePanel.postVolumeChanged(streamType, flags); // Broadcast Intent - sendVolumeUpdate(streamType); + sendVolumeUpdate(streamType, oldIndex, streamState.mIndex); } /** @see AudioManager#setStreamVolume(int, int, int) */ public void setStreamVolume(int streamType, int index, int flags) { ensureValidStreamType(streamType); + + final int oldIndex = mStreamStates[STREAM_VOLUME_ALIAS[streamType]].mIndex; + index = rescaleIndex(index * 10, streamType, STREAM_VOLUME_ALIAS[streamType]); setStreamVolumeInt(STREAM_VOLUME_ALIAS[streamType], index, false, true); // UI, etc. mVolumePanel.postVolumeChanged(streamType, flags); // Broadcast Intent - sendVolumeUpdate(streamType); + sendVolumeUpdate(streamType, oldIndex, index); } - private void sendVolumeUpdate(int streamType) { + private void sendVolumeUpdate(int streamType, int oldIndex, int index) { + oldIndex = (oldIndex + 5) / 10; + index = (index + 5) / 10; + Intent intent = new Intent(AudioManager.VOLUME_CHANGED_ACTION); intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, streamType); - intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, getStreamVolume(streamType)); + intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index); + intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex); - // Currently, sending the intent only when the stream is BLUETOOTH_SCO - if (streamType == AudioSystem.STREAM_BLUETOOTH_SCO) { - mContext.sendBroadcast(intent); - } + mContext.sendBroadcast(intent); } /**