Merge "Fix issue 2440226: Car dock volume synchronization."
This commit is contained in:
committed by
Android (Google) Code Review
commit
afdf85d435
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user