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

Commit 7de54f20 authored by Yu Shan's avatar Yu Shan
Browse files

Implement get supported values for FakeVehicleHardware.

Use the test property: VENDOR_EXTENSION_INT_PROPERTY as an example
to show a basic implementation for getMinMaxSupportedValues and
getSupportedValuesLists.

This CL also updates json config parser to parse HasSupportedValueInfo
field.

Flag: EXEMPT HAL
Bug: 382563296
Test: atest JsonConfigLoaderUnitTest FakeVehicleHardwareTest
Manual test in KS.

Change-Id: I346a809f6b307ec1b957172aa41176aeaa4bc5f1
parent cb0bd830
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ using ::aidl::android::hardware::automotive::vehicle::FuelType;
using ::aidl::android::hardware::automotive::vehicle::GsrComplianceRequirementType;
using ::aidl::android::hardware::automotive::vehicle::HandsOnDetectionDriverState;
using ::aidl::android::hardware::automotive::vehicle::HandsOnDetectionWarning;
using ::aidl::android::hardware::automotive::vehicle::HasSupportedValueInfo;
using ::aidl::android::hardware::automotive::vehicle::ImpactSensorLocation;
using ::aidl::android::hardware::automotive::vehicle::LaneCenteringAssistCommand;
using ::aidl::android::hardware::automotive::vehicle::LaneCenteringAssistState;
@@ -600,6 +601,22 @@ void JsonConfigParser::parseAreas(const Json::Value& parentJsonNode, const std::
        if (!supportedEnumValues.empty()) {
            areaConfig.supportedEnumValues = std::move(supportedEnumValues);
        }

        if (jsonAreaConfig.isMember("hasSupportedValueInfo")) {
            HasSupportedValueInfo hasSupportedValueInfo = HasSupportedValueInfo{};
            const Json::Value& jsonHasSupportedValueInfo = jsonAreaConfig["hasSupportedValueInfo"];
            tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasMinSupportedValue",
                                        /*optional=*/true,
                                        &hasSupportedValueInfo.hasMinSupportedValue, errors);
            tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasMaxSupportedValue",
                                        /*optional=*/true,
                                        &hasSupportedValueInfo.hasMaxSupportedValue, errors);
            tryParseJsonValueToVariable(jsonHasSupportedValueInfo, "hasSupportedValuesList",
                                        /*optional=*/true,
                                        &hasSupportedValueInfo.hasSupportedValuesList, errors);
            areaConfig.hasSupportedValueInfo = std::move(hasSupportedValueInfo);
        }

        config->config.areaConfigs.push_back(std::move(areaConfig));

        RawPropValues areaValue = {};
+103 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ namespace hardware {
namespace automotive {
namespace vehicle {

using ::aidl::android::hardware::automotive::vehicle::HasSupportedValueInfo;
using ::aidl::android::hardware::automotive::vehicle::RawPropValues;
using ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
@@ -803,6 +804,108 @@ TEST_F(JsonConfigLoaderUnitTest, testAccess_areaOverrideGlobal) {
    ASSERT_EQ(areaConfig2.areaId, 1);
}

TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_allTrue) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
            "areas": [{
                "access": "VehiclePropertyAccess::WRITE",
                "areaId": 0,
                "hasSupportedValueInfo": {
                    "hasMinSupportedValue": true,
                    "hasMaxSupportedValue": true,
                    "hasSupportedValuesList": true
                }
            }],
            "access": "VehiclePropertyAccess::READ",
        }]
    }
    )");

    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.access, VehiclePropertyAccess::READ);
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.hasSupportedValueInfo, HasSupportedValueInfo({
                                                        .hasMinSupportedValue = true,
                                                        .hasMaxSupportedValue = true,
                                                        .hasSupportedValuesList = true,
                                                }));
}

TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_allFalse) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
            "areas": [{
                "access": "VehiclePropertyAccess::WRITE",
                "areaId": 0,
                "hasSupportedValueInfo": {
                    "hasMinSupportedValue": false,
                    "hasMaxSupportedValue": false,
                    "hasSupportedValuesList": false
                }
            }],
            "access": "VehiclePropertyAccess::READ",
        }]
    }
    )");

    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.access, VehiclePropertyAccess::READ);
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.hasSupportedValueInfo, HasSupportedValueInfo({
                                                        .hasMinSupportedValue = false,
                                                        .hasMaxSupportedValue = false,
                                                        .hasSupportedValuesList = false,
                                                }));
}

