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

Commit 1d2fd733 authored by Shrikar Amirisetty's avatar Shrikar Amirisetty Committed by Android (Google) Code Review
Browse files

Merge "Update properties and FakeVehicleHardware to support multi-display" into udc-dev

parents 5810bdb9 86ce85e8
Loading
Loading
Loading
Loading
+233 −45
Original line number Diff line number Diff line
@@ -1329,22 +1329,26 @@
        },
        {
            "property": "VehicleProperty::SEAT_OCCUPANCY",
            "areas": [
                {
            "defaultValue": {
                "int32Values": [
                    "VehicleSeatOccupancyState::VACANT"
                ]
            },
            "areas": [
                {
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "defaultValue": {
                        "int32Values": [
                            "VehicleSeatOccupancyState::VACANT"
                        ]
                    },
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1854,7 +1858,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1867,7 +1883,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ],
            "configArray": [
@@ -1918,7 +1946,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1931,7 +1971,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1944,7 +1996,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1957,7 +2021,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1970,7 +2046,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -1983,7 +2071,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -2009,7 +2109,27 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL",
                    "areaId": "Constants::SEAT_1_LEFT",
                    "minInt32Value": 1,
                    "maxInt32Value": 7
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT",
                    "minInt32Value": 1,
                    "maxInt32Value": 7
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT",
                    "minInt32Value": 1,
                    "maxInt32Value": 7
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT",
                    "minInt32Value": 1,
                    "maxInt32Value": 7
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER",
                    "minInt32Value": 1,
                    "maxInt32Value": 7
                }
@@ -2024,7 +2144,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -2043,7 +2175,19 @@
            },
            "areas": [
                {
                    "areaId": "Constants::HVAC_ALL"
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
@@ -2064,6 +2208,21 @@
                    "areaId": "Constants::SEAT_1_RIGHT",
                    "minInt32Value": 0,
                    "maxInt32Value": 3
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT",
                    "minInt32Value": 0,
                    "maxInt32Value": 3
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT",
                    "minInt32Value": 0,
                    "maxInt32Value": 3
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER",
                    "minInt32Value": 0,
                    "maxInt32Value": 3
                }
            ],
            "comment": "0 is off and +ve values indicate ventilation level."
@@ -2101,6 +2260,21 @@
                    "areaId": "Constants::SEAT_1_RIGHT",
                    "minInt32Value": -2,
                    "maxInt32Value": 2
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT",
                    "minInt32Value": -2,
                    "maxInt32Value": 2
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT",
                    "minInt32Value": -2,
                    "maxInt32Value": 2
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER",
                    "minInt32Value": -2,
                    "maxInt32Value": 2
                }
            ],
            "comment": "+ve values for heating and -ve for cooling"
@@ -2122,45 +2296,59 @@
        },
        {
            "property": "VehicleProperty::HVAC_TEMPERATURE_CURRENT",
            "areas": [
                {
            "defaultValue": {
                "floatValues": [
                            17.3
                    19.1
                ]
            },
                    "areaId": 49
            "areas": [
                {
                    "areaId": "Constants::SEAT_1_LEFT"
                },
                {
                    "defaultValue": {
                        "floatValues": [
                            19.1
                        ]
                    "areaId": "Constants::SEAT_1_RIGHT"
                },
                    "areaId": 68
                {
                    "areaId": "Constants::SEAT_2_LEFT"
                },
                {
                    "areaId": "Constants::SEAT_2_RIGHT"
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER"
                }
            ]
        },
        {
            "property": "VehicleProperty::HVAC_TEMPERATURE_SET",
            "areas": [
                {
            "defaultValue": {
                "floatValues": [
                            16.0
                    17.0
                ]
            },
                    "areaId": 49,
            "areas": [
                {
                    "areaId": "Constants::SEAT_1_LEFT",
                    "minFloatValue": 16.0,
                    "maxFloatValue": 28.0
                },
                {
                    "defaultValue": {
                        "floatValues": [
                            20.0
                        ]
                    "areaId": "Constants::SEAT_1_RIGHT",
                    "minFloatValue": 16.0,
                    "maxFloatValue": 28.0
                },
                {
                    "areaId": "Constants::SEAT_2_LEFT",
                    "minFloatValue": 16.0,
                    "maxFloatValue": 28.0
                },
                    "areaId": 68,
                {
                    "areaId": "Constants::SEAT_2_RIGHT",
                    "minFloatValue": 16.0,
                    "maxFloatValue": 28.0
                },
                {
                    "areaId": "Constants::SEAT_2_CENTER",
                    "minFloatValue": 16.0,
                    "maxFloatValue": 28.0
                }
+2 −2
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ class FakeVehicleHardware : public IVehicleHardware {
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    ValueResultType getEchoReverseBytes(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    bool isHvacPropAndHvacNotAvailable(int32_t propId) const;
    bool isHvacPropAndHvacNotAvailable(int32_t propId, int32_t areaId) const;

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

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

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

    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
+29 −16
Original line number Diff line number Diff line
@@ -298,17 +298,28 @@ VhalResult<void> FakeVehicleHardware::setApPowerStateReport(const VehiclePropVal
    return {};
}

bool FakeVehicleHardware::isHvacPropAndHvacNotAvailable(int32_t propId) const {
bool FakeVehicleHardware::isHvacPropAndHvacNotAvailable(int32_t propId, int32_t areaId) const {
    std::unordered_set<int32_t> powerProps(std::begin(HVAC_POWER_PROPERTIES),
                                           std::end(HVAC_POWER_PROPERTIES));
    if (powerProps.count(propId)) {
        auto hvacPowerOnResult =
                mServerSidePropStore->readValue(toInt(VehicleProperty::HVAC_POWER_ON), HVAC_ALL);

        if (hvacPowerOnResult.ok() && hvacPowerOnResult.value()->value.int32Values.size() == 1 &&
            hvacPowerOnResult.value()->value.int32Values[0] == 0) {
        auto hvacPowerOnResults =
                mServerSidePropStore->readValuesForProperty(toInt(VehicleProperty::HVAC_POWER_ON));
        if (!hvacPowerOnResults.ok()) {
            ALOGW("failed to get HVAC_POWER_ON 0x%x, error: %s",
                  toInt(VehicleProperty::HVAC_POWER_ON), getErrorMsg(hvacPowerOnResults).c_str());
            return false;
        }
        auto& hvacPowerOnValues = hvacPowerOnResults.value();
        for (size_t j = 0; j < hvacPowerOnValues.size(); j++) {
            auto hvacPowerOnValue = std::move(hvacPowerOnValues[j]);
            if ((hvacPowerOnValue->areaId & areaId) == areaId) {
                if (hvacPowerOnValue->value.int32Values.size() == 1 &&
                    hvacPowerOnValue->value.int32Values[0] == 0) {
                    return true;
                }
                break;
            }
        }
    }
    return false;
}
@@ -369,7 +380,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
        return getUserHalProp(value);
    }

    if (isHvacPropAndHvacNotAvailable(propId)) {
    if (isHvacPropAndHvacNotAvailable(propId, value.areaId)) {
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
    }
@@ -419,7 +430,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getEchoReverseBytes(
    return std::move(gotValue);
}

void FakeVehicleHardware::sendHvacPropertiesCurrentValues() {
void FakeVehicleHardware::sendHvacPropertiesCurrentValues(int32_t areaId) {
    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);
@@ -431,6 +442,7 @@ void FakeVehicleHardware::sendHvacPropertiesCurrentValues() {
        auto& powerPropValues = powerPropResults.value();
        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->timestamp = elapsedRealtimeNano();
                // This will trigger a property change event for the current hvac property value.
@@ -439,6 +451,7 @@ void FakeVehicleHardware::sendHvacPropertiesCurrentValues() {
            }
        }
    }
}

VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
                                                           bool* isSpecialValue) {
@@ -455,10 +468,10 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        value.value.int32Values[0] == 1) {
        // If we are turning HVAC power on, send current hvac property values through on change
        // event.
        sendHvacPropertiesCurrentValues();
        sendHvacPropertiesCurrentValues(value.areaId);
    }

    if (isHvacPropAndHvacNotAvailable(propId)) {
    if (isHvacPropAndHvacNotAvailable(propId, value.areaId)) {
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
    }
+82 −49
Original line number Diff line number Diff line
@@ -1147,69 +1147,102 @@ TEST_F(FakeVehicleHardwareTest, testSetVehicleMapService) {
}

TEST_F(FakeVehicleHardwareTest, testGetHvacPropNotAvailable) {
    int seatAreaIds[5] = {SEAT_1_LEFT, SEAT_1_RIGHT, SEAT_2_LEFT, SEAT_2_CENTER, SEAT_2_RIGHT};
    for (int areaId : seatAreaIds) {
        StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                      .areaId = areaId,
                                                      .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];
            for (int powerDependentAreaId : seatAreaIds) {
                auto getValueResult = getValue(VehiclePropValue{
                        .prop = powerPropId,
                .areaId = HVAC_ALL,
                        .areaId = powerDependentAreaId,
                });

                if (areaId == powerDependentAreaId) {
                    EXPECT_FALSE(getValueResult.ok());
                    EXPECT_EQ(getValueResult.error(), StatusCode::NOT_AVAILABLE);
                } else {
                    EXPECT_TRUE(getValueResult.ok());
                }
            }
        }

        // Resetting HVAC_POWER_ON at areaId back to ON state to ensure that there's no dependence
        // on this value from any power dependent property values other than those with the same
        // areaId.
        setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                  .areaId = areaId,
                                  .value.int32Values = {1}});
    }
}

TEST_F(FakeVehicleHardwareTest, testSetHvacPropNotAvailable) {
    int seatAreaIds[5] = {SEAT_1_LEFT, SEAT_1_RIGHT, SEAT_2_LEFT, SEAT_2_CENTER, SEAT_2_RIGHT};
    for (int areaId : seatAreaIds) {
        StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                      .areaId = areaId,
                                                      .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,
        });
            for (int powerDependentAreaId : seatAreaIds) {
                StatusCode status = setValue(VehiclePropValue{.prop = powerPropId,
                                                              .areaId = powerDependentAreaId,
                                                              .value.int32Values = {1}});

                if (areaId == powerDependentAreaId) {
                    EXPECT_EQ(status, StatusCode::NOT_AVAILABLE);
                } else {
                    EXPECT_EQ(status, StatusCode::OK);
                }
            }
        }

        // Resetting HVAC_POWER_ON at areaId back to ON state to ensure that there's no dependence
        // on this value from any power dependent property values other than those with the same
        // areaId.
        setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                  .areaId = areaId,
                                  .value.int32Values = {1}});
    }
}

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) {
        StatusCode status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                                  .areaId = HVAC_ALL,
                                                      .areaId = areaId,
                                                      .value.int32Values = {0}});

        ASSERT_EQ(status, StatusCode::OK);

        clearChangedProperties();

    status = setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                       .areaId = HVAC_ALL,
        setValue(VehiclePropValue{.prop = toInt(VehicleProperty::HVAC_POWER_ON),
                                  .areaId = areaId,
                                  .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.
        // 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_EQ(event.areaId, areaId);
            EXPECT_THAT(event.prop, AnyOfArray(changedPropIds));
        }
    }
}

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