audio: capEngine: Allow built-in strategies to omit the 'id' attribute
For builtin strategy, the "id" must be set from the name.
These builtin strategies must be provisionned in the structure file.
The parameters associated to these strategies will use their legacy
name (whereas vendor strategies are referred with "vx_<id>".
Bug: 390449625
Test: m
Change-Id: I63763f1e05f1ca2cdd7e3163d2e0c4e6b3979446
Signed-off-by: François Gaffie <francois.gaffie@ampere.cars>
diff --git a/audio/aidl/default/CapEngineConfigXmlConverter.cpp b/audio/aidl/default/CapEngineConfigXmlConverter.cpp
index 20fbca4..14d27f2 100644
--- a/audio/aidl/default/CapEngineConfigXmlConverter.cpp
+++ b/audio/aidl/default/CapEngineConfigXmlConverter.cpp
@@ -52,6 +52,7 @@
static constexpr const char* gOutputDevicesParameter = "selected_output_devices";
static constexpr const char* gOutputDeviceAddressParameter = "device_address";
static constexpr const char* gStrategyPrefix = "vx_";
+static constexpr const char* gLegacyStrategyPrefix = "STRATEGY_";
static constexpr const char* gLegacyOutputDevicePrefix = "AUDIO_DEVICE_OUT_";
static constexpr const char* gLegacyInputDevicePrefix = "AUDIO_DEVICE_IN_";
static constexpr const char* gLegacyStreamPrefix = "AUDIO_STREAM_";
@@ -159,6 +160,17 @@
}
return strategyId;
}
+ pos = stringToken.find(gLegacyStrategyPrefix);
+ if (pos != std::string::npos) {
+ std::string legacyStrategyIdLiteral = stringToken.substr(pos);
+ const auto legacyStrategies = getLegacyProductStrategyMap();
+ if (const auto& it = legacyStrategies.find(legacyStrategyIdLiteral);
+ it != legacyStrategies.end()) {
+ return it->second;
+ }
+ LOG(ERROR) << "Invalid legacy strategy " << stringToken << " from path " << path;
+ return unexpected(BAD_VALUE);
+ }
}
return unexpected(BAD_VALUE);
}
diff --git a/audio/aidl/default/EngineConfigXmlConverter.cpp b/audio/aidl/default/EngineConfigXmlConverter.cpp
index d945b17..78deb64 100644
--- a/audio/aidl/default/EngineConfigXmlConverter.cpp
+++ b/audio/aidl/default/EngineConfigXmlConverter.cpp
@@ -59,20 +59,6 @@
static constexpr char kCapEngineConfigFileName[] =
"/parameter-framework/Settings/Policy/PolicyConfigurableDomains.xml";
-void EngineConfigXmlConverter::initProductStrategyMap() {
-#define STRATEGY_ENTRY(name) {"STRATEGY_" #name, static_cast<int>(AudioProductStrategyType::name)}
-
- mProductStrategyMap = {STRATEGY_ENTRY(MEDIA),
- STRATEGY_ENTRY(PHONE),
- STRATEGY_ENTRY(SONIFICATION),
- STRATEGY_ENTRY(SONIFICATION_RESPECTFUL),
- STRATEGY_ENTRY(DTMF),
- STRATEGY_ENTRY(ENFORCED_AUDIBLE),
- STRATEGY_ENTRY(TRANSMITTED_THROUGH_SPEAKER),
- STRATEGY_ENTRY(ACCESSIBILITY)};
-#undef STRATEGY_ENTRY
-}
-
ConversionResult<int> EngineConfigXmlConverter::convertProductStrategyNameToAidl(
const std::string& xsdcProductStrategyName) {
const auto [it, success] = mProductStrategyMap.insert(
@@ -242,7 +228,7 @@
}
void EngineConfigXmlConverter::init() {
- initProductStrategyMap();
+ mProductStrategyMap = getLegacyProductStrategyMap();
if (getXsdcConfig()->hasProductStrategies()) {
mAidlEngineConfig.productStrategies = VALUE_OR_FATAL(
(convertWrappedCollectionToAidl<eng_xsd::ProductStrategies,
diff --git a/audio/aidl/default/XsdcConversion.cpp b/audio/aidl/default/XsdcConversion.cpp
index b42d7f5..5845903 100644
--- a/audio/aidl/default/XsdcConversion.cpp
+++ b/audio/aidl/default/XsdcConversion.cpp
@@ -816,4 +816,23 @@
}
return aidlCurvePoint;
}
+
+/**
+ * The hard coded id must be in sync with policy.h definition of legacy strategy ids.
+ */
+std::unordered_map<std::string, int> getLegacyProductStrategyMap() {
+#define STRATEGY_ENTRY(name, id) {"STRATEGY_" #name, static_cast<int>(id)}
+
+ return {STRATEGY_ENTRY(MEDIA, 5),
+ STRATEGY_ENTRY(PHONE, 0),
+ STRATEGY_ENTRY(SONIFICATION, 1),
+ STRATEGY_ENTRY(SONIFICATION_RESPECTFUL, 4),
+ STRATEGY_ENTRY(DTMF, 6),
+ STRATEGY_ENTRY(ENFORCED_AUDIBLE, 2),
+ STRATEGY_ENTRY(CALL_ASSISTANT, 7),
+ STRATEGY_ENTRY(TRANSMITTED_THROUGH_SPEAKER,8),
+ STRATEGY_ENTRY(ACCESSIBILITY, 3)};
+#undef STRATEGY_ENTRY
+}
+
} // namespace aidl::android::hardware::audio::core::internal
diff --git a/audio/aidl/default/include/core-impl/XsdcConversion.h b/audio/aidl/default/include/core-impl/XsdcConversion.h
index f00206b..b298eee 100644
--- a/audio/aidl/default/include/core-impl/XsdcConversion.h
+++ b/audio/aidl/default/include/core-impl/XsdcConversion.h
@@ -64,4 +64,5 @@
const engineconfiguration::Stream& xsdStreamType);
ConversionResult<int32_t> convertAudioFlagsToAidl(
const std::vector<engineconfiguration::FlagType>& xsdcFlagTypeVec);
+std::unordered_map<std::string, int> getLegacyProductStrategyMap();
} // namespace aidl::android::hardware::audio::core::internal