Merge "Revert "Fix M Issue on configurable policy engine version.""
diff --git a/services/audiopolicy/engineconfigurable/Android.mk b/services/audiopolicy/engineconfigurable/Android.mk
index 1cec54c..0b13085 100755
--- a/services/audiopolicy/engineconfigurable/Android.mk
+++ b/services/audiopolicy/engineconfigurable/Android.mk
@@ -1,4 +1,3 @@
-ifeq ($(USE_CONFIGURABLE_AUDIO_POLICY), 1)
 
 LOCAL_PATH := $(call my-dir)
 
@@ -58,5 +57,3 @@
 # Recursive call sub-folder Android.mk
 #
 include $(call all-makefiles-under,$(LOCAL_PATH))
-
-endif
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/example/Android.mk b/services/audiopolicy/engineconfigurable/parameter-framework/example/Android.mk
index 866ecc0..98b7152 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/example/Android.mk
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/example/Android.mk
@@ -10,11 +10,6 @@
 
 LOCAL_PATH := $(call my-dir)
 
-PFW_CORE := external/parameter-framework
-BUILD_PFW_SETTINGS := $(PFW_CORE)/support/android/build_pfw_settings.mk
-PFW_DEFAULT_SCHEMAS_DIR := $(PFW_CORE)/Schemas
-PFW_SCHEMAS_DIR := $(PFW_DEFAULT_SCHEMAS_DIR)
-
 ##################################################################
 # CONFIGURATION FILES
 ##################################################################
@@ -70,19 +65,26 @@
 
 ######### Policy PFW Settings #########
 
+######## Generate routing domains file ########
 include $(CLEAR_VARS)
 LOCAL_MODULE := parameter-framework.policy
 LOCAL_MODULE_STEM := PolicyConfigurableDomains.xml
-LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_RELATIVE_PATH := parameter-framework/Settings/Policy
-LOCAL_ADDITIONAL_DEPENDENCIES := \
+LOCAL_MODULE_TAGS := optional
+LOCAL_REQUIRED_MODULES := \
         PolicyClass.xml \
         PolicySubsystem.xml \
         ParameterFrameworkConfigurationPolicy.xml
 
