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

Commit 4a2c5fe8 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Retain ID mapping for product strategy to be optional

In legacy systems, configuration files for the CAP lack
the identifier attribute. If it is not specified, the ID
should be derived from the strategy name, as it used to be.

Bug: 385999648
Test: load CAP configuration from older Android versions
Change-Id: Icc8d71fe4fcb9a7bf403197ba349264345cd5929
parent bc74e235
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ PolicySubsystem::PolicySubsystem(const std::string &name, core::log::Logger &log
        );
    addSubsystemObjectFactory(
        new TSubsystemObjectFactory<ProductStrategy>(
            mProductStrategyComponentName, (1 << MappingKeyName) | (1 << MappingKeyIdentifier))
            mProductStrategyComponentName, (1 << MappingKeyName))
        );
}

+13 −8
Original line number Diff line number Diff line
@@ -29,9 +29,6 @@ ProductStrategy::ProductStrategy(const std::string &mappingValue,
                                (MappingKeyAmendEnd - MappingKeyAmend1 + 1),
                                context) {

    size_t id = context.getItemAsInteger(MappingKeyIdentifier);
    std::string nameFromStructure(context.getItem(MappingKeyName));

    ALOG_ASSERT(instanceConfigurableElement != nullptr, "Invalid Configurable Element");
    mPolicySubsystem = static_cast<const PolicySubsystem *>(
            instanceConfigurableElement->getBelongingSubsystem());
@@ -40,14 +37,22 @@ ProductStrategy::ProductStrategy(const std::string &mappingValue,
    mPolicyPluginInterface = mPolicySubsystem->getPolicyPluginInterface();
    ALOG_ASSERT(mPolicyPluginInterface != nullptr, "Invalid Policy Plugin Interface");

    const std::string nameFromStructure(context.getItem(MappingKeyName));
    std::string name;
    if (context.iSet(MappingKeyIdentifier)) {
        size_t id = context.getItemAsInteger(MappingKeyIdentifier);
        mId = static_cast<android::product_strategy_t>(id);
    std::string name = mPolicyPluginInterface->getProductStrategyName(mId);
        name = mPolicyPluginInterface->getProductStrategyName(mId);
        if (name.empty()) {
            name = nameFromStructure;
            mId = mPolicyPluginInterface->getProductStrategyByName(name);
        }
    } else {
        name = nameFromStructure;
        mId = mPolicyPluginInterface->getProductStrategyByName(nameFromStructure);
    }

    ALOG_ASSERT(mId != PRODUCT_STRATEGY_INVALID, "Product Strategy %s not found", name.c_str());
    ALOG_ASSERT(mId != PRODUCT_STRATEGY_NONE, "Product Strategy %s not found", name.c_str());

    ALOGE("Product Strategy %s added", name.c_str());
}