Fix parsing of legacy engine config XML files
The change aosp/3020124 adds a requirement for having
an 'id' field for product strategies. However, legacy
XML configuration files lack it. In order to preserve
compatibility, attempt to parse the string name of
the strategy in order to assign it the corresponding id.
Bug: 376030167
Test: atest audiopolicy_tests
Change-Id: I57a69f0507ef0bd4d06957e69b3fbe81b7febf40
diff --git a/services/audiopolicy/tests/audiopolicymanager_tests.cpp b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
index 5278b73..3662ddf 100644
--- a/services/audiopolicy/tests/audiopolicymanager_tests.cpp
+++ b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
@@ -185,6 +185,7 @@
void SetUp() override;
void TearDown() override;
virtual void SetUpManagerConfig();
+ virtual std::string getEngineConfigFilePath() const { return sTestEngineConfig; }
void dumpToLog();
// When explicit routing is needed, selectedDeviceId needs to be set as the wanted port
@@ -223,6 +224,7 @@
const std::string &address, audio_port_v7 *foundPort);
static audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch* patch);
virtual AudioPolicyManagerTestClient* getClient() { return new AudioPolicyManagerTestClient; }
+ void verifyBuiltInStrategyIdsAreValid();
sp<AudioPolicyConfig> mConfig;
std::unique_ptr<AudioPolicyManagerTestClient> mClient;
@@ -237,7 +239,7 @@
void AudioPolicyManagerTest::SetUp() {
mClient.reset(getClient());
ASSERT_NO_FATAL_FAILURE(SetUpManagerConfig()); // Subclasses may want to customize the config.
- mManager.reset(new AudioPolicyTestManager(mConfig, mClient.get(), sTestEngineConfig));
+ mManager.reset(new AudioPolicyTestManager(mConfig, mClient.get(), getEngineConfigFilePath()));
ASSERT_EQ(NO_ERROR, mManager->initialize());
ASSERT_EQ(NO_ERROR, mManager->initCheck());
}
@@ -397,6 +399,16 @@
return AUDIO_PORT_HANDLE_NONE;
}
+void AudioPolicyManagerTest::verifyBuiltInStrategyIdsAreValid() {
+ AudioProductStrategyVector strategies;
+ ASSERT_EQ(NO_ERROR, mManager->listAudioProductStrategies(strategies));
+ for (const auto& strategy : strategies) {
+ // Since ids are unsigned, this will also cover the case when the id is 'NONE' which is -1.
+ EXPECT_LT(strategy.getId(),
+ media::audio::common::AudioHalProductStrategy::VENDOR_STRATEGY_ID_START)
+ << strategy.getName();
+ }
+}
TEST_F(AudioPolicyManagerTest, InitSuccess) {
// SetUp must finish with no assertions.
@@ -454,6 +466,20 @@
// TODO: Add patch creation tests that involve already existing patch
+TEST_F(AudioPolicyManagerTest, BuiltInStrategyIdsAreValid) {
+ verifyBuiltInStrategyIdsAreValid();
+}
+
+class AudioPolicyManagerTestWithDefaultEngineConfig : public AudioPolicyManagerTest {
+ protected:
+ // The APM will use the default engine config from EngineDefaultConfig.h.
+ std::string getEngineConfigFilePath() const override { return ""; }
+};
+
+TEST_F(AudioPolicyManagerTestWithDefaultEngineConfig, BuiltInStrategyIdsAreValid) {
+ verifyBuiltInStrategyIdsAreValid();
+}
+
enum
{
MSD_AUDIO_PATCH_COUNT_NUM_AUDIO_PATCHES_INDEX = 0,