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

Commit ddf0ea0d authored by Yu Shan's avatar Yu Shan
Browse files

Make HVAC dep properties unavailable to get when power is off.

Previously HVAC properties are unavailable to set when hvac power is
off. This CL makes VHAL returns NOT_AVAILABLE for get as well. VHAL
will also generate property change event when the power is switched
on again.

Test: atest FakeVehicleHardwareTest
Bug: 262461830
Change-Id: I17ca8a4e48f3ff5854226a6a38a42220078073d5
parent cf23435a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -194,7 +194,7 @@ class FakeVehicleHardware : public IVehicleHardware {
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    ValueResultType getEchoReverseBytes(
    ValueResultType getEchoReverseBytes(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    bool isHvacPropAndHvacNotAvailable(int32_t propId);
    bool isHvacPropAndHvacNotAvailable(int32_t propId) const;


    std::unordered_map<int32_t, ConfigDeclaration> loadConfigDeclarations();
    std::unordered_map<int32_t, ConfigDeclaration> loadConfigDeclarations();


@@ -236,6 +236,7 @@ class FakeVehicleHardware : public IVehicleHardware {
            const aidl::android::hardware::automotive::vehicle::SetValueRequest& request);
            const aidl::android::hardware::automotive::vehicle::SetValueRequest& request);


    std::string genFakeDataCommand(const std::vector<std::string>& options);
    std::string genFakeDataCommand(const std::vector<std::string>& options);
    void sendHvacPropertiesCurrentValues();


    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
+34 −1
Original line number Original line Diff line number Diff line
@@ -295,7 +295,7 @@ VhalResult<void> FakeVehicleHardware::setApPowerStateReport(const VehiclePropVal
    return {};
    return {};
}
}


bool FakeVehicleHardware::isHvacPropAndHvacNotAvailable(int32_t propId) {
bool FakeVehicleHardware::isHvacPropAndHvacNotAvailable(int32_t propId) const {
    std::unordered_set<int32_t> powerProps(std::begin(HVAC_POWER_PROPERTIES),
    std::unordered_set<int32_t> powerProps(std::begin(HVAC_POWER_PROPERTIES),
                                           std::end(HVAC_POWER_PROPERTIES));
                                           std::end(HVAC_POWER_PROPERTIES));
    if (powerProps.count(propId)) {
    if (powerProps.count(propId)) {
@@ -366,6 +366,11 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
        return getUserHalProp(value);
        return getUserHalProp(value);
    }
    }


    if (isHvacPropAndHvacNotAvailable(propId)) {
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
    }

    switch (propId) {
    switch (propId) {
        case OBD2_FREEZE_FRAME:
        case OBD2_FREEZE_FRAME:
            *isSpecialValue = true;
            *isSpecialValue = true;
@@ -408,6 +413,27 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getEchoReverseBytes(
    return std::move(gotValue);
    return std::move(gotValue);
}
}


void FakeVehicleHardware::sendHvacPropertiesCurrentValues() {
    for (size_t i = 0; i < sizeof(HVAC_POWER_PROPERTIES) / sizeof(int32_t); i++) {
        int powerPropId = HVAC_POWER_PROPERTIES[i];
        auto powerPropResults = mServerSidePropStore->readValuesForProperty(powerPropId);
        if (!powerPropResults.ok()) {
            ALOGW("failed to get power prop 0x%x, error: %s", powerPropId,
                  getErrorMsg(powerPropResults).c_str());
            continue;
        }
        auto& powerPropValues = powerPropResults.value();
        for (size_t j = 0; j < powerPropValues.size(); j++) {
            auto powerPropValue = std::move(powerPropValues[j]);
            powerPropValue->status = VehiclePropertyStatus::AVAILABLE;
            powerPropValue->timestamp = elapsedRealtimeNano();
            // This will trigger a property change event for the current hvac property value.
            mServerSidePropStore->writeValue(std::move(powerPropValue), /*updateStatus=*/true,
                                             VehiclePropertyStore::EventMode::ALWAYS);
        }
    }
}

VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
                                                           bool* isSpecialValue) {
                                                           bool* isSpecialValue) {
    *isSpecialValue = false;
    *isSpecialValue = false;
@@ -419,6 +445,13 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        return setUserHalProp(value);
        return setUserHalProp(value);
    }
    }


    if (propId == toInt(VehicleProperty::HVAC_POWER_ON) && value.value.int32Values.size() == 1 &&
        value.value.int32Values[0] == 1) {
        // If we are turning HVAC power on, send current hvac property values through on change
        // event.
        sendHvacPropertiesCurrentValues();
    }

    if (isHvacPropAndHvacNotAvailable(propId)) {
    if (isHvacPropAndHvacNotAvailable(propId)) {
        *isSpecialValue = true;
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
+66 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ using ::android::base::expected;
using ::android::base::ScopedLockAssertion;
using ::android::base::ScopedLockAssertion;
using ::android::base::StringPrintf;
using ::android::base::StringPrintf;
using ::android::base::unexpected;
using ::android::base::unexpected;
using ::testing::AnyOfArray;
using ::testing::ContainerEq;
using ::testing::ContainerEq;
using ::testing::ContainsRegex;
using ::testing::ContainsRegex;
using ::testing::Eq;
using ::testing::Eq;
@@ -1140,6 +1141,71 @@ TEST_F(FakeVehicleHardwareTest, testSetVehicleMapService) {
    EXPECT_EQ(getValueResult.error(), StatusCode::NOT_AVAILABLE);
    EXPECT_EQ(getValueResult.error(), StatusCode::NOT_AVAILABLE);
}
}


TEST_F(FakeVehicleHardwareTest, testGetHvacPropNotAvailable) {
    StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                  .value.int32Values = {0}});

    ASSERT_EQ(status, StatusCode::OK);

    for (size_t i = 0; i < sizeof(HVAC_POWER_PROPERTIES) / sizeof(int32_t); i++) {
        int powerPropId = HVAC_POWER_PROPERTIES[i];
        auto getValueResult = getValue(VehiclePropValue{
                .prop = powerPropId,
                .areaId = HVAC_ALL,
        });

        EXPECT_FALSE(getValueResult.ok());
        EXPECT_EQ(getValueResult.error(), StatusCode::NOT_AVAILABLE);
    }
}

TEST_F(FakeVehicleHardwareTest, testSetHvacPropNotAvailable) {
    StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                  .value.int32Values = {0}});

    ASSERT_EQ(status, StatusCode::OK);

    for (size_t i = 0; i < sizeof(HVAC_POWER_PROPERTIES) / sizeof(int32_t); i++) {
        int powerPropId = HVAC_POWER_PROPERTIES[i];
        status = setValue(VehiclePropValue{
                .prop = powerPropId,
                .areaId = HVAC_ALL,
        });

        EXPECT_EQ(status, StatusCode::NOT_AVAILABLE);
    }
}

