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

Commit 23247c49 authored by Tyler Trephan's avatar Tyler Trephan
Browse files

Added new supportedEnumValues to VehicleAreaConfig.aidl file

Test: atest CarPropertyManagerTest JsonConfigLoaderUnitTest
Bug: 259476396
Change-Id: Iea031a5b0bca2f9030dbfb2df2fc182cb600a785
parent edba8ed3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,4 +41,5 @@ parcelable VehicleAreaConfig {
  long maxInt64Value;
  float minFloatValue;
  float maxFloatValue;
  @nullable long[] supportedEnumValues;
}
+7 −0
Original line number Diff line number Diff line
@@ -40,4 +40,11 @@ parcelable VehicleAreaConfig {

    float minFloatValue;
    float maxFloatValue;

    /**
     * If the property has a @data_enum, then it is possible to specify a supported subset of the
     * @data_enum. If the property has a @data_enum and supportedEnumValues is null, then it is
     * assumed all @data_enum values are supported unless specified through another mechanism.
     */
    @nullable long[] supportedEnumValues;
}
+8 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ const std::unordered_map<std::string, int> CONSTANTS_BY_NAME = {
         FAN_DIRECTION_FLOOR | FAN_DIRECTION_DEFROST | FAN_DIRECTION_FACE},
        {"FUEL_DOOR_REAR_LEFT", FUEL_DOOR_REAR_LEFT},
        {"LIGHT_STATE_ON", LIGHT_STATE_ON},
        {"LIGHT_STATE_OFF", LIGHT_STATE_OFF},
        {"LIGHT_SWITCH_OFF", LIGHT_SWITCH_OFF},
        {"LIGHT_SWITCH_AUTO", LIGHT_SWITCH_AUTO},
        {"MIRROR_DRIVER_LEFT_RIGHT",
@@ -460,6 +461,13 @@ void JsonConfigParser::parseAreas(const Json::Value& parentJsonNode, const std::
                                    &areaConfig.minFloatValue, errors);
        tryParseJsonValueToVariable(jsonAreaConfig, "maxFloatValue", /*optional=*/true,
                                    &areaConfig.maxFloatValue, errors);

        std::vector<int64_t> supportedEnumValues;
        tryParseJsonArrayToVariable(jsonAreaConfig, "supportedEnumValues", /*optional=*/true,
                                    &supportedEnumValues, errors);
        if (!supportedEnumValues.empty()) {
            areaConfig.supportedEnumValues = std::move(supportedEnumValues);
        }
        config->config.areaConfigs.push_back(std::move(areaConfig));

        RawPropValues areaValue = {};
+83 −0
Original line number Diff line number Diff line
@@ -616,6 +616,89 @@ TEST_F(JsonConfigLoaderUnitTest, testAreas_FailInvalidTypeForOneAreaValue) {
            << "Wrong type for DefaultValue for one area must cause error";
}

TEST_F(JsonConfigLoaderUnitTest, testAreas_HandlesNoSupportedEnumValuesDeclared) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_STATE",
            "areas": [{
                "areaId": 0,
            }]
        }]
    }
    )");

    auto result = mLoader.loadPropConfig(iss);
    ASSERT_TRUE(result.ok());

    auto configs = result.value();
    ASSERT_EQ(configs.size(), 1u);

    const VehiclePropConfig& config = configs.begin()->second.config;
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.areaId, 0);
    ASSERT_FALSE(areaConfig.supportedEnumValues);
}

TEST_F(JsonConfigLoaderUnitTest, testAreas_HandlesSupportedEnumValues) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_STATE",
            "areas": [{
                "areaId": 0,
                "supportedEnumValues": ["Constants::LIGHT_STATE_ON", "Constants::LIGHT_STATE_OFF"]
            }]
        }]
    }
    )");

    auto result = mLoader.loadPropConfig(iss);
    ASSERT_TRUE(result.ok());

    auto configs = result.value();
    ASSERT_EQ(configs.size(), 1u);

    const VehiclePropConfig& config = configs.begin()->second.config;
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.areaId, 0);
    ASSERT_TRUE(areaConfig.supportedEnumValues);
    ASSERT_EQ(areaConfig.supportedEnumValues.value().size(), 2u);
    ASSERT_EQ(areaConfig.supportedEnumValues.value(),
              std::vector<int64_t>({LIGHT_STATE_ON, LIGHT_STATE_OFF}));
}

TEST_F(JsonConfigLoaderUnitTest, testAreas_HandlesEmptySupportedEnumValues) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_STATE",
            "areas": [{
                "areaId": 0,
                "supportedEnumValues": []
            }]
        }]
    }
    )");

    auto result = mLoader.loadPropConfig(iss);
    ASSERT_TRUE(result.ok());

    auto configs = result.value();
    ASSERT_EQ(configs.size(), 1u);

    const VehiclePropConfig& config = configs.begin()->second.config;
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.areaId, 0);
    ASSERT_FALSE(areaConfig.supportedEnumValues);
}

}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ constexpr int FUEL_DOOR_REAR_LEFT = toInt(propertyutils_impl::PortLocationType::
constexpr int CHARGE_PORT_FRONT_LEFT = toInt(propertyutils_impl::PortLocationType::FRONT_LEFT);
constexpr int CHARGE_PORT_REAR_LEFT = toInt(propertyutils_impl::PortLocationType::REAR_LEFT);
constexpr int LIGHT_STATE_ON = toInt(propertyutils_impl::VehicleLightState::ON);
constexpr int LIGHT_STATE_OFF = toInt(propertyutils_impl::VehicleLightState::OFF);
constexpr int LIGHT_SWITCH_OFF = toInt(propertyutils_impl::VehicleLightSwitch::OFF);
constexpr int LIGHT_SWITCH_AUTO = toInt(propertyutils_impl::VehicleLightSwitch::AUTOMATIC);
constexpr int WHEEL_FRONT_LEFT = toInt(propertyutils_impl::VehicleAreaWheel::LEFT_FRONT);