AudioManager: Add support for master mute
Change-Id: I98e87d1e266e0523c4aacb23cc5c4b3fdc7a1eac Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -91,6 +91,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
private static final int MSG_VIBRATE = 4;
|
||||
private static final int MSG_TIMEOUT = 5;
|
||||
private static final int MSG_RINGER_MODE_CHANGED = 6;
|
||||
private static final int MSG_MUTE_CHANGED = 7;
|
||||
|
||||
// Pseudo stream type for master volume
|
||||
private static final int STREAM_MASTER = -100;
|
||||
@@ -295,8 +296,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
|
||||
private boolean isMuted(int streamType) {
|
||||
if (streamType == STREAM_MASTER) {
|
||||
// master volume mute not yet supported
|
||||
return false;
|
||||
return mAudioService.isMasterMute();
|
||||
} else {
|
||||
return mAudioService.isStreamMute(streamType);
|
||||
}
|
||||
@@ -328,8 +328,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
|
||||
private int getLastAudibleStreamVolume(int streamType) {
|
||||
if (streamType == STREAM_MASTER) {
|
||||
// master volume mute not yet supported
|
||||
return getStreamVolume(STREAM_MASTER);
|
||||
return mAudioService.getLastAudibleMasterVolume();
|
||||
} else {
|
||||
return mAudioService.getLastAudibleStreamVolume(streamType);
|
||||
}
|
||||
@@ -460,6 +459,19 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
postVolumeChanged(STREAM_MASTER, flags);
|
||||
}
|
||||
|
||||
public void postMuteChanged(int streamType, int flags) {
|
||||
if (hasMessages(MSG_VOLUME_CHANGED)) return;
|
||||
if (mStreamControls == null) {
|
||||
createSliders();
|
||||
}
|
||||
removeMessages(MSG_FREE_RESOURCES);
|
||||
obtainMessage(MSG_MUTE_CHANGED, streamType, flags).sendToTarget();
|
||||
}
|
||||
|
||||
public void postMasterMuteChanged(int flags) {
|
||||
postMuteChanged(STREAM_MASTER, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if you have other work to do when the volume changes (for
|
||||
* example, vibrating, playing a sound, etc.). Make sure to call through to
|
||||
@@ -493,6 +505,18 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
resetTimeout();
|
||||
}
|
||||
|
||||
protected void onMuteChanged(int streamType, int flags) {
|
||||
|
||||
if (LOGD) Log.d(TAG, "onMuteChanged(streamType: " + streamType + ", flags: " + flags + ")");
|
||||
|
||||
StreamControl sc = mStreamControls.get(streamType);
|
||||
if (sc != null) {
|
||||
sc.icon.setImageResource(isMuted(sc.streamType) ? sc.iconMuteRes : sc.iconRes);
|
||||
}
|
||||
|
||||
onVolumeChanged(streamType, flags);
|
||||
}
|
||||
|
||||
protected void onShowVolumeChanged(int streamType, int flags) {
|
||||
int index = isMuted(streamType) ?
|
||||
getLastAudibleStreamVolume(streamType)
|
||||
@@ -693,6 +717,11 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_MUTE_CHANGED: {
|
||||
onMuteChanged(msg.arg1, msg.arg2);
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_FREE_RESOURCES: {
|
||||
onFreeResources();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user