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

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

Merge "Add logic for VHAL versions > 2.0 to forward property information to...

Merge "Add logic for VHAL versions > 2.0 to forward property information to 2.0 Use this infrastructure to move OBD2_LIVE_FRAME support over to the Vehicle HAL 2.0 layer."
parents d4762a75 15e12268
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ void DefaultVehicleHal::doGetPropertyAll(emulator::EmulatorMessage& /* rxMsg */,

        for (auto& prop : mProps) {
            emulator::VehiclePropValue* protoVal = respMsg.add_value();
            populateProtoVehiclePropValue(protoVal, prop.second.get());
            populateProtoVehiclePropValue(protoVal, prop.second->get());
        }
    }
}
@@ -175,7 +175,7 @@ VehiclePropValue* DefaultVehicleHal::getVehiclePropValueLocked(int32_t propId, i

    auto prop = mProps.find(std::make_pair(propId, areaId));
    if (prop != mProps.end()) {
        return prop->second.get();
        return prop->second->get();
    }
    ALOGW("%s: Property not found:  propId = 0x%x, areaId = 0x%x", __func__, propId, areaId);
    return nullptr;
@@ -530,6 +530,13 @@ StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
    return status;
}

V2_0::StatusCode DefaultVehicleHal::addCustomProperty(int32_t property,
    std::unique_ptr<CustomVehiclePropertyHandler>&& handler) {
    mProps[std::make_pair(property, 0)] = std::move(handler);
    ALOGW("%s: Added custom property: propId = 0x%x", __func__, property);
    return StatusCode::OK;
}

// Parse supported properties list and generate vector of property values to hold current values.
void DefaultVehicleHal::onCreate() {
    // Initialize member variables
@@ -598,7 +605,11 @@ void DefaultVehicleHal::onCreate() {
            prop->areaId = curArea;
            prop->prop = cfg.prop;
            setDefaultValue(prop.get());
            mProps[std::make_pair(prop->prop, prop->areaId)] = std::move(prop);
            std::unique_ptr<CustomVehiclePropertyHandler> handler;
            handler.reset(new StoredValueCustomVehiclePropertyHandler());
            handler->set(*prop);
            mProps[std::make_pair(prop->prop, prop->areaId)] =
                    std::move(handler);
        } while (supportedAreas != 0);
    }

