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

Commit c2278c20 authored by Bryan Eyler's avatar Bryan Eyler Committed by Android (Google) Code Review
Browse files

Merge "Add default behavior for HVAC power"

parents a366070f 1c386b58
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@ namespace V2_0 {

namespace impl {

const VehicleProperty kHvacPowerProperties[] = {
    VehicleProperty::HVAC_FAN_SPEED,
    VehicleProperty::HVAC_FAN_DIRECTION,
};

const VehiclePropConfig kVehicleProperties[] = {
    {
        .prop = toInt(VehicleProperty::INFO_MAKE),
@@ -63,7 +68,10 @@ const VehiclePropConfig kVehicleProperties[] = {
        .prop = toInt(VehicleProperty::HVAC_POWER_ON),
        .access = VehiclePropertyAccess::READ_WRITE,
        .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
        .supportedAreas = toInt(VehicleAreaZone::ROW_1)
        .supportedAreas = toInt(VehicleAreaZone::ROW_1),
        // TODO(bryaneyler): Ideally, this is generated dynamically from
        // kHvacPowerProperties.
        .configString = "0x12400500,0x12400501"  // HVAC_FAN_SPEED,HVAC_FAN_DIRECTION
    },

    {
+22 −7
Original line number Diff line number Diff line
@@ -102,9 +102,9 @@ void DefaultVehicleHal::doGetPropertyAll(emulator::EmulatorMessage& /* rxMsg */,
    {
        std::lock_guard<std::mutex> lock(mPropsMutex);

        for (auto& propVal : mProps) {
        for (auto& prop : mProps) {
            emulator::VehiclePropValue* protoVal = respMsg.add_value();
            populateProtoVehiclePropValue(protoVal, propVal.get());
            populateProtoVehiclePropValue(protoVal, prop.second.get());
        }
    }
}
@@ -172,10 +172,9 @@ VehiclePropValue* DefaultVehicleHal::getVehiclePropValueLocked(int32_t propId, i
        areaId = 0;
    }

    for (auto& prop : mProps) {
        if ((prop->prop == propId) && (prop->areaId == areaId)) {
            return prop.get();
        }
    auto prop = mProps.find(std::make_pair(propId, areaId));
    if (prop != mProps.end()) {
        return prop->second.get();
    }
    ALOGW("%s: Property not found:  propId = 0x%x, areaId = 0x%x", __FUNCTION__, propId, areaId);
    return nullptr;
@@ -497,6 +496,18 @@ StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
    StatusCode status;
    switch (propId) {
        default:
            if (mHvacPowerProps.find(VehicleProperty(propId)) !=
                    mHvacPowerProps.end()) {
                auto prop = mProps.find(
                    std::make_pair(toInt(VehicleProperty::HVAC_POWER_ON), 0));
                if (prop != mProps.end()) {
                    if (prop->second->value.int32Values.size() == 1 &&
                        prop->second->value.int32Values[0] == 0) {
                        status = StatusCode::NOT_AVAILABLE;
                        break;
                    }
                }
            }
            status = updateProperty(propValue);
            if (status == StatusCode::OK) {
                // Send property update to emulator
@@ -518,6 +529,10 @@ void DefaultVehicleHal::onCreate() {
    // Initialize member variables
    mExit = 0;

    for (auto& prop : kHvacPowerProperties) {
        mHvacPowerProps.insert(prop);
    }

    // Get the list of configurations supported by this HAL
    std::vector<VehiclePropConfig> configs = listProperties();

@@ -579,7 +594,7 @@ void DefaultVehicleHal::onCreate() {
            prop->areaId = curArea;
            prop->prop = cfg.prop;
            setDefaultValue(prop.get());
            mProps.push_back(std::move(prop));
            mProps[std::make_pair(prop->prop, prop->areaId)] = std::move(prop);
        } while (supportedAreas != 0);
    }

+6 −2
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
#ifndef android_hardware_automotive_vehicle_V2_0_impl_DefaultVehicleHal_H_
#define android_hardware_automotive_vehicle_V2_0_impl_DefaultVehicleHal_H_

#include <map>
#include <memory>
#include <sys/socket.h>
#include <thread>
#include <unordered_set>

#include <utils/SystemClock.h>

@@ -93,9 +95,11 @@ private:
    void txMsg(emulator::EmulatorMessage& txMsg);
    StatusCode updateProperty(const VehiclePropValue& propValue);
private:
    // TODO:  Use a hashtable to support indexing props
    std::vector<std::unique_ptr<VehiclePropValue>> mProps;
    std::map<
        std::pair<int32_t /*VehicleProperty*/, int32_t /*areaId*/>,
        std::unique_ptr<VehiclePropValue>> mProps;
    std::atomic<int> mExit;
    std::unordered_set<VehicleProperty> mHvacPowerProps;
    std::mutex mPropsMutex;
    std::thread mThread;
    std::unique_ptr<CommBase> mComm{nullptr};