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.
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 70c27c2..32c5c23 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -87,10 +87,11 @@
/**
* @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 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 bde8a47..668917e 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -403,30 +403,34 @@
// 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);
}
/**