1.AudioService::adjustStreamVolume
private void adjustStreamVolume(int streamType, int direction, int flags,
String callingPackage, String caller, int uid) {
......
//finally update notify systemui to update
int index = mStreamStates[streamType].getIndex(device);
sendVolumeUpdate(streamType, oldIndex, index, flags);
2.flags一定要是奇数才能显示UI,对应Audiomanager 中public static final int FLAG_SHOW_UI = 1 << 0;
// UI update and Broadcast Intent
protected void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags) {
streamType = mStreamVolumeAlias[streamType];
if (streamType == AudioSystem.STREAM_MUSIC) {
flags = updateFlagsForSystemAudio(flags);
}
mVolumeController.postVolumeChanged(streamType, flags);
}
3.mVolumeController是AudioService的内部类VolumeController,封装了VolumeDialogControllerImpl,也就是mController,这是SystemUI启动的时候通过AudioManager的setVolumeController设置的。
public void postVolumeChanged(int streamType, int flags) {
if (mController == null)
return;
try {
mController.volumeChanged(streamType, flags);
} catch (RemoteException e) {
Log.w(TAG, "Error calling volumeChanged", e);
}
}
4.SystemUI VolumeDialogControllerImpl内部类的VC
private final class VC extends IVolumeController.Stub {
...
@Override
public void volumeChanged(int streamType, int flags) throws RemoteException {
if (D.BUG) Log.d(TAG, "volumeChanged " + AudioSystem.streamToString(streamType)
+ " " + Util.audioManagerFlagsToString(flags));