Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7188f1ad authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: engineconfigurable: Merge Policy Engine and Wrapper configuration files

Test: make
Change-Id: I0a905752218438378d9ca87457cd55f6cd0f2586
parent f1e9508a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -133,6 +133,8 @@ const engineConfig::ProductStrategies gOrderedStrategies = {

const engineConfig::Config gDefaultEngineConfig = {
    1.0,
    gOrderedStrategies
    gOrderedStrategies,
    {},
    {}
};
} // namespace android
+23 −0
Original line number Diff line number Diff line
@@ -52,9 +52,32 @@ struct ProductStrategy {

using ProductStrategies = std::vector<ProductStrategy>;

using ValuePair = std::pair<uint32_t, std::string>;
using ValuePairs = std::vector<ValuePair>;

struct CriterionType
{
    std::string name;
    bool isInclusive;
    ValuePairs valuePairs;
};

using CriterionTypes = std::vector<CriterionType>;

struct Criterion
{
    std::string name;
    std::string typeName;
    std::string defaultLiteralValue;
};

using Criteria = std::vector<Criterion>;

struct Config {
    float version;
    ProductStrategies productStrategies;
    Criteria criteria;
    CriterionTypes criterionTypes;
};

/** Result of `parse(const char*)` */
+115 −1
Original line number Diff line number Diff line
@@ -70,6 +70,43 @@ struct ProductStrategyTraits : public BaseSerializerTraits<ProductStrategy, Prod
    };
    static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root, Collection &ps);
};
struct ValueTraits : public BaseSerializerTraits<ValuePair, ValuePairs> {
    static constexpr const char *tag = "value";
    static constexpr const char *collectionTag = "values";

    struct Attributes {
        static constexpr const char *literal = "literal";
        static constexpr const char *numerical = "numerical";
    };

    static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root,
                                         Collection &collection);
};
struct CriterionTypeTraits : public BaseSerializerTraits<CriterionType, CriterionTypes> {
    static constexpr const char *tag = "criterion_type";
    static constexpr const char *collectionTag = "criterion_types";

    struct Attributes {
        static constexpr const char *name = "name";
        static constexpr const char *type = "type";
    };

    static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root,
                                         Collection &collection);
};
struct CriterionTraits : public BaseSerializerTraits<Criterion, Criteria> {
    static constexpr const char *tag = "criterion";
    static constexpr const char *collectionTag = "criteria";

    struct Attributes {
        static constexpr const char *name = "name";
        static constexpr const char *type = "type";
        static constexpr const char *defaultVal = "default";
    };

    static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root,
                                         Collection &collection);
};

using xmlCharUnique = std::unique_ptr<xmlChar, decltype(xmlFree)>;

@@ -254,6 +291,80 @@ status_t AttributesGroupTraits::deserialize(_xmlDoc *doc, const _xmlNode *child,
    return NO_ERROR;
}

status_t ValueTraits::deserialize(_xmlDoc */*doc*/, const _xmlNode *child, Collection &values)
{
    std::string literal = getXmlAttribute(child, Attributes::literal);
    if (literal.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::literal);
        return BAD_VALUE;
    }
    uint32_t numerical = 0;
    std::string numericalTag = getXmlAttribute(child, Attributes::numerical);
    if (numericalTag.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::literal);
        return BAD_VALUE;
    }
    if (!convertTo(numericalTag, numerical)) {
        ALOGE("%s: : Invalid value(%s)", __FUNCTION__, numericalTag.c_str());
        return BAD_VALUE;
    }
    values.push_back({numerical, literal});
    return NO_ERROR;
}

status_t CriterionTypeTraits::deserialize(_xmlDoc *doc, const _xmlNode *child,
                                          Collection &criterionTypes)
{
    std::string name = getXmlAttribute(child, Attributes::name);
    if (name.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::name);
        return BAD_VALUE;
    }
    ALOGV("%s: %s %s = %s", __FUNCTION__, tag, Attributes::name, name.c_str());

    std::string type = getXmlAttribute(child, Attributes::type);
    if (type.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::type);
        return BAD_VALUE;
    }
    ALOGV("%s: %s %s = %s", __FUNCTION__, tag, Attributes::type, type.c_str());
    bool isInclusive(type == "inclusive");

    ValuePairs pairs;
    size_t nbSkippedElements = 0;
    deserializeCollection<ValueTraits>(doc, child, pairs, nbSkippedElements);
    criterionTypes.push_back({name, isInclusive, pairs});
    return NO_ERROR;
}