-PFW_TOPLEVEL_FILE := $(TARGET_OUT_ETC)/parameter-framework/ParameterFrameworkConfigurationPolicy.xml
-PFW_CRITERIA_FILE := $(LOCAL_PATH)/policy_criteria.txt
-PFW_EDD_FILES := \
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/parameter-framework/Settings/Policy
+include $(BUILD_SYSTEM)/base_rules.mk
+
+$(LOCAL_BUILT_MODULE): MY_TOOL := $(HOST_OUT_EXECUTABLES)/hostDomainGenerator.sh
+$(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/hostDomainGenerator.sh
+$(LOCAL_BUILT_MODULE): MY_SRC_FILES := \
+        $(TARGET_OUT_ETC)/parameter-framework/ParameterFrameworkConfigurationPolicy.xml \
+        $(LOCAL_PATH)/policy_criteria.txt \
+        /dev/null \
         $(LOCAL_PATH)/Settings/device_for_strategy_media.pfw \
         $(LOCAL_PATH)/Settings/device_for_strategy_phone.pfw \
         $(LOCAL_PATH)/Settings/device_for_strategy_sonification.pfw \
@@ -95,6 +97,8 @@
         $(LOCAL_PATH)/Settings/strategy_for_stream.pfw \
         $(LOCAL_PATH)/Settings/strategy_for_usage.pfw \
         $(LOCAL_PATH)/Settings/device_for_input_source.pfw \
-        $(LOCAL_PATH)/Settings/volumes.pfw
+        $(LOCAL_PATH)/Settings/volumes.pfw \
 
-include $(BUILD_PFW_SETTINGS)
+$(LOCAL_BUILT_MODULE): $(LOCAL_REQUIRED_MODULES)
+	$(hide) mkdir -p $(dir $@)
+	bash --debug $(MY_TOOL) --nonverbose --validate $(MY_SRC_FILES) > $@
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/example/policy_criteria.txt b/services/audiopolicy/engineconfigurable/parameter-framework/example/policy_criteria.txt
index ef06498..3b3151c 100755
--- a/services/audiopolicy/engineconfigurable/parameter-framework/example/policy_criteria.txt
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/example/policy_criteria.txt
@@ -1,9 +1,14 @@
 ExclusiveCriterion TelephonyMode                :   Normal          RingTone                InCall              InCommunication
+
 InclusiveCriterion AvailableInputDevices        :   Communication Ambient BuiltinMic BluetoothScoHeadset WiredHeadset Hdmi TelephonyRx BackMic RemoteSubmix AnlgDockHeadset DgtlDockHeadset UsbAccessory UsbDevice FmTuner TvTuner Line Spdif BluetoothA2dp Loopback
+
 InclusiveCriterion AvailableOutputDevices       :   Earpiece Speaker WiredSpeaker WiredHeadset WiredHeadphone BluetoothSco BluetoothScoHeadset BluetoothScoCarkit BluetoothA2dp BluetoothA2dpHeadphones BluetoothA2dpSpeaker Hdmi AnlgDockHeadset DgtlDockHeadset UsbAccessory UsbDevice RemoteSubmix TelephonyTx Line HdmiArc Spdif Fm AuxLine SpeakerSafe
+
 ExclusiveCriterion ForceUseForCommunication     :   ForceNone       ForceSpeaker            ForceBtSco
 ExclusiveCriterion ForceUseForMedia             :   ForceNone       ForceSpeaker			ForceHeadphones         ForceBtA2dp         ForceWiredAccessory ForceAnalogDock ForceDigitalDock    ForceNoBtA2dp       ForceSystemEnforced
 ExclusiveCriterion ForceUseForRecord            :   ForceNone       ForceBtSco              ForceWiredAccessory
 ExclusiveCriterion ForceUseForDock              :   ForceNone       ForceWiredAccessory     ForceBtCarDock      ForceBtDeskDock     ForceAnalogDock ForceDigitalDock
 ExclusiveCriterion ForceUseForSystem            :   ForceNone       ForceSystemEnforced
 ExclusiveCriterion ForceUseForHdmiSystemAudio   :   ForceNone       ForceHdmiSystemEnforced
+
+
diff --git a/services/audiopolicy/engineconfigurable/src/Engine.cpp b/services/audiopolicy/engineconfigurable/src/Engine.cpp
index 61fae71..c5cccfd 100755
--- a/services/audiopolicy/engineconfigurable/src/Engine.cpp
+++ b/services/audiopolicy/engineconfigurable/src/Engine.cpp
@@ -146,7 +146,7 @@
 template <>
 routing_strategy Engine::getPropertyForKey<routing_strategy, audio_usage_t>(audio_usage_t usage) const
 {
-    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
+    const AudioOutputCollection &outputs = mApmObserver->getOutputs();
 
     if (usage == AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY &&
             (outputs.isStreamActive(AUDIO_STREAM_RING) ||
@@ -170,7 +170,7 @@
 template <>
 audio_devices_t Engine::getPropertyForKey<audio_devices_t, routing_strategy>(routing_strategy strategy) const
 {
-    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();
+    const AudioOutputCollection &outputs = mApmObserver->getOutputs();
 
     /** This is the only case handled programmatically because the PFW is unable to know the
      * activity of streams.
@@ -213,7 +213,7 @@
     return element->template set<Property>(property) == NO_ERROR;
 }
 
-float Engine::volIndexToDb(Volume::device_category category,
+float Engine::volIndexToAmpl(Volume::device_category category,
                              audio_stream_type_t streamType,
                              int indexInUi)
 {
@@ -222,7 +222,7 @@
         ALOGE("%s: Element indexed by key=%d not found", __FUNCTION__, streamType);
         return 1.0f;
     }
-    return stream->volIndexToDb(category, indexInUi);
+    return stream->volIndexToAmpl(category, indexInUi);
 }
 
 status_t Engine::initStreamVolume(audio_stream_type_t streamType,
diff --git a/services/audiopolicy/engineconfigurable/src/Engine.h b/services/audiopolicy/engineconfigurable/src/Engine.h
index 6fa7a13..23ca7d0 100755
--- a/services/audiopolicy/engineconfigurable/src/Engine.h
+++ b/services/audiopolicy/engineconfigurable/src/Engine.h
@@ -97,11 +97,11 @@
 
         virtual void initializeVolumeCurves(bool /*isSpeakerDrcEnabled*/) {}
 
-        virtual float volIndexToDb(Volume::device_category deviceCategory,
+        virtual float volIndexToAmpl(Volume::device_category deviceCategory,
                                      audio_stream_type_t stream,
                                      int indexInUi)
         {
-            return mPolicyEngine->volIndexToDb(deviceCategory, stream, indexInUi);
+            return mPolicyEngine->volIndexToAmpl(deviceCategory, stream, indexInUi);
         }
 
     private:
@@ -183,9 +183,9 @@
     status_t setDeviceConnectionState(audio_devices_t devices, audio_policy_dev_state_t state,
                                       const char *deviceAddress);
 
-    float volIndexToDb(Volume::device_category category,
-                       audio_stream_type_t stream,
-                       int indexInUi);
+    float volIndexToAmpl(Volume::device_category category,
+                         audio_stream_type_t stream,
+                         int indexInUi);
     status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
 
     StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */
diff --git a/services/audiopolicy/engineconfigurable/src/Stream.cpp b/services/audiopolicy/engineconfigurable/src/Stream.cpp
index 378d592..7126c27 100755
--- a/services/audiopolicy/engineconfigurable/src/Stream.cpp
+++ b/services/audiopolicy/engineconfigurable/src/Stream.cpp
@@ -91,7 +91,7 @@
     return NO_ERROR;
 }
 
-float Element<audio_stream_type_t>::volIndexToDb(Volume::device_category deviceCategory,
+float Element<audio_stream_type_t>::volIndexToAmpl(Volume::device_category deviceCategory,
                                                    int indexInUi)
 {
     VolumeProfileConstIterator it = mVolumeProfiles.find(deviceCategory);
@@ -140,14 +140,17 @@
                     ((float)(curve[segment+1].mIndex -
                             curve[segment].mIndex)) );
 
+    float amplification = exp(decibels * 0.115129f); /** exp( dB * ln(10) / 20 ) */
+
     ALOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
             curve[segment].mIndex, volIdx,
             curve[segment+1].mIndex,
             curve[segment].mDBAttenuation,
             decibels,
-            curve[segment+1].mDBAttenuation);
+            curve[segment+1].mDBAttenuation,
+            amplification);
 
-    return decibels;
+    return amplification;
 }
 
 } // namespace audio_policy
diff --git a/services/audiopolicy/engineconfigurable/src/Stream.h b/services/audiopolicy/engineconfigurable/src/Stream.h
index 8c39dc6..03a9b3e9 100755
--- a/services/audiopolicy/engineconfigurable/src/Stream.h
+++ b/services/audiopolicy/engineconfigurable/src/Stream.h
@@ -81,7 +81,7 @@
 
     status_t setVolumeProfile(Volume::device_category category, const VolumeCurvePoints &points);
 
-    float volIndexToDb(Volume::device_category deviceCategory, int indexInUi);
+    float volIndexToAmpl(Volume::device_category deviceCategory, int indexInUi);
 
     status_t initVolume(int indexMin, int indexMax);