TEST_F(FakeVehicleHardwareTest, testHvacPowerOnSendCurrentHvacPropValues) {
    StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                  .value.int32Values = {0}});

    ASSERT_EQ(status, StatusCode::OK);

    clearChangedProperties();

    status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                       .areaId = HVAC_ALL,
                                       .value.int32Values = {1}});

    auto events = getChangedProperties();
    // If we turn HVAC power on, we expect to receive one property event for every HVAC prop areas
    // plus one event for HVAC_POWER_ON.
    std::vector<int32_t> changedPropIds;
    for (size_t i = 0; i < sizeof(HVAC_POWER_PROPERTIES) / sizeof(int32_t); i++) {
        changedPropIds.push_back(HVAC_POWER_PROPERTIES[i]);
    }
    changedPropIds.push_back(toInt(VehicleProperty::HVAC_POWER_ON));
    ASSERT_EQ(events.size(), changedPropIds.size());
    for (const auto& event : events) {
        EXPECT_EQ(event.areaId, HVAC_ALL);
        EXPECT_THAT(event.prop, AnyOfArray(changedPropIds));
    }
}

TEST_F(FakeVehicleHardwareTest, testGetUserPropertySetOnly) {
TEST_F(FakeVehicleHardwareTest, testGetUserPropertySetOnly) {
    for (VehicleProperty prop : std::vector<VehicleProperty>({
    for (VehicleProperty prop : std::vector<VehicleProperty>({
                 VehicleProperty::INITIAL_USER_INFO,
                 VehicleProperty::INITIAL_USER_INFO,