1. 从AudioService.java 的方法入手,
doSetMasterVolume(),主要干了三件事,
1)AudioSystem.setMasterVolume(volume);
2)sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME, SENDMSG_REPLACE, Math.round(volume * (float)1000.0), 0, null, PERSIST_DELAY);
3)sendMasterVolumeUpdate(flags, oldVolume, newVolume);
private void doSetMasterVolume(float volume, int flags) {
// don't allow changing master volume when muted
if (!AudioSystem.getMasterMute()) {
int oldVolume = getMasterVolume();
A<span style="background-color: rgb(102, 255, 255);">udioSystem.setMasterVolume(volume);</span>
int newVolume = getMasterVolume();
if (newVolume != oldVolume) {
// Post a persist master volume msg
<span style="background-color: rgb(102, 255, 255);">sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME, SENDMSG_REPLACE,</span>
Math.round(volume * (float)1000.0), 0, null, PERSIST_DELAY);
setSystemAudioVolume(oldVolume, newVolume, getMasterMaxVolume(), flags);
}
// Send the volume update regardless whether there was a change.
<span style="background-color: rgb(102, 255, 255);">sendMasterVolumeUpdate(flags, oldVolume, newVolume);</span>
}
}