audiopolicy: Fix crash in getMsdPatches
Added a missing check for the possibility of not having an MSD module.
Remove a check for the module handle, as mHwModules by design
can't contain modules with AUDIO_MODULE_HANDLE_NONE (see
AudioPolicyManager::initialize).
Bug: 117253728
Test: see the repro steps in the bug
Change-Id: Ia8761a2e3ceccf9595b672c8ba48e086b457e3ae
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 088bcaa..c6d0a8b 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1110,16 +1110,16 @@
const AudioPatchCollection AudioPolicyManager::getMsdPatches() const {
AudioPatchCollection msdPatches;
- audio_module_handle_t msdModuleHandle = mHwModules.getModuleFromName(
- AUDIO_HARDWARE_MODULE_ID_MSD)->getHandle();
- if (msdModuleHandle == AUDIO_MODULE_HANDLE_NONE) return msdPatches;
- for (size_t i = 0; i < mAudioPatches.size(); ++i) {
- sp<AudioPatch> patch = mAudioPatches.valueAt(i);
- for (size_t j = 0; j < patch->mPatch.num_sources; ++j) {
- const struct audio_port_config *source = &patch->mPatch.sources[j];
- if (source->type == AUDIO_PORT_TYPE_DEVICE &&
- source->ext.device.hw_module == msdModuleHandle) {
- msdPatches.addAudioPatch(patch->mHandle, patch);
+ sp<HwModule> msdModule = mHwModules.getModuleFromName(AUDIO_HARDWARE_MODULE_ID_MSD);
+ if (msdModule != 0) {
+ for (size_t i = 0; i < mAudioPatches.size(); ++i) {
+ sp<AudioPatch> patch = mAudioPatches.valueAt(i);
+ for (size_t j = 0; j < patch->mPatch.num_sources; ++j) {
+ const struct audio_port_config *source = &patch->mPatch.sources[j];
+ if (source->type == AUDIO_PORT_TYPE_DEVICE &&
+ source->ext.device.hw_module == msdModule->getHandle()) {
+ msdPatches.addAudioPatch(patch->mHandle, patch);
+ }
}
}
}