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

Commit 4065fbfa authored by Hao Chen's avatar Hao Chen
Browse files

Vehicle HAL client reads the config from the server instead of DefaultConfigs.h

Test: Launch cf auto instance (with default vhal) and

atest
packages/services/Car/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarPropertyTest.java

Bug: 188005769

Change-Id: If98db799be8c894bd9a7ba44bf3075f1f7384e5c
parent 87527e23
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <android-base/logging.h>
#include <utils/SystemClock.h>

#include "DefaultConfig.h"
#include "EmulatedVehicleConnector.h"
#include "JsonFakeValueGenerator.h"
#include "LinearFakeValueGenerator.h"
@@ -39,6 +38,10 @@ EmulatedUserHal* EmulatedVehicleConnector::getEmulatedUserHal() {
    return &mEmulatedUserHal;
}

void EmulatedVehicleConnector::triggerSendAllValues() {
    sendAllValuesToClient();
}

StatusCode EmulatedVehicleConnector::onSetProperty(const VehiclePropValue& value,
                                                   bool updateStatus) {
    if (mEmulatedUserHal.isSupported(value.prop)) {
+3 −1
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@ namespace impl {

class EmulatedVehicleConnector : public IPassThroughConnector<VehicleHalClient, VehicleHalServer> {
  public:
    EmulatedVehicleConnector() {}
    EmulatedVehicleConnector() = default;

    EmulatedUserHal* getEmulatedUserHal();

    // Methods from VehicleHalServer
    void triggerSendAllValues() override;

    StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override;

    bool onDump(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
+22 −35
Original line number Diff line number Diff line
@@ -105,9 +105,6 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH
      mVehicleClient(client),
      mEmulatedUserHal(emulatedUserHal) {
    initStaticConfig();
    for (size_t i = 0; i < arraysize(kVehicleProperties); i++) {
        mPropStore->registerProperty(kVehicleProperties[i].config);
    }
    mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue,
                                                            this, std::placeholders::_1,
                                                            std::placeholders::_2));
@@ -180,7 +177,13 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
                v = getValuePool()->obtain(*internalPropValue);
            }

            *outStatus = v != nullptr ? StatusCode::OK : StatusCode::INVALID_ARG;
            if (!v) {
                *outStatus = StatusCode::INVALID_ARG;
            } else if (v->status == VehiclePropertyStatus::AVAILABLE) {
                *outStatus = StatusCode::OK;
            } else {
                *outStatus = StatusCode::TRY_AGAIN;
            }
            break;
    }
    if (v.get()) {
@@ -280,57 +283,41 @@ static bool isDiagnosticProperty(VehiclePropConfig propConfig) {
void EmulatedVehicleHal::onCreate() {
    static constexpr bool shouldUpdateStatus = true;

    for (auto& it : kVehicleProperties) {
        VehiclePropConfig cfg = it.config;
        int32_t numAreas = cfg.areaConfigs.size();
    auto configs = mVehicleClient->getAllPropertyConfig();

    for (const auto& cfg : configs) {
        if (isDiagnosticProperty(cfg)) {
            // do not write an initial empty value for the diagnostic properties
            // as we will initialize those separately.
            continue;
        }

        // A global property will have only a single area
        if (isGlobalProp(cfg.prop)) {
            numAreas = 1;
        }
        int32_t numAreas = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs.size();

        for (int i = 0; i < numAreas; i++) {
            int32_t curArea;

            if (isGlobalProp(cfg.prop)) {
                curArea = 0;
            } else {
                curArea = cfg.areaConfigs[i].areaId;
            }
            int32_t curArea = isGlobalProp(cfg.prop) ? 0 : cfg.areaConfigs[i].areaId;

            // Create a separate instance for each individual zone
            VehiclePropValue prop = {
                    .areaId = curArea,
                    .prop = cfg.prop,
                    .status = VehiclePropertyStatus::UNAVAILABLE,
            };

            if (it.initialAreaValues.size() > 0) {
                auto valueForAreaIt = it.initialAreaValues.find(curArea);
                if (valueForAreaIt != it.initialAreaValues.end()) {
                    prop.value = valueForAreaIt->second;
                } else {
                    ALOGW("%s failed to get default value for prop 0x%x area 0x%x",
                            __func__, cfg.prop, curArea);
                }
            } else {
                prop.value = it.initialValue;
            if (mInitVhalValueOverride) {
                for (auto& itOverride : mVehiclePropertiesOverride) {
                    if (itOverride.prop == cfg.prop) {
                        prop.status = VehiclePropertyStatus::AVAILABLE;
                        prop.value = itOverride.value;
                    }
                }
            }
            }
            mPropStore->writeValue(prop, shouldUpdateStatus);
        }
    }

    mVehicleClient->triggerSendAllValues();

    initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME));
    initObd2FreezeFrame(*mPropStore->getConfigOrDie(OBD2_FREEZE_FRAME));
    mInEmulator = isInEmulator();
@@ -414,8 +401,8 @@ void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value, bool upd
}

void EmulatedVehicleHal::initStaticConfig() {
    for (auto&& it = std::begin(kVehicleProperties); it != std::end(kVehicleProperties); ++it) {
        const auto& cfg = it->config;
    auto configs = mVehicleClient->getAllPropertyConfig();
    for (auto&& cfg : configs) {
        VehiclePropertyStore::TokenFunction tokenFunction = nullptr;

        switch (cfg.prop) {
+1 −1
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@
#include <vhal_v2_0/VehicleHal.h>
#include "vhal_v2_0/VehiclePropertyStore.h"

#include "DefaultConfig.h"
#include "EmulatedUserHal.h"
#include "EmulatedVehicleConnector.h"
#include "GeneratorHub.h"
#include "PropertyUtils.h"
#include "VehicleEmulator.h"

namespace android {
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ class VehicleHalClient : public IVehicleClient {
    // Type of callback function for handling the new property values
    using PropertyCallBackType = std::function<void(const VehiclePropValue&, bool updateStatus)>;

    // The server will call sendAllValuesToClient, onPropertyValue will be called when values are
    // received.
    virtual void triggerSendAllValues() = 0;

    // Method from IVehicleClient
    void onPropertyValue(const VehiclePropValue& value, bool updateStatus) override;

Loading