Bug fix on Engine Configurable

This patch fixes a couple of issue within audio policy engine configurable
 -valgrind error detected within the parsing of the configuration file
 -configuration file typos
 -start of the PFW delayed to the init in order to wait the full construction
of the engine object
 -wrong specialization of template functions.
 -broadcast volume min / max init to stream collection of manager & PFW

Change-Id: I08823ab4040c92b719747c60cc3fa5c8b5f172ac
Signed-off-by: François Gaffie <francois.gaffie@intel.com>
diff --git a/services/audiopolicy/engineconfigurable/src/Engine.cpp b/services/audiopolicy/engineconfigurable/src/Engine.cpp
index 61fae71..733cdf6 100755
--- a/services/audiopolicy/engineconfigurable/src/Engine.cpp
+++ b/services/audiopolicy/engineconfigurable/src/Engine.cpp
@@ -87,11 +87,6 @@
       mPolicyParameterMgr(new ParameterManagerWrapper()),
       mApmObserver(NULL)
 {
-    if (mPolicyParameterMgr->start() != NO_ERROR) {
-        ALOGE("%s: could not start Policy PFW", __FUNCTION__);
-        delete mPolicyParameterMgr;
-        mPolicyParameterMgr = NULL;
-    }
 }
 
 Engine::~Engine()
@@ -111,10 +106,13 @@
 
 status_t Engine::initCheck()
 {
-    return (mPolicyParameterMgr != NULL) &&
-            mPolicyParameterMgr->isStarted() &&
-            (mApmObserver != NULL)?
-                NO_ERROR : NO_INIT;
+    if (mPolicyParameterMgr != NULL && mPolicyParameterMgr->start() != NO_ERROR) {
+        ALOGE("%s: could not start Policy PFW", __FUNCTION__);
+        delete mPolicyParameterMgr;
+        mPolicyParameterMgr = NULL;
+        return NO_INIT;
+    }
+    return (mApmObserver != NULL)? NO_ERROR : NO_INIT;
 }
 
 bool Engine::setVolumeProfileForStream(const audio_stream_type_t &streamType,
@@ -143,19 +141,6 @@
     return collection.add(name, key);
 }
 
-template <>
-routing_strategy Engine::getPropertyForKey<routing_strategy, audio_usage_t>(audio_usage_t usage) const
-{
-    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
-
-    if (usage == AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY &&
-            (outputs.isStreamActive(AUDIO_STREAM_RING) ||
-             outputs.isStreamActive(AUDIO_STREAM_ALARM))) {
-        return STRATEGY_SONIFICATION;
-    }
-    return getPropertyForKey<routing_strategy, audio_usage_t>(usage);
-}
-
 template <typename Property, typename Key>
 Property Engine::getPropertyForKey(Key key) const
 {
@@ -167,10 +152,21 @@
     return element->template get<Property>();
 }
 
-template <>
-audio_devices_t Engine::getPropertyForKey<audio_devices_t, routing_strategy>(routing_strategy strategy) const
+routing_strategy Engine::ManagerInterfaceImpl::getStrategyForUsage(audio_usage_t usage)
 {
-    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
+    const SwAudioOutputCollection &outputs = mPolicyEngine->mApmObserver->getOutputs();
+
+    if (usage == AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY &&
+            (outputs.isStreamActive(AUDIO_STREAM_RING) ||
+             outputs.isStreamActive(AUDIO_STREAM_ALARM))) {
+        return STRATEGY_SONIFICATION;
+    }
+    return mPolicyEngine->getPropertyForKey<routing_strategy, audio_usage_t>(usage);
+}
+
+audio_devices_t Engine::ManagerInterfaceImpl::getDeviceForStrategy(routing_strategy strategy) const
+{
+    const SwAudioOutputCollection &outputs = mPolicyEngine->mApmObserver->getOutputs();
 
     /** This is the only case handled programmatically because the PFW is unable to know the
      * activity of streams.
@@ -187,19 +183,9 @@
             !outputs.isStreamActiveRemotely(AUDIO_STREAM_MUSIC,
                                     SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY) &&
             outputs.isStreamActive(AUDIO_STREAM_MUSIC, SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY)) {
-        return getPropertyForKey<audio_devices_t, routing_strategy>(STRATEGY_MEDIA);
+        return mPolicyEngine->getPropertyForKey<audio_devices_t, routing_strategy>(STRATEGY_MEDIA);
     }
-    return getPropertyForKey<audio_devices_t, routing_strategy>(strategy);
-}
-
-routing_strategy Engine::ManagerInterfaceImpl::getStrategyForUsage(audio_usage_t usage)
-{
-    return mPolicyEngine->getPropertyForKey<routing_strategy, audio_usage_t>(usage);
-}
-
-audio_devices_t Engine::ManagerInterfaceImpl::getDeviceForStrategy(routing_strategy stategy) const
-{
-    return mPolicyEngine->getPropertyForKey<audio_devices_t, routing_strategy>(stategy);
+    return mPolicyEngine->getPropertyForKey<audio_devices_t, routing_strategy>(strategy);
 }
 
 template <typename Property, typename Key>
@@ -233,6 +219,9 @@
         ALOGE("%s: Stream Type %d not found", __FUNCTION__, streamType);
         return BAD_TYPE;
     }
+    mApmObserver->getStreamDescriptors().setVolumeIndexMin(streamType, indexMin);
+    mApmObserver->getStreamDescriptors().setVolumeIndexMax(streamType, indexMax);
+
     return stream->initVolume(indexMin, indexMax);
 }