Display a fixed volume silder when docked.

Align UI indication to volume policy when docked: the music volume
cannot be adjusted when docked or connected to HDMI. Display
a disabled slider at max volume in this case to be consistent.

Bug 4335692.

Change-Id: I6f8db143b0e2ecf54e4bdacd88afdeb661a98a18
This commit is contained in:
Eric Laurent
2012-09-24 14:26:30 -07:00
committed by Jean-Baptiste Queru
parent 3b772c6b67
commit 4bbcc65497
3 changed files with 126 additions and 86 deletions

View File

@@ -699,9 +699,12 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
if (sc.seekbarView.getMax() != max) { if (sc.seekbarView.getMax() != max) {
sc.seekbarView.setMax(max); sc.seekbarView.setMax(max);
} }
sc.seekbarView.setProgress(index); sc.seekbarView.setProgress(index);
if (streamType != mAudioManager.getMasterStreamType() if (((flags & AudioManager.FLAG_FIXED_VOLUME) != 0) ||
&& streamType != AudioService.STREAM_REMOTE_MUSIC && isMuted(streamType)) { (streamType != mAudioManager.getMasterStreamType() &&
streamType != AudioService.STREAM_REMOTE_MUSIC &&
isMuted(streamType))) {
sc.seekbarView.setEnabled(false); sc.seekbarView.setEnabled(false);
} else { } else {
sc.seekbarView.setEnabled(true); sc.seekbarView.setEnabled(true);

View File

@@ -313,6 +313,13 @@ public class AudioManager {
*/ */
public static final int FLAG_VIBRATE = 1 << 4; public static final int FLAG_VIBRATE = 1 << 4;
/**
* Indicates to VolumePanel that the volume slider should be disabled as user
* cannot change the stream volume
* @hide
*/
public static final int FLAG_FIXED_VOLUME = 1 << 5;
/** /**
* Ringer mode that will be silent and will not vibrate. (This overrides the * Ringer mode that will be silent and will not vibrate. (This overrides the
* vibrate setting.) * vibrate setting.)

View File

@@ -424,6 +424,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
*/ */
public final static int STREAM_REMOTE_MUSIC = -200; public final static int STREAM_REMOTE_MUSIC = -200;
// Devices for which the volume is fixed and VolumePanel slider should be disabled
final int mFixedVolumeDevices = AudioSystem.DEVICE_OUT_AUX_DIGITAL |
AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET |
AudioSystem.DEVICE_OUT_ALL_USB;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Construction // Construction
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@@ -762,58 +767,66 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
return; return;
} }
// If either the client forces allowing ringer modes for this adjustment,
// or the stream type is one that is affected by ringer modes
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
(streamTypeAlias == getMasterStreamType())) {
int ringerMode = getRingerMode();
// do not vibrate if already in vibrate mode
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
flags &= ~AudioManager.FLAG_VIBRATE;
}
// Check if the ringer mode changes with this volume adjustment. If
// it does, it will handle adjusting the volume, so we won't below
adjustVolume = checkForRingerModeChange(aliasIndex, direction, step);
if ((streamTypeAlias == getMasterStreamType()) &&
(mRingerMode == AudioManager.RINGER_MODE_SILENT)) {
streamState.setLastAudibleIndex(0, device);
}
}
// If stream is muted, adjust last audible index only
int index; int index;
final int oldIndex = mStreamStates[streamType].getIndex(device, int oldIndex;
(mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
if (streamState.muteCount() != 0) { if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) &&
if (adjustVolume) { ((device & mFixedVolumeDevices) != 0)) {
// Post a persist volume msg flags |= AudioManager.FLAG_FIXED_VOLUME;
// no need to persist volume on all streams sharing the same alias index = mStreamStates[streamType].getMaxIndex();
streamState.adjustLastAudibleIndex(direction * step, device); oldIndex = index;
sendMsg(mAudioHandler,
MSG_PERSIST_VOLUME,
SENDMSG_QUEUE,
PERSIST_LAST_AUDIBLE,
device,
streamState,
PERSIST_DELAY);
}
index = mStreamStates[streamType].getIndex(device, true /* lastAudible */);
} else { } else {
if (adjustVolume && streamState.adjustIndex(direction * step, device)) { // If either the client forces allowing ringer modes for this adjustment,
// Post message to set system volume (it in turn will post a message // or the stream type is one that is affected by ringer modes
// to persist). Do not change volume if stream is muted. if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
sendMsg(mAudioHandler, (streamTypeAlias == getMasterStreamType())) {
MSG_SET_DEVICE_VOLUME, int ringerMode = getRingerMode();
SENDMSG_QUEUE, // do not vibrate if already in vibrate mode
device, if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
0, flags &= ~AudioManager.FLAG_VIBRATE;
streamState, }
0); // Check if the ringer mode changes with this volume adjustment. If
// it does, it will handle adjusting the volume, so we won't below
adjustVolume = checkForRingerModeChange(aliasIndex, direction, step);
if ((streamTypeAlias == getMasterStreamType()) &&
(mRingerMode == AudioManager.RINGER_MODE_SILENT)) {
streamState.setLastAudibleIndex(0, device);
}
} }
index = mStreamStates[streamType].getIndex(device, false /* lastAudible */);
}
// If stream is muted, adjust last audible index only
oldIndex = mStreamStates[streamType].getIndex(device,
(mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
if (streamState.muteCount() != 0) {
if (adjustVolume) {
// Post a persist volume msg
// no need to persist volume on all streams sharing the same alias
streamState.adjustLastAudibleIndex(direction * step, device);
sendMsg(mAudioHandler,
MSG_PERSIST_VOLUME,
SENDMSG_QUEUE,
PERSIST_LAST_AUDIBLE,
device,
streamState,
PERSIST_DELAY);
}
index = mStreamStates[streamType].getIndex(device, true /* lastAudible */);
} else {
if (adjustVolume && streamState.adjustIndex(direction * step, device)) {
// Post message to set system volume (it in turn will post a message
// to persist). Do not change volume if stream is muted.
sendMsg(mAudioHandler,
MSG_SET_DEVICE_VOLUME,
SENDMSG_QUEUE,
device,
0,
streamState,
0);
}
index = mStreamStates[streamType].getIndex(device, false /* lastAudible */);
}
}
sendVolumeUpdate(streamType, oldIndex, index, flags); sendVolumeUpdate(streamType, oldIndex, index, flags);
} }
@@ -839,40 +852,47 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
VolumeStreamState streamState = mStreamStates[mStreamVolumeAlias[streamType]]; VolumeStreamState streamState = mStreamStates[mStreamVolumeAlias[streamType]];
final int device = getDeviceForStream(streamType); final int device = getDeviceForStream(streamType);
int oldIndex;
// get last audible index if stream is muted, current index otherwise if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
final int oldIndex = streamState.getIndex(device, ((device & mFixedVolumeDevices) != 0)) {
(streamState.muteCount() != 0) /* lastAudible */); flags |= AudioManager.FLAG_FIXED_VOLUME;
index = mStreamStates[streamType].getMaxIndex();
oldIndex = index;
} else {
// get last audible index if stream is muted, current index otherwise
oldIndex = streamState.getIndex(device,
(streamState.muteCount() != 0) /* lastAudible */);
index = rescaleIndex(index * 10, streamType, mStreamVolumeAlias[streamType]); index = rescaleIndex(index * 10, streamType, mStreamVolumeAlias[streamType]);
if (!checkSafeMediaVolume(mStreamVolumeAlias[streamType], index, device)) { if (!checkSafeMediaVolume(mStreamVolumeAlias[streamType], index, device)) {
return; return;
}
// setting volume on master stream type also controls silent mode
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
(mStreamVolumeAlias[streamType] == getMasterStreamType())) {
int newRingerMode;
if (index == 0) {
newRingerMode = mHasVibrator ? AudioManager.RINGER_MODE_VIBRATE
: AudioManager.RINGER_MODE_SILENT;
setStreamVolumeInt(mStreamVolumeAlias[streamType],
index,
device,
false,
true);
} else {
newRingerMode = AudioManager.RINGER_MODE_NORMAL;
} }
setRingerMode(newRingerMode);
// setting volume on master stream type also controls silent mode
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
(mStreamVolumeAlias[streamType] == getMasterStreamType())) {
int newRingerMode;
if (index == 0) {
newRingerMode = mHasVibrator ? AudioManager.RINGER_MODE_VIBRATE
: AudioManager.RINGER_MODE_SILENT;
setStreamVolumeInt(mStreamVolumeAlias[streamType],
index,
device,
false,
true);
} else {
newRingerMode = AudioManager.RINGER_MODE_NORMAL;
}
setRingerMode(newRingerMode);
}
setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, false, true);
// get last audible index if stream is muted, current index otherwise
index = mStreamStates[streamType].getIndex(device,
(mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
} }
setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, false, true);
// get last audible index if stream is muted, current index otherwise
index = mStreamStates[streamType].getIndex(device,
(mStreamStates[streamType].muteCount() != 0) /* lastAudible */);
sendVolumeUpdate(streamType, oldIndex, index, flags); sendVolumeUpdate(streamType, oldIndex, index, flags);
} }
@@ -988,13 +1008,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
mVolumePanel.postVolumeChanged(streamType, flags); mVolumePanel.postVolumeChanged(streamType, flags);
oldIndex = (oldIndex + 5) / 10; if ((flags & AudioManager.FLAG_FIXED_VOLUME) == 0) {
index = (index + 5) / 10; oldIndex = (oldIndex + 5) / 10;
Intent intent = new Intent(AudioManager.VOLUME_CHANGED_ACTION); index = (index + 5) / 10;
intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, streamType); Intent intent = new Intent(AudioManager.VOLUME_CHANGED_ACTION);
intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index); intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, streamType);
intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex); intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index);
sendBroadcastToAll(intent); intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
sendBroadcastToAll(intent);
}
} }
// UI update and Broadcast Intent // UI update and Broadcast Intent
@@ -1109,7 +1131,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
public int getStreamVolume(int streamType) { public int getStreamVolume(int streamType) {
ensureValidStreamType(streamType); ensureValidStreamType(streamType);
int device = getDeviceForStream(streamType); int device = getDeviceForStream(streamType);
return (mStreamStates[streamType].getIndex(device, false /* lastAudible */) + 5) / 10; int index;
if ((mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
(device & mFixedVolumeDevices) != 0) {
index = mStreamStates[streamType].getMaxIndex();
} else {
index = mStreamStates[streamType].getIndex(device, false /* lastAudible */);
}
return (index + 5) / 10;
} }
public int getMasterVolume() { public int getMasterVolume() {