Plumb APM configuration retrieval from HAL
Add 'AudioHwModule' and 'AudioPolicyConfig' AIDL types
to represent the APM configuration. Add 'getAudioPolicyConfig'
method to 'IAudioFlinger' interface. Implement it for
the AIDL HAL case. Add missing method to 'DeviceHalInterface'.
Remove 'isSpeakerDrcEnabled' from 'AudioPolicyConfig'
as it is not used anywhere in the framework.
Bug: 205884982
Test: atest audiopolicy_tests
Test: atest audiosystem_tests
Test: atest audio_health_tests
Test: m audiopolicy_fuzzer
Change-Id: Icaf043085373ec661be37d4a7a5ed4356aeb4bbe
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index f69307b..ab197f8 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -111,6 +111,7 @@
using media::IEffectClient;
using media::audio::common::AudioMMapPolicyInfo;
using media::audio::common::AudioMMapPolicyType;
+using media::audio::common::AudioMode;
using android::content::AttributionSourceState;
using android::detail::AudioHalVersionInfo;
@@ -236,6 +237,7 @@
BINDER_METHOD_ENTRY(isBluetoothVariableLatencyEnabled) \
BINDER_METHOD_ENTRY(supportsBluetoothVariableLatency) \
BINDER_METHOD_ENTRY(getSoundDoseInterface) \
+BINDER_METHOD_ENTRY(getAudioPolicyConfig) \
// singleton for Binder Method Statistics for IAudioFlinger
static auto& getIAudioFlingerStatistics() {
@@ -2573,6 +2575,47 @@
// ----------------------------------------------------------------------------
+status_t AudioFlinger::getAudioPolicyConfig(media::AudioPolicyConfig *config)
+{
+ if (config == nullptr) {
+ return BAD_VALUE;
+ }
+ Mutex::Autolock _l(mLock);
+ AutoMutex lock(mHardwareLock);
+ RETURN_STATUS_IF_ERROR(
+ mDevicesFactoryHal->getSurroundSoundConfig(&config->surroundSoundConfig));
+ RETURN_STATUS_IF_ERROR(mDevicesFactoryHal->getEngineConfig(&config->engineConfig));
+ std::vector<std::string> hwModuleNames;
+ RETURN_STATUS_IF_ERROR(mDevicesFactoryHal->getDeviceNames(&hwModuleNames));
+ std::set<AudioMode> allSupportedModes;
+ for (const auto& name : hwModuleNames) {
+ AudioHwDevice* module = loadHwModule_l(name.c_str());
+ if (module == nullptr) continue;
+ media::AudioHwModule aidlModule;
+ if (module->hwDevice()->getAudioPorts(&aidlModule.ports) == OK &&
+ module->hwDevice()->getAudioRoutes(&aidlModule.routes) == OK) {
+ aidlModule.handle = module->handle();
+ aidlModule.name = module->moduleName();
+ config->modules.push_back(std::move(aidlModule));
+ }
+ std::vector<AudioMode> supportedModes;
+ if (module->hwDevice()->getSupportedModes(&supportedModes) == OK) {
+ allSupportedModes.insert(supportedModes.begin(), supportedModes.end());
+ }
+ }
+ if (!allSupportedModes.empty()) {
+ config->supportedModes.insert(config->supportedModes.end(),
+ allSupportedModes.begin(), allSupportedModes.end());
+ } else {
+ ALOGW("%s: The HAL does not provide telephony functionality", __func__);
+ config->supportedModes = { media::audio::common::AudioMode::NORMAL,
+ media::audio::common::AudioMode::RINGTONE,
+ media::audio::common::AudioMode::IN_CALL,
+ media::audio::common::AudioMode::IN_COMMUNICATION };
+ }
+ return OK;
+}
+
audio_module_handle_t AudioFlinger::loadHwModule(const char *name)
{
if (name == NULL) {
@@ -2583,16 +2626,17 @@
}
Mutex::Autolock _l(mLock);
AutoMutex lock(mHardwareLock);
- return loadHwModule_l(name);
+ AudioHwDevice* module = loadHwModule_l(name);
+ return module != nullptr ? module->handle() : AUDIO_MODULE_HANDLE_NONE;
}
// loadHwModule_l() must be called with AudioFlinger::mLock and AudioFlinger::mHardwareLock held
-audio_module_handle_t AudioFlinger::loadHwModule_l(const char *name)
+AudioHwDevice* 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);
+ return mAudioHwDevs.valueAt(i);
}
}
@@ -2601,7 +2645,7 @@
int rc = mDevicesFactoryHal->openDevice(name, &dev);
if (rc) {
ALOGE("loadHwModule() error %d loading module %s", rc, name);
- return AUDIO_MODULE_HANDLE_NONE;
+ return nullptr;
}
if (!mMelReporter->activateHalSoundDoseComputation(name, dev)) {
ALOGW("loadHwModule() sound dose reporting is not available");
@@ -2612,7 +2656,7 @@
mHardwareStatus = AUDIO_HW_IDLE;
if (rc) {
ALOGE("loadHwModule() init check error %d for module %s", rc, name);
- return AUDIO_MODULE_HANDLE_NONE;
+ return nullptr;
}
// Check and cache this HAL's level of support for master mute and master
@@ -2686,8 +2730,7 @@
ALOGI("loadHwModule() Loaded %s audio interface, handle %d", name, handle);
- return handle;
-
+ return audioDevice;
}
// ----------------------------------------------------------------------------
@@ -4729,6 +4772,7 @@
case TransactionCode::SET_REQUESTED_LATENCY_MODE:
case TransactionCode::GET_SUPPORTED_LATENCY_MODES:
case TransactionCode::INVALIDATE_TRACKS:
+ case TransactionCode::GET_AUDIO_POLICY_CONFIG:
ALOGW("%s: transaction %d received from PID %d",
__func__, code, IPCThreadState::self()->getCallingPid());
// return status only for non void methods