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
Merged-In: Icaf043085373ec661be37d4a7a5ed4356aeb4bbe
diff --git a/media/libaudiohal/impl/DeviceHalAidl.cpp b/media/libaudiohal/impl/DeviceHalAidl.cpp
index e452a35..3079d91 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalAidl.cpp
@@ -107,8 +107,26 @@
return cpp;
}
+template<typename T>
+std::shared_ptr<T> retrieveSubInterface(const std::shared_ptr<IModule>& module,
+ ::ndk::ScopedAStatus (IModule::*getT)(std::shared_ptr<T>*)) {
+ if (module != nullptr) {
+ std::shared_ptr<T> instance;
+ if (auto status = (module.get()->*getT)(&instance); status.isOk()) {
+ return instance;
+ }
+ }
+ return nullptr;
+}
+
} // namespace
+DeviceHalAidl::DeviceHalAidl(const std::string& instance, const std::shared_ptr<IModule>& module)
+ : ConversionHelperAidl("DeviceHalAidl"),
+ mInstance(instance), mModule(module),
+ mTelephony(retrieveSubInterface<ITelephony>(module, &IModule::getTelephony)) {
+}
+
status_t DeviceHalAidl::getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) {
auto convertAudioPortFromMap = [](const Ports::value_type& pair) {
return ndk2cpp_AudioPort(pair.second);
@@ -124,6 +142,22 @@
return OK;
}
+status_t DeviceHalAidl::getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) {
+ TIME_CHECK();
+ if (modes == nullptr) {
+ return BAD_VALUE;
+ }
+ if (mModule == nullptr) return NO_INIT;
+ if (mTelephony == nullptr) return INVALID_OPERATION;
+ std::vector<AudioMode> aidlModes;
+ RETURN_STATUS_IF_ERROR(
+ statusTFromBinderStatus(mTelephony->getSupportedAudioModes(&aidlModes)));
+ *modes = VALUE_OR_RETURN_STATUS(
+ ::aidl::android::convertContainer<std::vector<media::audio::common::AudioMode>>(
+ aidlModes, ndk2cpp_AudioMode));
+ return OK;
+}
+
status_t DeviceHalAidl::getSupportedDevices(uint32_t*) {
// Obsolete.
return INVALID_OPERATION;
@@ -175,17 +209,14 @@
status_t DeviceHalAidl::setVoiceVolume(float volume) {
TIME_CHECK();
if (!mModule) return NO_INIT;
- std::shared_ptr<ITelephony> telephony;
- if (ndk::ScopedAStatus status = mModule->getTelephony(&telephony);
- status.isOk() && telephony != nullptr) {
- ITelephony::TelecomConfig inConfig{ .voiceVolume = Float{volume} }, outConfig;
- RETURN_STATUS_IF_ERROR(
- statusTFromBinderStatus(telephony->setTelecomConfig(inConfig, &outConfig)));
- ALOGW_IF(outConfig.voiceVolume.has_value() && volume != outConfig.voiceVolume.value().value,
- "%s: the resulting voice volume %f is not the same as requested %f",
- __func__, outConfig.voiceVolume.value().value, volume);
- }
- return INVALID_OPERATION;
+ if (mTelephony == nullptr) return INVALID_OPERATION;
+ ITelephony::TelecomConfig inConfig{ .voiceVolume = Float{volume} }, outConfig;
+ RETURN_STATUS_IF_ERROR(
+ statusTFromBinderStatus(mTelephony->setTelecomConfig(inConfig, &outConfig)));
+ ALOGW_IF(outConfig.voiceVolume.has_value() && volume != outConfig.voiceVolume.value().value,
+ "%s: the resulting voice volume %f is not the same as requested %f",
+ __func__, outConfig.voiceVolume.value().value, volume);
+ return OK;
}
status_t DeviceHalAidl::setMasterVolume(float volume) {
@@ -204,10 +235,8 @@
TIME_CHECK();
if (!mModule) return NO_INIT;
AudioMode audioMode = VALUE_OR_FATAL(::aidl::android::legacy2aidl_audio_mode_t_AudioMode(mode));
- std::shared_ptr<ITelephony> telephony;
- if (ndk::ScopedAStatus status = mModule->getTelephony(&telephony);
- status.isOk() && telephony != nullptr) {
- RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(telephony->switchAudioMode(audioMode)));
+ if (mTelephony != nullptr) {
+ RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mTelephony->switchAudioMode(audioMode)));
}
return statusTFromBinderStatus(mModule->updateAudioMode(audioMode));
}