+63 −2
Original line number Diff line number Diff line
@@ -43,6 +43,30 @@ namespace V2_0 {
namespace impl {

class DefaultVehicleHal : public VehicleHal {
public:
    class CustomVehiclePropertyHandler {
    public:
        virtual VehiclePropValue* get() = 0;
        virtual StatusCode set(const VehiclePropValue& propValue) = 0;
        virtual ~CustomVehiclePropertyHandler() = default;
    };

protected:
    class StoredValueCustomVehiclePropertyHandler :
        public CustomVehiclePropertyHandler {
    public:
        VehiclePropValue* get() override {
            return mPropValue.get();
        }

        StatusCode set(const VehiclePropValue& propValue) {
            *mPropValue = propValue;
            return StatusCode::OK;
        }
private:
    std::unique_ptr<VehiclePropValue> mPropValue{new VehiclePropValue()};
};

public:
  DefaultVehicleHal() : mRecurrentTimer(
            std::bind(&DefaultVehicleHal::onContinuousPropertyTimer, this, std::placeholders::_1)) {
@@ -77,6 +101,43 @@ public:

    StatusCode unsubscribe(int32_t property) override;

    /**
     * Add custom property information to this HAL instance.
     *
     * This is useful for allowing later versions of Vehicle HAL to coalesce
     * the list of properties they support with a previous version of the HAL.
     *
     * @param property The identifier of the new property
     * @param handler The object that will handle get/set requests
     * @return OK on success, an error code on failure
     */
    virtual StatusCode addCustomProperty(int32_t,
        std::unique_ptr<CustomVehiclePropertyHandler>&&);

    /**
     * Add custom property information to this HAL instance.
     *
     * This is useful for allowing later versions of Vehicle HAL to coalesce
     * the list of properties they support with a previous version of the HAL.
     *
     * @param initialValue The initial value for the new property. This is not
     *                     constant data, as later set() operations can change
     *                     this value at will
     * @return OK on success, an error code on failure
     */
    virtual StatusCode addCustomProperty(
        const VehiclePropValue& initialValue) {
        std::unique_ptr<CustomVehiclePropertyHandler> handler;
        handler.reset(new StoredValueCustomVehiclePropertyHandler());
        StatusCode setResponse = handler->set(initialValue);
        if (StatusCode::OK == setResponse) {
          return addCustomProperty(initialValue.prop,
                                   std::move(handler));
        } else {
          return setResponse;
        }
    }

private:
    void doGetConfig(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
    void doGetConfigAll(emulator::EmulatorMessage& rxMsg, emulator::EmulatorMessage& respMsg);
@@ -106,7 +167,7 @@ private:
private:
    std::map<
        std::pair<int32_t /*VehicleProperty*/, int32_t /*areaId*/>,
        std::unique_ptr<VehiclePropValue>> mProps;
        std::unique_ptr<CustomVehiclePropertyHandler>> mProps;
    std::atomic<int> mExit;
    std::unordered_set<int32_t> mHvacPowerProps;
    std::mutex mPropsMutex;
+9 −18
Original line number Diff line number Diff line
@@ -120,12 +120,12 @@ static std::unique_ptr<Obd2SensorStore> fillDefaultObd2Frame(
    return sensorStore;
}

void DefaultVehicleHal::initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig) {
void DefaultVehicleHal::initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig,
    V2_0::VehiclePropValue* liveObd2Frame) {
    auto sensorStore = fillDefaultObd2Frame(propConfig.configArray[0],
            propConfig.configArray[1]);
    mLiveObd2Frame = createVehiclePropValue(
            V2_0::VehiclePropertyType::COMPLEX, 0);
    sensorStore->fillPropValue(mLiveObd2Frame.get(), "");
    sensorStore->fillPropValue(liveObd2Frame, "");
    liveObd2Frame->prop = V2_0::toInt(VehicleProperty::OBD2_LIVE_FRAME);
}

void DefaultVehicleHal::initObd2FreezeFrame(V2_0::VehiclePropConfig& propConfig) {
@@ -144,14 +144,6 @@ void DefaultVehicleHal::initObd2FreezeFrame(V2_0::VehiclePropConfig& propConfig)
    sensorStore->fillPropValue(mFreezeObd2Frames[2].get(), "P0123");
}

V2_0::StatusCode DefaultVehicleHal::fillObd2LiveFrame(V2_0::VehiclePropValue* v) {
    v->prop = V2_0::toInt(VehicleProperty::OBD2_LIVE_FRAME);
    v->value.int32Values = mLiveObd2Frame->value.int32Values;
    v->value.floatValues = mLiveObd2Frame->value.floatValues;
    v->value.bytes = mLiveObd2Frame->value.bytes;
    return V2_0::StatusCode::OK;
}

template<typename Iterable>
typename Iterable::const_iterator findPropValueAtTimestamp(
        const Iterable& frames,
@@ -224,8 +216,11 @@ void DefaultVehicleHal::onCreate() {
    std::vector<V2_0::VehiclePropConfig> configs = listProperties();
    for (auto& cfg : configs) {
        switch(cfg.prop) {
            case V2_0::toInt(V2_1::VehicleProperty::OBD2_LIVE_FRAME):
                initObd2LiveFrame(cfg);
            case V2_0::toInt(V2_1::VehicleProperty::OBD2_LIVE_FRAME): {
                auto liveObd2Frame = createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX, 0);
                initObd2LiveFrame(cfg, liveObd2Frame.get());
                mVehicleHal20->addCustomProperty(*liveObd2Frame);
            }
                break;
            case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME):
                initObd2FreezeFrame(cfg);
@@ -245,10 +240,6 @@ DefaultVehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
    auto& pool = *getValuePool();

    switch (propId) {
    case V2_0::toInt(V2_1::VehicleProperty::OBD2_LIVE_FRAME):
        v = pool.obtainComplex();
        *outStatus = fillObd2LiveFrame(v.get());
        return v;
    case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME):
        v = pool.obtainComplex();
        *outStatus = fillObd2FreezeFrame(requestedPropValue, v.get());
+5 −5
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ using namespace std::placeholders;

class DefaultVehicleHal : public V2_0::VehicleHal {
public:
    DefaultVehicleHal(V2_0::VehicleHal* vhal20) : mVehicleHal20(vhal20) {}
    DefaultVehicleHal(V2_0::impl::DefaultVehicleHal* vhal20) :
          mVehicleHal20(vhal20) {}

    std::vector<V2_0::VehiclePropConfig> listProperties() override {
        std::vector<V2_0::VehiclePropConfig> propConfigs(mVehicleHal20->listProperties());
@@ -70,17 +71,16 @@ public:
    void onCreate() override;

private:
    void initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig);
    void initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig,
        V2_0::VehiclePropValue* liveObd2Frame);
    void initObd2FreezeFrame(V2_0::VehiclePropConfig& propConfig);
    V2_0::StatusCode fillObd2LiveFrame(V2_0::VehiclePropValue* v);
    V2_0::StatusCode fillObd2FreezeFrame(const V2_0::VehiclePropValue& requestedPropValue,
            V2_0::VehiclePropValue* v);
    V2_0::StatusCode fillObd2DtcInfo(V2_0::VehiclePropValue *v);
    V2_0::StatusCode clearObd2FreezeFrames(const V2_0::VehiclePropValue& propValue);

private:
    V2_0::VehicleHal* mVehicleHal20;
    std::unique_ptr<V2_0::VehiclePropValue> mLiveObd2Frame {nullptr};
    V2_0::impl::DefaultVehicleHal* mVehicleHal20;
    std::vector<std::unique_ptr<V2_0::VehiclePropValue>> mFreezeObd2Frames;
};