status_t CriterionTraits::deserialize(_xmlDoc */*doc*/, const _xmlNode *child,
                                      Collection &criteria)
{
    std::string name = getXmlAttribute(child, Attributes::name);
    if (name.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::name);
        return BAD_VALUE;
    }
    ALOGV("%s: %s = %s", __FUNCTION__, Attributes::name, name.c_str());

    std::string defaultValue = getXmlAttribute(child, Attributes::defaultVal);
    if (defaultValue.empty()) {
        // Not mandatory to provide a default value for a criterion, even it is recommanded...
        ALOGV("%s: No attribute %s found (but recommanded)", __FUNCTION__, Attributes::defaultVal);
    }
    ALOGV("%s: %s = %s", __FUNCTION__, Attributes::defaultVal, defaultValue.c_str());

    std::string typeName = getXmlAttribute(child, Attributes::type);
    if (typeName.empty()) {
        ALOGE("%s: No attribute %s found", __FUNCTION__, Attributes::name);
        return BAD_VALUE;
    }
    ALOGV("%s: %s = %s", __FUNCTION__, Attributes::type, typeName.c_str());

    criteria.push_back({name, typeName, defaultValue});
    return NO_ERROR;
}

status_t ProductStrategyTraits::deserialize(_xmlDoc *doc, const _xmlNode *child,
                                            Collection &strategies)
{
@@ -299,7 +410,10 @@ ParsingResult parse(const char* path) {
    config->version = std::stof(version);
    deserializeCollection<ProductStrategyTraits>(
                doc, cur, config->productStrategies, nbSkippedElements);

    deserializeCollection<CriterionTraits>(
                doc, cur, config->criteria, nbSkippedElements);
    deserializeCollection<CriterionTypeTraits>(
                doc, cur, config->criterionTypes, nbSkippedElements);
    return {std::move(config), nbSkippedElements};
}

+33 −1
Original line number Diff line number Diff line
LOCAL_PATH := $(call my-dir)

TOOLS := frameworks/av/services/audiopolicy/engineconfigurable/tools
PROVISION_CRITERION_TYPES := $(TOOLS)/provision_criterion_types_from_android_headers.mk

##################################################################
# CONFIGURATION TOP FILE
##################################################################
@@ -16,7 +19,9 @@ LOCAL_VENDOR_MODULE := true
LOCAL_SRC_FILES := phone/$(LOCAL_MODULE_STEM)

LOCAL_REQUIRED_MODULES := \
    audio_policy_engine_product_strategies_phone.xml
    audio_policy_engine_product_strategies_phone.xml  \
    audio_policy_engine_criteria.xml \
    audio_policy_engine_criterion_types.xml

include $(BUILD_PREBUILT)

@@ -48,6 +53,8 @@ LOCAL_SRC_FILES := automotive/$(LOCAL_MODULE_STEM)

LOCAL_REQUIRED_MODULES := \
    audio_policy_engine_product_strategies_automotive.xml \
    audio_policy_engine_criteria.xml \
    audio_policy_engine_criterion_types.xml

include $(BUILD_PREBUILT)

@@ -65,3 +72,28 @@ LOCAL_SRC_FILES := automotive/$(LOCAL_MODULE_STEM)
include $(BUILD_PREBUILT)

endif #ifeq ($(BUILD_AUDIO_POLICY_EXAMPLE_CONFIGURATION), automotive_configurable)

ifeq ($(BUILD_AUDIO_POLICY_EXAMPLE_CONFIGURATION),$(filter $(BUILD_AUDIO_POLICY_EXAMPLE_CONFIGURATION),phone_configurable automotive_configurable))

include $(CLEAR_VARS)
LOCAL_MODULE := audio_policy_engine_criteria.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_VENDOR_MODULE := true
LOCAL_SRC_FILES := common/$(LOCAL_MODULE)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := audio_policy_engine_criterion_types.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_VENDOR_MODULE := true
LOCAL_ADDITIONAL_DEPENDENCIES := \
    $(TARGET_OUT_VENDOR_ETC)/audio_policy_configuration.xml

ANDROID_AUDIO_BASE_HEADER_FILE := system/media/audio/include/system/audio-base.h
AUDIO_POLICY_CONFIGURATION_FILE := $(TARGET_OUT_VENDOR_ETC)/audio_policy_configuration.xml
CRITERION_TYPES_FILE := $(LOCAL_PATH)/common/$(LOCAL_MODULE).in

include $(PROVISION_CRITERION_TYPES)

endif #ifeq ($(BUILD_AUDIO_POLICY_EXAMPLE_CONFIGURATION),$(filter $(BUILD_AUDIO_POLICY_EXAMPLE_CONFIGURATION),phone_configurable automotive_configurable))
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
<configuration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">

    <xi:include href="audio_policy_engine_product_strategies.xml"/>
    <xi:include href="audio_policy_engine_criterion_types.xml"/>
    <xi:include href="audio_policy_engine_criteria.xml"/>

</configuration>
Loading