summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/engineconfigurable/wrapper
diff options
context:
space:
mode:
authorFrançois Gaffie <francois.gaffie@intel.com>2015-03-24 09:01:14 +0100
committerEric Laurent <elaurent@google.com>2015-04-24 14:57:55 -0700
commit65c3781db3443531deacecfbda5c7e7e82868a34 (patch)
tree5560072d1f61a9d76e437ef311ef282976fc253d /services/audiopolicy/engineconfigurable/wrapper
parent21db57282da8b3daba1549f3a8e41c4fbaf80059 (diff)
downloadframeworks_av-65c3781db3443531deacecfbda5c7e7e82868a34.zip
frameworks_av-65c3781db3443531deacecfbda5c7e7e82868a34.tar.gz
frameworks_av-65c3781db3443531deacecfbda5c7e7e82868a34.tar.bz2
Add a configurable version of the policy engine based on PFW
This patch adds a configurable version of the policy engine based on the parameter framework. This configurable engine shall be activated with a flag USE_CONFIGURABLE_AUDIO_POLICY within BoardConfig.mk This patch provides the generic configuration as an example. This configuration provides the same user experience as the default policy engine. Change-Id: Ic8217333ae370b89bfdd2ad11320c5f14ea4da34 Signed-off-by: François Gaffie <francois.gaffie@intel.com>
Diffstat (limited to 'services/audiopolicy/engineconfigurable/wrapper')
-rw-r--r--services/audiopolicy/engineconfigurable/wrapper/Android.mk42
-rwxr-xr-xservices/audiopolicy/engineconfigurable/wrapper/ParameterManagerWrapper.cpp434
-rwxr-xr-xservices/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h71
-rwxr-xr-xservices/audiopolicy/engineconfigurable/wrapper/config/audio_policy_criteria.conf192
-rwxr-xr-xservices/audiopolicy/engineconfigurable/wrapper/include/ParameterManagerWrapper.h286
5 files changed, 1025 insertions, 0 deletions
diff --git a/services/audiopolicy/engineconfigurable/wrapper/Android.mk b/services/audiopolicy/engineconfigurable/wrapper/Android.mk
new file mode 100644
index 0000000..5373613
--- /dev/null
+++ b/services/audiopolicy/engineconfigurable/wrapper/Android.mk
@@ -0,0 +1,42 @@
+LOCAL_PATH:= $(call my-dir)
+
+##################################################################
+# WRAPPER LIBRARY
+##################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/include \
+ $(TARGET_OUT_HEADERS)/parameter \
+ $(TOPDIR)frameworks/av/services/audiopolicy/engineconfigurable/include \
+ $(TOPDIR)frameworks/av/services/audiopolicy/engineconfigurable/interface \
+
+LOCAL_SRC_FILES:= ParameterManagerWrapper.cpp
+
+LOCAL_STATIC_LIBRARIES := \
+ libmedia_helper \
+ libutilities_convert
+
+LOCAL_MODULE:= libaudiopolicypfwwrapper
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wall -Werror -Wextra
+
+include external/stlport/libstlport.mk
+
+include $(BUILD_STATIC_LIBRARY)
+
+##################################################################
+# CONFIGURATION FILE
+##################################################################
+
+# specific management of audio_policy_criteria.conf
+include $(CLEAR_VARS)
+LOCAL_MODULE := audio_policy_criteria.conf
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
+LOCAL_SRC_FILES := config/$(LOCAL_MODULE)
+include $(BUILD_PREBUILT)
diff --git a/services/audiopolicy/engineconfigurable/wrapper/ParameterManagerWrapper.cpp b/services/audiopolicy/engineconfigurable/wrapper/ParameterManagerWrapper.cpp
new file mode 100755
index 0000000..9dda20c
--- /dev/null
+++ b/services/audiopolicy/engineconfigurable/wrapper/ParameterManagerWrapper.cpp
@@ -0,0 +1,434 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "APM::AudioPolicyEngine/PFWWrapper"
+
+#include "ParameterManagerWrapper.h"
+#include "audio_policy_criteria_conf.h"
+#include <ParameterMgrPlatformConnector.h>
+#include <SelectionCriterionTypeInterface.h>
+#include <SelectionCriterionInterface.h>
+#include <convert.h>
+#include <algorithm>
+#include <cutils/config_utils.h>
+#include <cutils/misc.h>
+#include <fstream>
+#include <limits>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <stdint.h>
+#include <cmath>
+#include <utils/Log.h>
+
+using std::string;
+using std::map;
+using std::vector;
+
+/// PFW related definitions
+// Logger
+class ParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger
+{
+public:
+ ParameterMgrPlatformConnectorLogger() {}
+
+ virtual void log(bool isWarning, const string &log)
+ {
+ const static string format("policy-parameter-manager: ");
+
+ if (isWarning) {
+ ALOGW("%s %s", format.c_str(), log.c_str());
+ } else {
+ ALOGD("%s %s", format.c_str(), log.c_str());
+ }
+ }
+};
+
+namespace android
+{
+
+using utilities::convertTo;
+
+namespace audio_policy
+{
+const char *const ParameterManagerWrapper::mPolicyPfwDefaultConfFileName =
+ "/etc/parameter-framework/ParameterFrameworkConfigurationPolicy.xml";
+
+template <>
+struct ParameterManagerWrapper::parameterManagerElementSupported<ISelectionCriterionInterface> {};
+template <>
+struct ParameterManagerWrapper::parameterManagerElementSupported<ISelectionCriterionTypeInterface> {};
+
+ParameterManagerWrapper::ParameterManagerWrapper()
+ : mPfwConnectorLogger(new ParameterMgrPlatformConnectorLogger)
+{
+ // Connector
+ mPfwConnector = new CParameterMgrPlatformConnector(mPolicyPfwDefaultConfFileName);
+
+ // Logger
+ mPfwConnector->setLogger(mPfwConnectorLogger);
+
+ // Load criteria file
+ if ((loadAudioPolicyCriteriaConfig(gAudioPolicyCriteriaVendorConfFilePath) != NO_ERROR) &&
+ (loadAudioPolicyCriteriaConfig(gAudioPolicyCriteriaConfFilePath) != NO_ERROR)) {
+ ALOGE("%s: Neither vendor conf file (%s) nor system conf file (%s) could be found",
+ __FUNCTION__, gAudioPolicyCriteriaVendorConfFilePath,
+ gAudioPolicyCriteriaConfFilePath);
+ }
+ ALOGD("%s: ParameterManagerWrapper instantiated!", __FUNCTION__);
+}
+
+ParameterManagerWrapper::~ParameterManagerWrapper()
+{
+ // Unset logger
+ mPfwConnector->setLogger(NULL);
+ // Remove logger
+ delete mPfwConnectorLogger;
+ // Remove connector
+ delete mPfwConnector;
+}
+
+status_t ParameterManagerWrapper::start()
+{
+ ALOGD("%s: in", __FUNCTION__);
+ /// Start PFW
+ std::string error;
+ if (!mPfwConnector->start(error)) {
+ ALOGE("%s: Policy PFW start error: %s", __FUNCTION__, error.c_str());
+ return NO_INIT;
+ }
+ ALOGD("%s: Policy PFW successfully started!", __FUNCTION__);
+ return NO_ERROR;
+}
+
+
+void ParameterManagerWrapper::addCriterionType(const string &typeName, bool isInclusive)
+{
+ ALOG_ASSERT(mPolicyCriterionTypes.find(typeName) == mPolicyCriterionTypes.end(),
+ "CriterionType " << typeName << " already added");
+ ALOGD("%s: Adding new criterionType %s", __FUNCTION__, typeName.c_str());
+
+ mPolicyCriterionTypes[typeName] = mPfwConnector->createSelectionCriterionType(isInclusive);
+}
+
+void ParameterManagerWrapper::addCriterionTypeValuePair(
+ const string &typeName,
+ uint32_t numericValue,
+ const string &literalValue)
+{
+ ALOG_ASSERT(mPolicyCriterionTypes.find(typeName) != mPolicyCriterionTypes.end(),
+ "CriterionType " << typeName.c_str() << "not found");
+ ALOGV("%s: Adding new value pair (%d,%s) for criterionType %s", __FUNCTION__,
+ numericValue, literalValue.c_str(), typeName.c_str());
+ ISelectionCriterionTypeInterface *criterionType = mPolicyCriterionTypes[typeName];
+ criterionType->addValuePair(numericValue, literalValue.c_str());
+}
+
+void ParameterManagerWrapper::loadCriterionType(cnode *root, bool isInclusive)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node;
+ for (node = root->first_child; node != NULL; node = node->next) {
+
+ ALOG_ASSERT(node != NULL, "error in parsing file");
+ const char *typeName = node->name;
+ char *valueNames = (char *)node->value;
+
+ addCriterionType(typeName, isInclusive);
+
+ uint32_t index = 0;
+ char *ctx;
+ char *valueName = strtok_r(valueNames, ",", &ctx);
+ while (valueName != NULL) {
+ if (strlen(valueName) != 0) {
+
+ // Conf file may use or not pair, if no pair, use incremental index, else
+ // use provided index.
+ if (strchr(valueName, ':') != NULL) {
+
+ char *first = strtok(valueName, ":");
+ char *second = strtok(NULL, ":");
+ ALOG_ASSERT((first != NULL) && (strlen(first) != 0) &&
+ (second != NULL) && (strlen(second) != 0),
+ "invalid value pair");
+
+ if (!convertTo<string, uint32_t>(first, index)) {
+ ALOGE("%s: Invalid index(%s) found", __FUNCTION__, first);
+ }
+ addCriterionTypeValuePair(typeName, index, second);
+ } else {
+
+ uint32_t pfwIndex = isInclusive ? 1 << index : index;
+ addCriterionTypeValuePair(typeName, pfwIndex, valueName);
+ index += 1;
+ }
+ }
+ valueName = strtok_r(NULL, ",", &ctx);
+ }
+ }
+}
+
+void ParameterManagerWrapper::loadInclusiveCriterionType(cnode *root)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node = config_find(root, gInclusiveCriterionTypeTag.c_str());
+ if (node == NULL) {
+ return;
+ }
+ loadCriterionType(node, true);
+}
+
+void ParameterManagerWrapper::loadExclusiveCriterionType(cnode *root)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node = config_find(root, gExclusiveCriterionTypeTag.c_str());
+ if (node == NULL) {
+ return;
+ }
+ loadCriterionType(node, false);
+}
+
+void ParameterManagerWrapper::parseChildren(cnode *root, string &defaultValue, string &type)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node;
+ for (node = root->first_child; node != NULL; node = node->next) {
+ ALOG_ASSERT(node != NULL, "error in parsing file");
+
+ if (string(node->name) == gDefaultTag) {
+ defaultValue = node->value;
+ } else if (string(node->name) == gTypeTag) {
+ type = node->value;
+ } else {
+ ALOGE("%s: Unrecognized %s %s node", __FUNCTION__, node->name, node->value);
+ }
+ }
+}
+
+template <typename T>
+T *ParameterManagerWrapper::getElement(const string &name, std::map<string, T *> &elementsMap)
+{
+ parameterManagerElementSupported<T>();
+ typename std::map<string, T *>::iterator it = elementsMap.find(name);
+ ALOG_ASSERT(it != elementsMap.end(), "Element " << name << " not found");
+ return it->second;
+}
+
+template <typename T>
+const T *ParameterManagerWrapper::getElement(const string &name, const std::map<string, T *> &elementsMap) const
+{
+ parameterManagerElementSupported<T>();
+ typename std::map<string, T *>::const_iterator it = elementsMap.find(name);
+ ALOG_ASSERT(it != elementsMap.end(), "Element " << name << " not found");
+ return it->second;
+}
+
+void ParameterManagerWrapper::loadCriteria(cnode *root)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node = config_find(root, gCriterionTag.c_str());
+
+ if (node == NULL) {
+ ALOGW("%s: no inclusive criteria found", __FUNCTION__);
+ return;
+ }
+ for (node = node->first_child; node != NULL; node = node->next) {
+ loadCriterion(node);
+ }
+}
+
+void ParameterManagerWrapper::addCriterion(const string &name, const string &typeName,
+ const string &defaultLiteralValue)
+{
+ ALOG_ASSERT(mPolicyCriteria.find(criterionName) == mPolicyCriteria.end(),
+ "Route Criterion " << criterionName << " already added");
+
+ ISelectionCriterionTypeInterface *criterionType =
+ getElement<ISelectionCriterionTypeInterface>(typeName, mPolicyCriterionTypes);
+
+ ISelectionCriterionInterface *criterion =
+ mPfwConnector->createSelectionCriterion(name, criterionType);
+
+ mPolicyCriteria[name] = criterion;
+ int numericalValue = 0;
+ if (!criterionType->getNumericalValue(defaultLiteralValue.c_str(), numericalValue)) {
+ ALOGE("%s; trying to apply invalid default literal value", __FUNCTION__,
+ defaultLiteralValue.c_str());
+ }
+ criterion->setCriterionState(numericalValue);
+}
+
+void ParameterManagerWrapper::loadCriterion(cnode *root)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ const char *criterionName = root->name;
+
+ ALOG_ASSERT(mPolicyCriteria.find(criterionName) == mPolicyCriteria.end(),
+ "Criterion " << criterionName << " already added");
+
+ string paramKeyName = "";
+ string path = "";
+ string typeName = "";
+ string defaultValue = "";
+
+ parseChildren(root, defaultValue, typeName);
+
+ addCriterion(criterionName, typeName, defaultValue);
+}
+
+void ParameterManagerWrapper::loadConfig(cnode *root)
+{
+ ALOG_ASSERT(root != NULL, "error in parsing file");
+ cnode *node = config_find(root, gPolicyConfTag.c_str());
+ if (node == NULL) {
+ ALOGW("%s: Could not find node for pfw", __FUNCTION__);
+ return;
+ }
+ ALOGD("%s: Loading conf for pfw", __FUNCTION__);
+ loadInclusiveCriterionType(node);
+ loadExclusiveCriterionType(node);
+ loadCriteria(node);
+}
+
+
+status_t ParameterManagerWrapper::loadAudioPolicyCriteriaConfig(const char *path)
+{
+ ALOG_ASSERT(path != NULL, "error in parsing file: empty path");
+ cnode *root;
+ char *data;
+ ALOGD("%s", __FUNCTION__);
+ data = (char *)load_file(path, NULL);
+ if (data == NULL) {
+ return -ENODEV;
+ }
+ root = config_node("", "");
+ ALOG_ASSERT(root != NULL, "Unable to allocate a configuration node");
+ config_load(root, data);
+
+ loadConfig(root);
+
+ config_free(root);
+ free(root);
+ free(data);
+ ALOGD("%s: loaded", __FUNCTION__);
+ return NO_ERROR;
+}
+
+bool ParameterManagerWrapper::isStarted()
+{
+ return mPfwConnector && mPfwConnector->isStarted();
+}
+
+status_t ParameterManagerWrapper::setPhoneState(audio_mode_t mode)
+{
+ ISelectionCriterionInterface *criterion = mPolicyCriteria[gPhoneStateCriterionTag];
+ if (!isValueValidForCriterion(criterion, static_cast<int>(mode))) {
+ return BAD_VALUE;
+ }
+ criterion->setCriterionState((int)(mode));
+ applyPlatformConfiguration();
+ return NO_ERROR;
+}
+
+audio_mode_t ParameterManagerWrapper::getPhoneState() const
+{
+ const ISelectionCriterionInterface *criterion =
+ getElement<ISelectionCriterionInterface>(gPhoneStateCriterionTag, mPolicyCriteria);
+ return static_cast<audio_mode_t>(criterion->getCriterionState());
+}
+
+status_t ParameterManagerWrapper::setForceUse(audio_policy_force_use_t usage,
+ audio_policy_forced_cfg_t config)
+{
+ // @todo: return an error on a unsupported value
+ if (usage > AUDIO_POLICY_FORCE_USE_CNT) {
+ return BAD_VALUE;
+ }
+
+ ISelectionCriterionInterface *criterion = mPolicyCriteria[gForceUseCriterionTag[usage]];
+ if (!isValueValidForCriterion(criterion, static_cast<int>(config))) {
+ return BAD_VALUE;
+ }
+ criterion->setCriterionState((int)config);
+ applyPlatformConfiguration();
+ return NO_ERROR;
+}
+
+audio_policy_forced_cfg_t ParameterManagerWrapper::getForceUse(audio_policy_force_use_t usage) const
+{
+ // @todo: return an error on a unsupported value
+ if (usage > AUDIO_POLICY_FORCE_USE_CNT) {
+ return AUDIO_POLICY_FORCE_NONE;
+ }
+ const ISelectionCriterionInterface *criterion =
+ getElement<ISelectionCriterionInterface>(gForceUseCriterionTag[usage], mPolicyCriteria);
+ return static_cast<audio_policy_forced_cfg_t>(criterion->getCriterionState());
+}
+
+bool ParameterManagerWrapper::isValueValidForCriterion(ISelectionCriterionInterface *criterion,
+ int valueToCheck)
+{
+ const ISelectionCriterionTypeInterface *interface = criterion->getCriterionType();
+ string literalValue;
+ return interface->getLiteralValue(valueToCheck, literalValue);
+}
+
+status_t ParameterManagerWrapper::setDeviceConnectionState(audio_devices_t devices,
+ audio_policy_dev_state_t state,
+ const char */*deviceAddres*/)
+{
+ ISelectionCriterionInterface *criterion = NULL;
+
+ if (audio_is_output_devices(devices)) {
+ criterion = mPolicyCriteria[gOutputDeviceCriterionTag];
+ } else if (devices & AUDIO_DEVICE_BIT_IN) {
+ criterion = mPolicyCriteria[gInputDeviceCriterionTag];
+ } else {
+ return BAD_TYPE;
+ }
+ if (criterion == NULL) {
+ ALOGE("%s: no criterion found for devices");
+ return DEAD_OBJECT;
+ }
+
+ int32_t previousDevices = criterion->getCriterionState();
+ switch (state)
+ {
+ case AUDIO_POLICY_DEVICE_STATE_AVAILABLE:
+ criterion->setCriterionState(previousDevices |= devices);
+ break;
+
+ case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE:
+ if (devices & AUDIO_DEVICE_BIT_IN) {
+ devices &= ~AUDIO_DEVICE_BIT_IN;
+ }
+ criterion->setCriterionState(previousDevices &= ~devices);
+ break;
+
+ default:
+ return BAD_VALUE;
+ }
+ applyPlatformConfiguration();
+ return NO_ERROR;
+}
+
+void ParameterManagerWrapper::applyPlatformConfiguration()
+{
+ mPfwConnector->applyConfigurations();
+}
+
+} // namespace audio_policy
+} // namespace android
diff --git a/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h b/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h
new file mode 100755
index 0000000..58e7135
--- /dev/null
+++ b/services/audiopolicy/engineconfigurable/wrapper/audio_policy_criteria_conf.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <system/audio_policy.h>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+// Definitions for audio policy criteria configuration file (audio_policy_criteria.conf) //
+// //
+// @TODO: scripted from audio.h & audio_policy,h //
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+static const char *const gAudioPolicyCriteriaConfFilePath =
+ "/system/etc/audio_policy_criteria.conf";
+static const char *const gAudioPolicyCriteriaVendorConfFilePath =
+ "/vendor/etc/audio_policy_criteria.conf";
+
+/**
+ * PFW instances tags
+ */
+static const std::string &gPolicyConfTag = "Policy";
+static const std::string &gDefaultTag = "Default";
+static const std::string &gTypeTag = "Type";
+
+/**
+ * PFW elements tags
+ */
+static const std::string &gInclusiveCriterionTypeTag = "InclusiveCriterionType";
+static const std::string &gExclusiveCriterionTypeTag = "ExclusiveCriterionType";
+static const std::string &gCriterionTag = "Criterion";
+
+/**
+ * PFW known criterion tags
+ */
+static const std::string &gInputDeviceCriterionTag = "AvailableInputDevices";
+static const std::string &gOutputDeviceCriterionTag = "AvailableOutputDevices";
+static const std::string &gPhoneStateCriterionTag = "TelephonyMode";
+
+/**
+ * Order MUST be align with defintiion of audio_policy_force_use_t within audio_policy.h
+ */
+static const std::string gForceUseCriterionTag[AUDIO_POLICY_FORCE_USE_CNT] =
+{
+ [AUDIO_POLICY_FORCE_FOR_COMMUNICATION] = "ForceUseForCommunication",
+ [AUDIO_POLICY_FORCE_FOR_MEDIA] = "ForceUseForMedia",
+ [AUDIO_POLICY_FORCE_FOR_RECORD] = "ForceUseForRecord",
+ [AUDIO_POLICY_FORCE_FOR_DOCK] = "ForceUseForDock",
+ [AUDIO_POLICY_FORCE_FOR_SYSTEM] = "ForceUseForSystem",
+ [AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO] = "ForceUseForHdmiSystemAudio"
+};
+
+
+
+
+
+
diff --git a/services/audiopolicy/engineconfigurable/wrapper/config/audio_policy_criteria.conf b/services/audiopolicy/engineconfigurable/wrapper/config/audio_policy_criteria.conf
new file mode 100755
index 0000000..a4ffdd5
--- /dev/null
+++ b/services/audiopolicy/engineconfigurable/wrapper/config/audio_policy_criteria.conf
@@ -0,0 +1,192 @@
+################################################################################################
+#
+# @NOTE:
+# Audio Policy Criteria file example for generic device build
+#
+# Any vendor shall have its own configuration within the corresponding device folder
+#
+################################################################################################
+
+#########################################################
+# Criterion type Example:
+# For each criterion, a couple of numerical, literal values must be provided to the PFW.
+# The numerical part is not mandatory. If not filled by the user, a default numerical value will be
+# automatically provided by audio HAL using the following logic:
+# - Exclusive criterion:
+# * 0 -> first literal value,
+# * 1 -> second literal value,
+# ...
+# * N -> (N+1)th literal value.
+# - Inclusive criterion:
+# * 1 << 0 -> first literal value,
+# * 1 << 1 -> second literal value,
+# ...
+# * 1 << N -> (N+1)th literal value,
+#
+#########################################################
+# Route|Audio {
+# InclusiveCriterionType|ExclusiveCriterionType {
+# <Criterion Name> [numerical value 1:]<literal value 1>,[numerical value 2:]<literal value 2>,<literal value 3>,...
+# }
+# }
+
+#########################################################
+# Criterion:
+#########################################################
+# Route|Audio {
+# Criterion {
+# <Criterion Name> {
+# Type <Criterion type name>
+# Default <default value of the criterion>
+# }
+# }
+# }
+
+Policy {
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the audio_mode_t
+ # from system/audio.h
+ #
+ AndroidModeType 0:Normal,1:RingTone,2:InCall,3:InCommunication
+ }
+ InclusiveCriterionType {
+ #
+ # DO NOT CHANGE ORDER. This definition must be aligned with the definition of
+ # AUDIO_DEVICE_OUT_* within <system/audio.h> file of android.
+ #
+ OutputDevicesMaskType Earpiece,Speaker,WiredHeadset,WiredHeadphone,BluetoothSco,BluetoothScoHeadset,BluetoothScoCarkit,BluetoothA2dp,BluetoothA2dpHeadphones,BluetoothA2dpSpeaker,Hdmi,AnlgDockHeadset,DgtlDockHeadset,UsbAccessory,UsbDevice,RemoteSubmix,TelephonyTx,Line,HdmiArc,Spdif,Fm,AuxLine,SpeakerSafe
+ }
+ InclusiveCriterionType {
+ #
+ # DO NOT CHANGE ORDER. This definition must be aligned with the definition of
+ # AUDIO_DEVICE_IN_* within <system/audio.h> file of android.
+ # Note also that direction bit will be decimated by AudioHAL in order to allow using a mask
+ # with the cardinality of 1 between a bit and an input device.
+ #
+ InputDevicesMaskType Communication,Ambient,BuiltinMic,BluetoothScoHeadset,WiredHeadset,Hdmi,TelephonyRx,BackMic,RemoteSubmix,AnlgDockHeadset,DgtlDockHeadset,UsbAccessory,UsbDevice,FmTuner,TvTune,Line,Spdif,BluetoothA2dp,Loopback
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForCommunicationType 0:ForceNone,1:ForceSpeaker,3:ForceBtSco
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForMediaType 0:ForceNone,1:ForceSpeaker,2:ForceHeadphones,4:ForceBtA2dp,5:ForceWiredAccessory,8:ForceAnalogDock,9:ForceDigitalDock,10:ForceNoBtA2dp
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForRecordType 0:ForceNone,3:ForceBtSco,5:ForceWiredAccessory
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForDockType 0:ForceNone,5:ForceWiredAccessory,6:ForceBtCarDock,7:ForceBtDeskDock,8:ForceAnalogDock,9:ForceDigitalDock
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForSystemType 0:ForceNone,11:ForceSystemEnforced
+ }
+ ExclusiveCriterionType {
+ #
+ # The values of the mode MUST be aligned with the definition of the
+ # audio_policy_forced_config_t from system/audio.h
+ #
+ ForceUseForHdmiSystemAudioType 0:ForceNone,12:ForceHdmiSystemEnforced
+ }
+ ExclusiveCriterionType {
+ Rate 8000,11025,12000,16000,22050,24000,32000,44100,48000,96000,176400,192000
+ }
+ ExclusiveCriterionType {
+ Format Mp3,AmrNb,AmrWb,Aac,HeAacV1,HeAacV2,Vorbis,Pcm16Bit,Pcm8Bit,Pcm32Bit,Pcm8_24Bit
+ }
+ InclusiveCriterionType {
+ OutputChannelMask FrontLeft,FrontRight,FrontCenter,LowFrequence,BackLeft,BackRight,FromLeftOfCenter,FromRightOfCenter,BackCenter,SideLeft,SideRight,TopCenter,TopFrontLeft,TopFrontCenter,TopFrontRight,TopBackLeft,TopBackCenter,TopBackRight
+ }
+ ExclusiveCriterionType {
+ OutputChannelMasks Mono,Stereo,Quad,QuadBack,QuadSide,5Point1,5Point1Back,5Point1Side,7Point1,All
+ }
+ InclusiveCriterionType {
+ InputChannelMask Left,Right,Front,Back,LeftProcessed,RightProcessed,FrontProcessed,BackProcessed,Pressure,XAxis,YAxis,ZAxis,VoiceUplink,VoiceDnlink
+ }
+ ExclusiveCriterionType {
+ InputChannelMasks Mono,Stereo,FrontBack,VoiceUplinkDnlink,All
+ }
+ InclusiveCriterionType {
+ OutputFlags Direct,Primary,Fast,DeepBuffer,CompressOffload,NonBlocking,HwAvSync
+ }
+ ExclusiveCriterionType {
+ InputSource Default,Mic,VoiceUplink,VoiceDownlink,VoiceCall,Camcorder,VoiceRecognition,VoiceCommunication,RemoteSubmix,Hotword
+ }
+
+
+ Criterion {
+ AvailableInputDevices {
+ Type InputDevicesMaskType
+ Default none
+ }
+ }
+ Criterion {
+ AvailableOutputDevices {
+ Type OutputDevicesMaskType
+ Default none
+ }
+ }
+ Criterion {
+ TelephonyMode {
+ Type AndroidModeType
+ Default Normal
+ }
+ }
+ Criterion {
+ ForceUseForCommunication {
+ Type ForceUseForCommunicationType
+ Default ForceNone
+ }
+ }
+ Criterion {
+ ForceUseForMedia {
+ Type ForceUseForMediaType
+ Default ForceNone
+ }
+ }
+ Criterion {
+ ForceUseForRecord {
+ Type ForceUseForRecordType
+ Default ForceNone
+ }
+ }
+ Criterion {
+ ForceUseForDock {
+ Type ForceUseForDockType
+ Default ForceNone
+ }
+ }
+ Criterion {
+ ForceUseForSystem {
+ Type ForceUseForSystemType
+ Default ForceNone
+ }
+ }
+ Criterion {
+ ForceUseForHdmiSystemAudio {
+ Type ForceUseForHdmiSystemAudioType
+ Default ForceNone
+ }
+ }
+}
+
diff --git a/services/audiopolicy/engineconfigurable/wrapper/include/ParameterManagerWrapper.h b/services/audiopolicy/engineconfigurable/wrapper/include/ParameterManagerWrapper.h
new file mode 100755
index 0000000..7530157
--- /dev/null
+++ b/services/audiopolicy/engineconfigurable/wrapper/include/ParameterManagerWrapper.h
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <system/audio.h>
+#include <system/audio_policy.h>
+#include <utils/Errors.h>
+#include <utils/RWLock.h>
+#include <list>
+#include <map>
+#include <string>
+#include <vector>
+
+class CParameterMgrPlatformConnector;
+class ISelectionCriterionInterface;
+class ISelectionCriterionTypeInterface;
+class cnode;
+
+class ParameterMgrPlatformConnectorLogger;
+
+namespace android
+{
+namespace audio_policy
+{
+
+class ParameterManagerWrapper
+{
+private:
+ typedef std::pair<int, const char *> CriterionTypeValuePair;
+
+ typedef std::map<std::string, ISelectionCriterionInterface *> CriterionCollection;
+ typedef std::map<std::string, ISelectionCriterionTypeInterface *> CriterionTypeCollection;
+ typedef CriterionCollection::iterator CriterionMapIterator;
+ typedef CriterionCollection::const_iterator CriterionMapConstIterator;
+ typedef CriterionTypeCollection::iterator CriterionTypeMapIterator;
+ typedef CriterionTypeCollection::const_iterator CriteriaTypeMapConstIterator;
+
+public:
+ ParameterManagerWrapper();
+ ~ParameterManagerWrapper();
+
+ /**
+ * Starts the platform state service.
+ * It starts the parameter framework policy instance.
+ *
+ * @return NO_ERROR if success, error code otherwise.
+ */
+ status_t start();
+
+ /**
+ * The following API wrap policy action to criteria
+ */
+
+ /**
+ * Checks if the platform state was correctly started (ie the policy parameter manager
+ * has been instantiated and started correctly).
+ *
+ * @todo: map on initCheck?
+ *
+ * @return true if platform state is started correctly, false otherwise.
+ */
+ bool isStarted();
+
+ /**
+ * Set Telephony Mode.
+ * It will set the telephony mode criterion accordingly and apply the configuration in order
+ * to select the right configuration on domains depending on this mode criterion.
+ *
+ * @param[in] mode: Android Phone state (normal, ringtone, csv, in communication)
+ *
+ * @return NO_ERROR if criterion set correctly, error code otherwise.
+ */
+ status_t setPhoneState(audio_mode_t mode);
+
+ audio_mode_t getPhoneState() const;
+
+ /**
+ * Set Force Use config for a given usage.
+ * It will set the corresponding policy parameter framework criterion.
+ *
+ * @param[in] usage for which a configuration shall be forced.
+ * @param[in] config wished to be forced for the given shall.
+ *
+ * @return NO_ERROR if the criterion was set correctly, error code otherwise (e.g. config not
+ * allowed a given usage...)
+ */
+ status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
+
+ audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const;
+
+ /**
+ * Set the connection state of device(s).
+ * It will set the associated policy parameter framework criterion.
+ *
+ * @param[in] devices mask of devices for which the state has changed.
+ * @param[in] state of availability of this(these) device(s).
+ * @param[in] deviceAddress: the mask might not be enough, as it may represents a type of
+ * device, so address of the device will help precise identification.
+ *
+ * @return NO_ERROR if devices criterion updated correctly, error code otherwise.
+ */
+ status_t setDeviceConnectionState(audio_devices_t devices, audio_policy_dev_state_t state,
+ const char *deviceAddress);
+
+private:
+ /**
+ * Apply the configuration of the platform on the policy parameter manager.
+ * Once all the criteria have been set, the client of the platform state must call
+ * this function in order to have the route PFW taking into account these criteria.
+ *
+ * OPENS: shall we expose this?
+ * - Yes if atomic set operation.
+ * In this case, abstract it behind the "STAGE AND COMMIT" pattern
+ * - no if need to set more than one before triggering an apply configuration.
+ */
+ void applyPlatformConfiguration();
+
+ /**
+ * Load the criterion configuration file.
+ *
+ * @param[in] path Criterion conf file path.
+ *
+ * @return NO_ERROR is parsing successful, error code otherwise.
+ */
+ status_t loadAudioPolicyCriteriaConfig(const char *path);
+
+ /**
+ * Add a criterion type to AudioPolicyPfw.
+ *
+ * @param[in] typeName of the PFW criterion type.
+ * @param[in] isInclusive attribute of the criterion type.
+ */
+ void addCriterionType(const std::string &typeName, bool isInclusive);
+
+ /**
+ * Add a criterion type value pair to AudioPolicyPfw.
+ *
+ * @param[in] typeName criterion type name to which this value pair is added to.
+ * @param[in] numeric part of the value pair.
+ * @param[in] literal part of the value pair.
+ */
+ void addCriterionTypeValuePair(const std::string &typeName, uint32_t numeric,
+ const std::string &literal);
+
+ /**
+ * Add a criterion to AudioPolicyPfw.
+ *
+ * @param[in] name of the PFW criterion.
+ * @param[in] typeName criterion type name to which this criterion is associated to.
+ * @param[in] defaultLiteralValue of the PFW criterion.
+ */
+ void addCriterion(const std::string &name,
+ const std::string &typeName,
+ const std::string &defaultLiteralValue);
+ /**
+ * Parse and load the inclusive criterion type from configuration file.
+ *
+ * @param[in] root node of the configuration file.
+ */
+ void loadInclusiveCriterionType(cnode *root);
+
+ /**
+ * Parse and load the exclusive criterion type from configuration file.
+ *
+ * @param[in] root node of the configuration file.
+ */
+ void loadExclusiveCriterionType(cnode *root);
+
+ /**
+ * Parse and load the criteria from configuration file.
+ *
+ * @param[in] root node of the configuration file.
+ */
+ void loadCriteria(cnode *root);
+
+ /**
+ * Parse and load a criterion from configuration file.
+ *
+ * @param[in] root node of the configuration file.
+ */
+ void loadCriterion(cnode *root);
+
+ /**
+ * Parse and load the criterion types from configuration file.
+ *
+ * @param[in] root node of the configuration file
+ * @param[in] isInclusive true if inclusive, false is exclusive.
+ */
+ void loadCriterionType(cnode *root, bool isInclusive);
+
+ /**
+ * Load the configuration file.
+ *
+ * @param[in] root node of the configuration file.
+ */
+ void loadConfig(cnode *root);
+
+ /**
+ * Parse and load the chidren node from a given root node.
+ *
+ * @param[in] root node of the configuration file
+ * @param[out] defaultValue of the parameter manager element to retrieve.
+ * @param[out] type of the parameter manager element to retrieve.
+ */
+ void parseChildren(cnode *root, std::string &defaultValue, std::string &type);
+
+ /**
+ * Retrieve an element from a map by its name.
+ *
+ * @tparam T type of element to search.
+ * @param[in] name name of the element to find.
+ * @param[in] elementsMap maps of elements to search into.
+ *
+ * @return valid pointer on element if found, NULL otherwise.
+ */
+ template <typename T>
+ T *getElement(const std::string &name, std::map<std::string, T *> &elementsMap);
+
+ /**
+ * Retrieve an element from a map by its name. Const version.
+ *
+ * @tparam T type of element to search.
+ * @param[in] name name of the element to find.
+ * @param[in] elementsMap maps of elements to search into.
+ *
+ * @return valid pointer on element if found, NULL otherwise.
+ */
+ template <typename T>
+ const T *getElement(const std::string &name,
+ const std::map<std::string, T *> &elementsMap) const;
+
+ /**
+ * set the value of a component state.
+ *
+ * @param[in] value new value to set to the component state.
+ * @param[in] stateName of the component state.
+ */
+ void setValue(int value, const std::string &stateName);
+
+ /**
+ * get the value of a component state.
+ *
+ * @param[in] name of the component state.
+ *
+ * @return value of the component state
+ */
+ int getValue(const std::string &stateName) const;
+
+ bool isValueValidForCriterion(ISelectionCriterionInterface *criterion, int valueToCheck);
+
+ CriterionTypeCollection mPolicyCriterionTypes; /**< Policy Criterion Type map. */
+ CriterionCollection mPolicyCriteria; /**< Policy Criterion Map. */
+
+ CParameterMgrPlatformConnector *mPfwConnector; /**< Policy Parameter Manager connector. */
+ ParameterMgrPlatformConnectorLogger *mPfwConnectorLogger; /**< Policy PFW logger. */
+
+
+ /**
+ * provide a compile time error if no specialization is provided for a given type.
+ *
+ * @tparam T: type of the parameter manager element. Supported one are:
+ * - Criterion
+ * - CriterionType.
+ */
+ template <typename T>
+ struct parameterManagerElementSupported;
+
+ static const char *const mPolicyPfwDefaultConfFileName; /**< Default Policy PFW top file name.*/
+};
+
+} // namespace audio_policy
+} // namespace android