TEST_F(JsonConfigLoaderUnitTest, testHasSupportedValueInfo_unspecified) {
    std::istringstream iss(R"(
    {
        "properties": [{
            "property": "VehicleProperty::CABIN_LIGHTS_SWITCH",
            "areas": [{
                "access": "VehiclePropertyAccess::WRITE",
                "areaId": 0
            }],
            "access": "VehiclePropertyAccess::READ",
        }]
    }
    )");

    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.access, VehiclePropertyAccess::READ);
    ASSERT_EQ(config.areaConfigs.size(), 1u);

    const VehicleAreaConfig& areaConfig = config.areaConfigs[0];
    ASSERT_EQ(areaConfig.hasSupportedValueInfo, std::nullopt);
}

}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
+6 −3
Original line number Diff line number Diff line
@@ -99,12 +99,15 @@
                {
                    "defaultValue": {
                        "int32Values": [
                            1
                            2
                        ]
                    },
                    "areaId": "VehicleAreaWindow::FRONT_WINDSHIELD",
                    "minInt32Value": -100,
                    "maxInt32Value": 100
                    "hasSupportedValueInfo": {
                        "hasMinSupportedValue": true,
                        "hasMaxSupportedValue": true,
                        "hasSupportedValuesList": true
                    }
                },
                {
                    "defaultValue": {
+6 −0
Original line number Diff line number Diff line
@@ -108,6 +108,12 @@ class FakeVehicleHardware : public IVehicleHardware {
    aidl::android::hardware::automotive::vehicle::StatusCode unsubscribe(int32_t propId,
                                                                         int32_t areaId) override;

    std::vector<aidlvhal::MinMaxSupportedValueResult> getMinMaxSupportedValues(
            const std::vector<PropIdAreaId>& propIdAreaIds) override;

    std::vector<aidlvhal::SupportedValuesListResult> getSupportedValuesLists(
            const std::vector<PropIdAreaId>& propIdAreaIds) override;

  protected:
    // mValuePool is also used in mServerSidePropStore.
    const std::shared_ptr<VehiclePropValuePool> mValuePool;
+58 −0
Original line number Diff line number Diff line
@@ -62,11 +62,13 @@ using ::aidl::android::hardware::automotive::vehicle::DriverDrowsinessAttentionW
using ::aidl::android::hardware::automotive::vehicle::ErrorState;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueResult;
using ::aidl::android::hardware::automotive::vehicle::MinMaxSupportedValueResult;
using ::aidl::android::hardware::automotive::vehicle::RawPropValues;
using ::aidl::android::hardware::automotive::vehicle::SetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::SetValueResult;
using ::aidl::android::hardware::automotive::vehicle::StatusCode;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
using ::aidl::android::hardware::automotive::vehicle::SupportedValuesListResult;
using ::aidl::android::hardware::automotive::vehicle::toString;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
@@ -2299,6 +2301,62 @@ StatusCode FakeVehicleHardware::subscribe(SubscribeOptions options) {
    return StatusCode::OK;
}

std::vector<MinMaxSupportedValueResult> FakeVehicleHardware::getMinMaxSupportedValues(
        const std::vector<PropIdAreaId>& propIdAreaIds) {
    std::vector<MinMaxSupportedValueResult> results;
    // We only support VENDOR_EXTENSION_INT_PROPERTY
    for (const auto& propIdAreaId : propIdAreaIds) {
        int propId = propIdAreaId.propId;
        int areaId = propIdAreaId.areaId;
        if (propId != toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY)) {
            results.push_back(MinMaxSupportedValueResult{
                    .status = StatusCode::INVALID_ARG,
            });
            continue;
        }
        results.push_back(MinMaxSupportedValueResult{
                .status = StatusCode::OK,
                .minSupportedValue =
                        RawPropValues{
                                .int32Values = {0},
                        },
                .maxSupportedValue =
                        RawPropValues{
                                .int32Values = {10},
                        },
        });
    }
    return results;
}

std::vector<SupportedValuesListResult> FakeVehicleHardware::getSupportedValuesLists(
        const std::vector<PropIdAreaId>& propIdAreaIds) {
    std::vector<SupportedValuesListResult> results;
    // We only support VENDOR_EXTENSION_INT_PROPERTY
    for (const auto& propIdAreaId : propIdAreaIds) {
        int propId = propIdAreaId.propId;
        int areaId = propIdAreaId.areaId;
        if (propId != toInt(TestVendorProperty::VENDOR_EXTENSION_INT_PROPERTY)) {
            results.push_back(SupportedValuesListResult{
                    .status = StatusCode::INVALID_ARG,
            });
            continue;
        }
        results.push_back(SupportedValuesListResult{
                .status = StatusCode::OK,
                .supportedValuesList = std::vector<std::optional<RawPropValues>>({
                        RawPropValues{.int32Values = {0}},
                        RawPropValues{.int32Values = {2}},
                        RawPropValues{.int32Values = {4}},
                        RawPropValues{.int32Values = {6}},
                        RawPropValues{.int32Values = {8}},
                        RawPropValues{.int32Values = {10}},
                }),
        });
    }
    return results;
}

bool FakeVehicleHardware::isVariableUpdateRateSupported(const VehiclePropConfig& vehiclePropConfig,
                                                        int32_t areaId) {
    for (size_t i = 0; i < vehiclePropConfig.areaConfigs.size(); i++) {
Loading