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

Commit 987a69a8 authored by Aaqib Ismail's avatar Aaqib Ismail
Browse files

Send CarPropertyValue status when HVAC power state changes

Bug: 301001111
Test: atest FakeVehicleHardwareTest
Test: atest CarPropertyManagerTest
Change-Id: I274d4480e6b1f264fd0b6eefd5926311a65f883a
parent b5edda79
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ class FakeVehicleHardware : public IVehicleHardware {
            const aidl::android::hardware::automotive::vehicle::SetValueRequest& request);

    std::string genFakeDataCommand(const std::vector<std::string>& options);
    void sendHvacPropertiesCurrentValues(int32_t areaId);
    void sendHvacPropertiesCurrentValues(int32_t areaId, int32_t hvacPowerOnVal);
    void sendAdasPropertiesState(int32_t propertyId, int32_t state);
    void generateVendorConfigs(
            std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropConfig>&) const;
+13 −9
Original line number Diff line number Diff line
@@ -731,7 +731,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getEchoReverseBytes(
    return std::move(gotValue);
}

void FakeVehicleHardware::sendHvacPropertiesCurrentValues(int32_t areaId) {
void FakeVehicleHardware::sendHvacPropertiesCurrentValues(int32_t areaId, int32_t hvacPowerOnVal) {
    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);
@@ -744,7 +744,8 @@ void FakeVehicleHardware::sendHvacPropertiesCurrentValues(int32_t areaId) {
        for (size_t j = 0; j < powerPropValues.size(); j++) {
            auto powerPropValue = std::move(powerPropValues[j]);
            if ((powerPropValue->areaId & areaId) == powerPropValue->areaId) {
                powerPropValue->status = VehiclePropertyStatus::AVAILABLE;
                powerPropValue->status = hvacPowerOnVal ? VehiclePropertyStatus::AVAILABLE
                                                        : VehiclePropertyStatus::UNAVAILABLE;
                powerPropValue->timestamp = elapsedRealtimeNano();
                // This will trigger a property change event for the current hvac property value.
                mServerSidePropStore->writeValue(std::move(powerPropValue), /*updateStatus=*/true,
@@ -796,13 +797,6 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        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(value.areaId);
    }

    if (isHvacPropAndHvacNotAvailable(propId, value.areaId)) {
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) << "hvac not available";
@@ -841,6 +835,16 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        case toInt(TestVendorProperty::VENDOR_PROPERTY_FOR_ERROR_CODE_TESTING):
            *isSpecialValue = true;
            return StatusError((StatusCode)VENDOR_ERROR_CODE);
        case toInt(VehicleProperty::HVAC_POWER_ON):
            if (value.value.int32Values.size() != 1) {
                *isSpecialValue = true;
                return StatusError(StatusCode::INVALID_ARG)
                       << "HVAC_POWER_ON requires only one int32 value";
            }
            // When changing HVAC power state, send current hvac property values
            // through on change event.
            sendHvacPropertiesCurrentValues(value.areaId, value.value.int32Values[0]);
            return {};
        case toInt(VehicleProperty::HVAC_TEMPERATURE_VALUE_SUGGESTION):
            *isSpecialValue = true;
            return setHvacTemperatureValueSuggestion(value);
+50 −26
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <inttypes.h>
#include <chrono>
#include <condition_variable>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
@@ -390,6 +391,25 @@ class FakeVehicleHardwareTest : public ::testing::Test {
        }
    } mPropValueCmp;

    std::unique_ptr<VehiclePropConfig> getVehiclePropConfig(int32_t propertyId) {
        auto configs = mHardware->getAllPropertyConfigs();
        for (auto& config : configs) {
            if (config.prop == propertyId) {
                auto ptr = std::make_unique<VehiclePropConfig>();
                ptr->prop = config.prop;
                ptr->access = config.access;
                ptr->changeMode = config.changeMode;
                ptr->areaConfigs = config.areaConfigs;
                ptr->configArray = config.configArray;
                ptr->configString = config.configString;
                ptr->minSampleRate = config.minSampleRate;
                ptr->maxSampleRate = config.maxSampleRate;
                return ptr;
            }
        }
        return std::unique_ptr<VehiclePropConfig>(nullptr);
    }

  private:
    std::unique_ptr<FakeVehicleHardware> mHardware;
    std::shared_ptr<IVehicleHardware::SetValuesCallback> mSetValuesCallback;
@@ -1755,32 +1775,41 @@ TEST_F(FakeVehicleHardwareTest, testSetHvacPropNotAvailable) {
}

TEST_F(FakeVehicleHardwareTest, testHvacPowerOnSendCurrentHvacPropValues) {
    int seatAreaIds[5] = {SEAT_1_LEFT, SEAT_1_RIGHT, SEAT_2_LEFT, SEAT_2_CENTER, SEAT_2_RIGHT};
    for (int areaId : seatAreaIds) {
    auto hvacPowerOnConfig = std::move(getVehiclePropConfig(toInt(VehicleProperty::HVAC_POWER_ON)));
    EXPECT_NE(hvacPowerOnConfig, nullptr);
    for (auto& hvacPowerOnAreaConfig : hvacPowerOnConfig->areaConfigs) {
        int hvacPowerAreaId = hvacPowerOnAreaConfig.areaId;
        StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                      .areaId = areaId,
                                                      .areaId = hvacPowerAreaId,
                                                      .value.int32Values = {0}});

        ASSERT_EQ(status, StatusCode::OK);

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

        EXPECT_EQ(status, StatusCode::OK);
        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]);
        for (const auto& event : events) {
            // Ignore HVAC_POWER_ON event
            if (event.prop == toInt(VehicleProperty::HVAC_POWER_ON)) {
                continue;
            }
        changedPropIds.push_back(toInt(VehicleProperty::HVAC_POWER_ON));
            EXPECT_THAT(event.prop, AnyOfArray(HVAC_POWER_PROPERTIES));
            EXPECT_EQ((hvacPowerAreaId & event.areaId), hvacPowerAreaId);
            EXPECT_EQ(event.status, VehiclePropertyStatus::UNAVAILABLE);
        }
        clearChangedProperties();

        status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                           .areaId = hvacPowerAreaId,
                                           .value.int32Values = {1}});
        EXPECT_EQ(status, StatusCode::OK);
        events = getChangedProperties();
        for (const auto& event : events) {
            EXPECT_EQ(event.areaId, areaId);
            EXPECT_THAT(event.prop, AnyOfArray(changedPropIds));
            // Ignore HVAC_POWER_ON event
            if (event.prop == toInt(VehicleProperty::HVAC_POWER_ON)) {
                continue;
            }
            EXPECT_THAT(event.prop, AnyOfArray(HVAC_POWER_PROPERTIES));
            EXPECT_EQ((hvacPowerAreaId & event.areaId), hvacPowerAreaId);
            EXPECT_EQ(event.status, VehiclePropertyStatus::AVAILABLE);
        }
        clearChangedProperties();
    }
}

@@ -3016,13 +3045,8 @@ TEST_F(FakeVehicleHardwareTest, testSetHvacTemperatureValueSuggestion) {

    // Config array values from HVAC_TEMPERATURE_SET in DefaultProperties.json
    auto configs = getHardware()->getAllPropertyConfigs();
    VehiclePropConfig* hvacTemperatureSetConfig = nullptr;
    for (auto& config : configs) {
        if (config.prop == toInt(VehicleProperty::HVAC_TEMPERATURE_SET)) {
            hvacTemperatureSetConfig = &config;
            break;
        }
    }
    auto hvacTemperatureSetConfig =
            std::move(getVehiclePropConfig(toInt(VehicleProperty::HVAC_TEMPERATURE_SET)));
    EXPECT_NE(hvacTemperatureSetConfig, nullptr);

    auto& hvacTemperatureSetConfigArray = hvacTemperatureSetConfig->configArray;