1.AudioManager的API
frameworks/base/media/java/android/media/AudioManager.java
public void handleKeyDown(){
adjustSuggestedStreamVolume();
}
public void adjustSuggestedStreamVolume(){
service.adjustSuggestedStreamVolume();
}
2.AudioService调用
frameworks/base/media/java/android/media/AudioService.java
public void adjustSuggestedStreamVolume(){
adjustStreamVolume(streamType, direction, flags, callingPackage);
}
public void adjustStreamVolume(){
}
public void handleMessage(){
case MSG_SET_DEVICE_VOLUME:
setDeviceVolume();
}
private void setDeviceVolume(){
mStreamStates[streamType].applyDeviceVolume(device);
}
public void applyDeviceVolume(){
AudioSystem.setStreamVolumeIndex(mStreamType, index, device);
}
3.调用AudioSystem接口
frameworks/base/media/java/android/media/AudioSystem.java
public static native int setStreamVolumeIndex();
frameworks/av/media/libmedia/AudioSystem.cpp
status_t AudioSystem::setStreamVolumeIndex(){
return aps->setStreamVolumeIndex();
}
4.服务端
frameworks/av/services/audioflinger/AudioPolicyService.cpp
status_t AudioPolicyService::setStreamVolumeIndex(){
return mpAudioPolicy->set_stream_volume_index();
}
hardware/libhardware_legacy/audio/audio_policy_hal.cpp
static int ap_set_stream_volume_index(){
return lap->apm->setStreamVolumeIndex();
}
hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp
status_t AudioPolicyManagerBase::setStreamVolumeIndex(){
checkAndSetVolume();
}
status_t AudioPolicyManagerBase::checkAndSetVolume(){
float volume = computeVolume();
mpClientInterface->setStreamVolume();
}
hardware/libhardware_legacy/audio/AudioPolicyCompatClient.cpp
void AudioPolicyCompatClient::setStreamVolume(){
return mServiceOps->set_stream_volume();
}
frameworks/av/services/audioflinger/AudioPolicyService.cpp
static int aps_set_stream_volume(){
return audioPolicyService->setStreamVolume();
}
int AudioPolicyService::setStreamVolume(){
return (int)mAudioCommandThread->volumeCommand();
}
bool AudioPolicyService::AudioCommandThread::threadLoop(){
case SET_VOLUME:{
AudioSystem::setStreamVolume();
}
}
frameworks/av/media/libmedia/AudioSystem.cpp
status_t AudioSystem::setStreamVolume(){
af->setStreamVolume();
}
frameworks/av/services/audioflinger/AudioFlinger.cpp
status_t AudioFlinger::setStreamVolume(){
mPlaybackThreads.valueAt(i)->setStreamVolume();
}