1. 整个加载流程图
2. 加载hal so的代码位置
2.1 在audiopolicymanager中的加载位置
diff --git a/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 632290a933..54ead728ea 100644
--- a/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -4110,6 +4110,7 @@ status_t AudioPolicyManager::initialize() {audio_devices_t inputDeviceTypes = mAvailableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN;for (const auto& hwModule : mHwModulesAll) {hwModule->setHandle(mpClientInterface->loadHwModule(hwModule->getName()));
+ ALOGW("===weiqifa=== loadHwModule() %s", hwModule->getName());if (hwModule->getHandle() == AUDIO_MODULE_HANDLE_NONE) {ALOGW("could not open HW module %s", hwModule->getName());continue;
2.2 在audioflinger中加载
AudioFlinger.cpp
audio_module_handle_t AudioFlinger::loadHwModule(const char *name)
{if (name == NULL) {return AUDIO_MODULE_HANDLE_NONE;}if (!settingsAllowed()) {return AUDIO_MODULE_HANDLE_NONE;}Mutex::Autolock _l(mLock);return loadHwModule_l(name);
}// loadHwModule_l() must be called with AudioFlinger::mLock held
audio_module_handle_t AudioFlinger::loadHwModule_l(const char *name)
{for (size_t i = 0; i < mAudioHwDevs.size(); i++) {if (strncmp(mAudioHwDevs.valueAt(i)->moduleName(), name, strlen(name)) == 0) {ALOGW("loadHwModule() module %s already loaded", name);return mAudioHwDevs.keyAt(i);}}sp<DeviceHalInterface> dev;int rc = mDevicesFactoryHal->openDevice(name, &dev);if (rc) {ALOGE("loadHwModule() error %d loading module %s", rc, name);return AUDIO_MODULE_HANDLE_NONE;}mHardwareStatus = AUDIO_HW_INIT;rc = dev->initCheck();mHardwareStatus = AUDIO_HW_IDLE;if (rc) {ALOGE("loadHwModule() init check error %d for module %s", rc, name);return AUDIO_MODULE_HANDLE_NONE;}// Check and cache this HAL's level of support for master mute and master// volume. If this is the first HAL opened, and it supports the get// methods, use the initial values provided by the HAL as the current// master mute and volume settings.AudioHwDevice::Flags flags = static_cast<AudioHwDevice::Flags>(0);{ // scope for auto-lock patternAutoMutex lock(mHardwareLock);if (0 == mAudioHwDevs.size()) {mHardwareStatus = AUDIO_HW_GET_MASTER_VOLUME;float mv;if (OK == dev->getMasterVolume(&mv)) {mMasterVolume = mv;}mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE;bool mm;if (OK == dev->getMasterMute(&mm)) {mMasterMute = mm;}}mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;if (OK == dev->setMasterVolume(mMasterVolume)) {flags = static_cast<AudioHwDevice::Flags>(flags |AudioHwDevice::AHWD_CAN_SET_MASTER_VOLUME);}mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;if (OK == dev->setMasterMute(mMasterMute)) {flags = static_cast<AudioHwDevice::Flags>(flags |AudioHwDevice::AHWD_CAN_SET_MASTER_MUTE);}mHardwareStatus = AUDIO_HW_IDLE;}audio_module_handle_t handle = (audio_module_handle_t) nextUniqueId(AUDIO_UNIQUE_ID_USE_MODULE);mAudioHwDevs.add(handle, new AudioHwDevice(handle, name, dev, flags));ALOGI("loadHwModule() Loaded %s audio interface, handle %d", name, handle);return handle;}
3. 开机日志
# logcat |grep loadHwModule278 278 I AudioFlinger: loadHwModule() Loaded primary audio interface, handle 10278 278 I AudioFlinger: loadHwModule() Loaded a2dp audio interface, handle 18278 278 I AudioFlinger: loadHwModule() Loaded r_submix audio interface, handle 26
4. so 在系统的位置
0:/ # find / -iname *primary*.so 2>/dev/nul
/vendor/lib/hw/audio.primary.default.so
/vendor/lib/hw/audio.primary.mt8167.so
/vendor/lib/libaudioprimarydevicehalifclient.so
1|Knowin inSight10:/ #