Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,12 @@ #define LOG_TAG "DefaultVehicleHal_v2_0" #include <android-base/macros.h> #include <android-base/properties.h> #include <android/log.h> #include <dirent.h> #include <sys/system_properties.h> #include <fstream> #include <regex> #include "EmulatedVehicleHal.h" #include "JsonFakeValueGenerator.h" Loading Loading @@ -101,6 +105,30 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue, this, std::placeholders::_1, std::placeholders::_2)); mInitVhalValueOverride = android::base::GetBoolProperty("persist.vendor.vhal_init_value_override", false); if (mInitVhalValueOverride) { getAllPropertiesOverride(); } } void EmulatedVehicleHal::getAllPropertiesOverride() { if (auto dir = opendir("/vendor/etc/vhaloverride/")) { std::regex reg_json(".*[.]json", std::regex::icase); while (auto f = readdir(dir)) { if (!regex_match(f->d_name, reg_json)) { continue; } std::string file = "/vendor/etc/vhaloverride/" + std::string(f->d_name); JsonFakeValueGenerator tmpGenerator(file); std::vector<VehiclePropValue> propvalues = tmpGenerator.getAllEvents(); mVehiclePropertiesOverride.insert(std::end(mVehiclePropertiesOverride), std::begin(propvalues), std::end(propvalues)); } closedir(dir); } } VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( Loading Loading @@ -277,6 +305,13 @@ void EmulatedVehicleHal::onCreate() { } } else { prop.value = it.initialValue; if (mInitVhalValueOverride) { for (auto& itOverride : mVehiclePropertiesOverride) { if (itOverride.prop == cfg.prop) { prop.value = itOverride.value; } } } } mPropStore->writeValue(prop, shouldUpdateStatus); } Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h +3 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public: // Methods from EmulatedVehicleHalIface bool setPropertyFromVehicle(const VehiclePropValue& propValue) override; std::vector<VehiclePropValue> getAllProperties() const override; void getAllPropertiesOverride(); private: constexpr std::chrono::nanoseconds hertzToNanoseconds(float hz) const { Loading @@ -87,6 +88,8 @@ private: RecurrentTimer mRecurrentTimer; VehicleHalClient* mVehicleClient; bool mInEmulator; bool mInitVhalValueOverride; std::vector<VehiclePropValue> mVehiclePropertiesOverride; }; } // impl Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/JsonFakeValueGenerator.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,22 @@ JsonFakeValueGenerator::JsonFakeValueGenerator(const VehiclePropValue& request) mNumOfIterations = v.int32Values.size() < 2 ? -1 : v.int32Values[1]; } JsonFakeValueGenerator::JsonFakeValueGenerator(std::string path) { std::ifstream ifs(path); if (!ifs) { ALOGE("%s: couldn't open %s for parsing.", __func__, path.c_str()); } mGenCfg = { .index = 0, .events = parseFakeValueJson(ifs), }; mNumOfIterations = mGenCfg.events.size(); } std::vector<VehiclePropValue> JsonFakeValueGenerator::getAllEvents() { return mGenCfg.events; } VehiclePropValue JsonFakeValueGenerator::nextEvent() { VehiclePropValue generatedValue; if (!hasNext()) { Loading Loading @@ -109,6 +125,7 @@ std::vector<VehiclePropValue> JsonFakeValueGenerator::parseFakeValueJson(std::is Json::Value rawEventValue = rawEvent["value"]; auto& value = event.value; int32_t count; switch (getPropType(event.prop)) { case VehiclePropertyType::BOOLEAN: case VehiclePropertyType::INT32: Loading @@ -126,6 +143,13 @@ std::vector<VehiclePropValue> JsonFakeValueGenerator::parseFakeValueJson(std::is case VehiclePropertyType::STRING: value.stringValue = rawEventValue.asString(); break; case VehiclePropertyType::INT32_VEC: value.int32Values.resize(rawEventValue.size()); count = 0; for (auto& it : rawEventValue) { value.int32Values[count++] = it.asInt(); } break; case VehiclePropertyType::MIXED: copyMixedValueJson(value, rawEventValue); if (isDiagnosticProperty(event.prop)) { Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/JsonFakeValueGenerator.h +3 −0 Original line number Diff line number Diff line Loading @@ -41,9 +41,12 @@ private: public: JsonFakeValueGenerator(const VehiclePropValue& request); JsonFakeValueGenerator(std::string path); ~JsonFakeValueGenerator() = default; VehiclePropValue nextEvent(); std::vector<VehiclePropValue> getAllEvents(); bool hasNext(); Loading Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,12 @@ #define LOG_TAG "DefaultVehicleHal_v2_0" #include <android-base/macros.h> #include <android-base/properties.h> #include <android/log.h> #include <dirent.h> #include <sys/system_properties.h> #include <fstream> #include <regex> #include "EmulatedVehicleHal.h" #include "JsonFakeValueGenerator.h" Loading Loading @@ -101,6 +105,30 @@ EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore, VehicleH mVehicleClient->registerPropertyValueCallback(std::bind(&EmulatedVehicleHal::onPropertyValue, this, std::placeholders::_1, std::placeholders::_2)); mInitVhalValueOverride = android::base::GetBoolProperty("persist.vendor.vhal_init_value_override", false); if (mInitVhalValueOverride) { getAllPropertiesOverride(); } } void EmulatedVehicleHal::getAllPropertiesOverride() { if (auto dir = opendir("/vendor/etc/vhaloverride/")) { std::regex reg_json(".*[.]json", std::regex::icase); while (auto f = readdir(dir)) { if (!regex_match(f->d_name, reg_json)) { continue; } std::string file = "/vendor/etc/vhaloverride/" + std::string(f->d_name); JsonFakeValueGenerator tmpGenerator(file); std::vector<VehiclePropValue> propvalues = tmpGenerator.getAllEvents(); mVehiclePropertiesOverride.insert(std::end(mVehiclePropertiesOverride), std::begin(propvalues), std::end(propvalues)); } closedir(dir); } } VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( Loading Loading @@ -277,6 +305,13 @@ void EmulatedVehicleHal::onCreate() { } } else { prop.value = it.initialValue; if (mInitVhalValueOverride) { for (auto& itOverride : mVehiclePropertiesOverride) { if (itOverride.prop == cfg.prop) { prop.value = itOverride.value; } } } } mPropStore->writeValue(prop, shouldUpdateStatus); } Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.h +3 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public: // Methods from EmulatedVehicleHalIface bool setPropertyFromVehicle(const VehiclePropValue& propValue) override; std::vector<VehiclePropValue> getAllProperties() const override; void getAllPropertiesOverride(); private: constexpr std::chrono::nanoseconds hertzToNanoseconds(float hz) const { Loading @@ -87,6 +88,8 @@ private: RecurrentTimer mRecurrentTimer; VehicleHalClient* mVehicleClient; bool mInEmulator; bool mInitVhalValueOverride; std::vector<VehiclePropValue> mVehiclePropertiesOverride; }; } // impl Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/JsonFakeValueGenerator.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,22 @@ JsonFakeValueGenerator::JsonFakeValueGenerator(const VehiclePropValue& request) mNumOfIterations = v.int32Values.size() < 2 ? -1 : v.int32Values[1]; } JsonFakeValueGenerator::JsonFakeValueGenerator(std::string path) { std::ifstream ifs(path); if (!ifs) { ALOGE("%s: couldn't open %s for parsing.", __func__, path.c_str()); } mGenCfg = { .index = 0, .events = parseFakeValueJson(ifs), }; mNumOfIterations = mGenCfg.events.size(); } std::vector<VehiclePropValue> JsonFakeValueGenerator::getAllEvents() { return mGenCfg.events; } VehiclePropValue JsonFakeValueGenerator::nextEvent() { VehiclePropValue generatedValue; if (!hasNext()) { Loading Loading @@ -109,6 +125,7 @@ std::vector<VehiclePropValue> JsonFakeValueGenerator::parseFakeValueJson(std::is Json::Value rawEventValue = rawEvent["value"]; auto& value = event.value; int32_t count; switch (getPropType(event.prop)) { case VehiclePropertyType::BOOLEAN: case VehiclePropertyType::INT32: Loading @@ -126,6 +143,13 @@ std::vector<VehiclePropValue> JsonFakeValueGenerator::parseFakeValueJson(std::is case VehiclePropertyType::STRING: value.stringValue = rawEventValue.asString(); break; case VehiclePropertyType::INT32_VEC: value.int32Values.resize(rawEventValue.size()); count = 0; for (auto& it : rawEventValue) { value.int32Values[count++] = it.asInt(); } break; case VehiclePropertyType::MIXED: copyMixedValueJson(value, rawEventValue); if (isDiagnosticProperty(event.prop)) { Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/JsonFakeValueGenerator.h +3 −0 Original line number Diff line number Diff line Loading @@ -41,9 +41,12 @@ private: public: JsonFakeValueGenerator(const VehiclePropValue& request); JsonFakeValueGenerator(std::string path); ~JsonFakeValueGenerator() = default; VehiclePropValue nextEvent(); std::vector<VehiclePropValue> getAllEvents(); bool hasNext(); Loading