可执行文件
./system/bin/audioserver 在手机里面可以找到这个文件

这是生成 audioserver 的信息

frameworks/av/media/audioserver/main_audioserver.cpp
    AudioFlinger::instantiate();
AudioPolicyService::instantiate();
IPCThreadState::self()->joinThreadPool();

初始化 AudioFlinger AudioPolicyService
加入线程池 joinThreadPool

frameworks/av/media/audioserver/Android.mk
LOCAL_MODULE := audioserver
LOCAL_INIT_RC := audioserver.rc
LOCAL_CFLAGS := -Werror -Wall
include $(BUILD_EXECUTABLE) //生成可执行文件 ./system/bin/audioserver
frameworks/av/services/audiopolicy/service/AudioPolicyService.cpp 看出audiopolicy创建

BnAudioPolicyService(), mpAudioPolicyDev(NULL), mpAudioPolicy(NULL),

mAudioPolicyManager(NULL), mAudioPolicyClient(NULL), mPhoneState(AUDIO_MODE_INVALID)

{

}

void AudioPolicyService::onFirstRef()
{
{
Mutex::Autolock _l(mLock);
    // start tone playback thread
mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this);
// start audio commands thread
mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this);
// start output activity command thread
mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this); //创建 3条线程

mAudioPolicyClient = new AudioPolicyClient(this);
mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
}
// load audio processing modules
sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects();
{
Mutex::Autolock _l(mLock);
mAudioPolicyEffects = audioPolicyEffects;
}
}
// 这个似乎没用解析audiopolicy.so
frameworks/av/services/audiopolicy/AudioPolicyInterface.h 这个函数定义了 audiopolicy.so 的接口audiosystem 调用 aps 的 setDeviceConnectionState
status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
audio_policy_dev_state_t state,
const char *device_address,
const char *device_name)
{
const sp& aps = AudioSystem::get_audio_policy_service();
const char *address = “”;
const char *name = “”;
if (aps == 0) return PERMISSION_DENIED;

if (device_address != NULL) {
address = device_address;
}
if (device_name != NULL) {
name = device_name;
}
return aps->setDeviceConnectionState(device, state, address, name);
}
audiosystem 调用 aps 的createAudioPatch
status_t AudioSystem::createAudioPatch(const struct audio_patch *patch,
audio_patch_handle_t *handle)
{
const sp& aps = AudioSystem::get_audio_policy_service();
if (aps == 0) return PERMISSION_DENIED;
return aps->createAudioPatch(patch, handle);
}