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

Commit 78acb2e3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "vhal_static_lib"

* changes:
  Define a makefile for vhal static libs.
  Make HVAC dep properties unavailable to get when power is off.
parents 2e550628 842efa2e
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_defaults {
    name: "VehicleHalInterfaceDefaults",
    static_libs: [
        "android.hardware.automotive.vehicle-V2-ndk",
    ],
}
+0 −7
Original line number Diff line number Diff line
@@ -18,13 +18,6 @@ package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_defaults {
    name: "VehicleHalInterfaceDefaults",
    static_libs: [
        "android.hardware.automotive.vehicle-V2-ndk",
    ],
}

cc_defaults {
    name: "VehicleHalDefaults",
    static_libs: [
+2 −1
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);
    bool isHvacPropAndHvacNotAvailable(int32_t propId) const;

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

@@ -236,6 +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();

    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
+34 −1
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ VhalResult<void> FakeVehicleHardware::setApPowerStateReport(const VehiclePropVal
    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::end(HVAC_POWER_PROPERTIES));
    if (powerProps.count(propId)) {
@@ -366,6 +366,11 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
        return getUserHalProp(value);
    }

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

    switch (propId) {
        case OBD2_FREEZE_FRAME:
            *isSpecialValue = true;
@@ -408,6 +413,27 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getEchoReverseBytes(
    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,
                                                           bool* isSpecialValue) {
    *isSpecialValue = false;
@@ -419,6 +445,13 @@ 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();
    }

    if (isHvacPropAndHvacNotAvailable(propId)) {
        *isSpecialValue = true;
        return StatusError(StatusCode::NOT_AVAILABLE) << "hvac not available";
+66 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ using ::android::base::expected;
using ::android::base::ScopedLockAssertion;
using ::android::base::StringPrintf;
using ::android::base::unexpected;
using ::testing::AnyOfArray;
using ::testing::ContainerEq;
using ::testing::ContainsRegex;
using ::testing::Eq;
@@ -1140,6 +1141,71 @@ TEST_F(FakeVehicleHardwareTest, testSetVehicleMapService) {
    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) {
    for (VehicleProperty prop : std::vector<VehicleProperty>({
                 VehicleProperty::INITIAL_USER_INFO,
Loading