Move engine loading out from the AudioPolicyManager
Separating loading of the APM Engine configuration from the APM
initialization. This opens the way for loading the engine
configuration from other sources than the XML file. The APM
receives an engine instance pre-loaded with the configuration on
its creation, regardless of the way the config data has been
obtained.
Bug: 205884982
Test: atest audiopolicy_tests
Test: atest audiosystem_tests
Test: atest audio_health_tests
Test: m audiopolicy_fuzzer
Change-Id: I5185d8e27fccf64ba14856d3a1f0ea07a47f02e0
Merged-In: I5185d8e27fccf64ba14856d3a1f0ea07a47f02e0
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index b558fed..e087d8a 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -5997,10 +5997,12 @@
}
AudioPolicyManager::AudioPolicyManager(const sp<const AudioPolicyConfig>& config,
+ EngineInstance&& engine,
AudioPolicyClientInterface *clientInterface)
:
mUidCached(AID_AUDIOSERVER), // no need to call getuid(), there's only one of us running.
mConfig(config),
+ mEngine(std::move(engine)),
mpClientInterface(clientInterface),
mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f),
mA2dpSuspended(false),
@@ -6015,18 +6017,8 @@
}
status_t AudioPolicyManager::initialize() {
- {
- auto engLib = EngineLibrary::load(
- "libaudiopolicyengine" + mConfig->getEngineLibraryNameSuffix() + ".so");
- if (!engLib) {
- ALOGE("%s: Failed to load the engine library", __FUNCTION__);
- return NO_INIT;
- }
- mEngine = engLib->createEngine();
- if (mEngine == nullptr) {
- ALOGE("%s: Failed to instantiate the APM engine", __FUNCTION__);
- return NO_INIT;
- }
+ if (mEngine == nullptr) {
+ return NO_INIT;
}
mEngine->setObserver(this);
status_t status = mEngine->initCheck();