Loading automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/include/LinearFakeValueGenerator.h +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ class LinearFakeValueGenerator : public FakeValueGenerator { float dispersion; // Defines minimum and maximum value based on initial value. float increment; // Value that we will be added to currentValue with each timer tick. int64_t interval; long lastEventTimestamp; int64_t lastEventTimestamp; }; GeneratorCfg mGenCfg; Loading automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/LinearFakeValueGenerator.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ std::optional<VehiclePropValue> LinearFakeValueGenerator::nextEvent() { if (mGenCfg.lastEventTimestamp == 0) { mGenCfg.lastEventTimestamp = elapsedRealtimeNano(); } else { long nextEventTime = mGenCfg.lastEventTimestamp + mGenCfg.interval; int64_t nextEventTime = mGenCfg.lastEventTimestamp + mGenCfg.interval; // Prevent overflow. assert(nextEventTime > mGenCfg.lastEventTimestamp); mGenCfg.lastEventTimestamp = nextEventTime; Loading automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h +5 −2 Original line number Diff line number Diff line Loading @@ -99,12 +99,17 @@ class FakeVehicleHardware : public IVehicleHardware { const std::shared_ptr<VehiclePropValuePool> mValuePool; const std::shared_ptr<VehiclePropertyStore> mServerSidePropStore; const std::string mDefaultConfigDir; const std::string mOverrideConfigDir; ValueResultType getValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const; VhalResult<void> setValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); bool UseOverrideConfigDir(); private: // Expose private methods to unit test. friend class FakeVehicleHardwareTestHelper; Loading Loading @@ -156,8 +161,6 @@ class FakeVehicleHardware : public IVehicleHardware { aidl::android::hardware::automotive::vehicle::SetValueRequest> mPendingSetValueRequests; const std::string mDefaultConfigDir; const std::string mOverrideConfigDir; const bool mForceOverride; bool mAddExtraTestVendorConfigs; Loading automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +27 −18 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #include <dirent.h> #include <inttypes.h> #include <sys/types.h> #include <fstream> #include <regex> #include <unordered_set> #include <vector> Loading Loading @@ -205,9 +204,10 @@ void FakeVehicleHardware::storePropInitialValue(const ConfigDeclaration& config) // Create a separate instance for each individual zone VehiclePropValue prop = { .timestamp = elapsedRealtimeNano(), .areaId = curArea, .prop = propId, .timestamp = elapsedRealtimeNano(), .value = {}, }; if (config.initialAreaValues.empty()) { Loading Loading @@ -240,6 +240,8 @@ FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir, bool forceOverride) : mValuePool(std::make_unique<VehiclePropValuePool>()), mServerSidePropStore(new VehiclePropertyStore(mValuePool)), mDefaultConfigDir(defaultConfigDir), mOverrideConfigDir(overrideConfigDir), mFakeObd2Frame(new obd2frame::FakeObd2Frame(mServerSidePropStore)), mFakeUserHal(new FakeUserHal(mValuePool)), mRecurrentTimer(new RecurrentTimer()), Loading @@ -247,8 +249,6 @@ FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir, [this](const VehiclePropValue& value) { eventFromVehicleBus(value); })), mPendingGetValueRequests(this), mPendingSetValueRequests(this), mDefaultConfigDir(defaultConfigDir), mOverrideConfigDir(overrideConfigDir), mForceOverride(forceOverride) { init(); } Loading @@ -259,11 +259,15 @@ FakeVehicleHardware::~FakeVehicleHardware() { mGeneratorHub.reset(); } bool FakeVehicleHardware::UseOverrideConfigDir() { return mForceOverride || android::base::GetBoolProperty(OVERRIDE_PROPERTY, /*default_value=*/false); } std::unordered_map<int32_t, ConfigDeclaration> FakeVehicleHardware::loadConfigDeclarations() { std::unordered_map<int32_t, ConfigDeclaration> configsByPropId; loadPropConfigsFromDir(mDefaultConfigDir, &configsByPropId); if (mForceOverride || android::base::GetBoolProperty(OVERRIDE_PROPERTY, /*default_value=*/false)) { if (UseOverrideConfigDir()) { loadPropConfigsFromDir(mOverrideConfigDir, &configsByPropId); } return configsByPropId; Loading Loading @@ -938,7 +942,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getValue( << StringPrintf("failed to get special value: %d, error: %s", value.prop, getErrorMsg(result).c_str()); } else { return std::move(result); return result; } } Loading @@ -953,7 +957,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getValue( } } return std::move(readResult); return readResult; } DumpResult FakeVehicleHardware::dump(const std::vector<std::string>& options) { Loading Loading @@ -990,9 +994,11 @@ DumpResult FakeVehicleHardware::dump(const std::vector<std::string>& options) { } else if (EqualsIgnoreCase(option, "--genTestVendorConfigs")) { mAddExtraTestVendorConfigs = true; result.refreshPropertyConfigs = true; result.buffer = "successfully generated vendor configs"; } else if (EqualsIgnoreCase(option, "--restoreVendorConfigs")) { mAddExtraTestVendorConfigs = false; result.refreshPropertyConfigs = true; result.buffer = "successfully restored vendor configs"; } else { result.buffer = StringPrintf("Invalid option: %s\n", option.c_str()); } Loading Loading @@ -1328,9 +1334,9 @@ std::string FakeVehicleHardware::genFakeDataCommand(const std::vector<std::strin VehiclePropValue FakeVehicleHardware::createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode, int32_t targetDisplay) { VehiclePropValue value = { .prop = toInt(VehicleProperty::HW_KEY_INPUT), .areaId = 0, .timestamp = elapsedRealtimeNano(), .areaId = 0, .prop = toInt(VehicleProperty::HW_KEY_INPUT), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = {toInt(action), keyCode, targetDisplay}, }; Loading @@ -1340,9 +1346,9 @@ VehiclePropValue FakeVehicleHardware::createHwInputKeyProp(VehicleHwKeyInputActi VehiclePropValue FakeVehicleHardware::createHwKeyInputV2Prop(int32_t area, int32_t targetDisplay, int32_t keyCode, int32_t action, int32_t repeatCount) { VehiclePropValue value = {.prop = toInt(VehicleProperty::HW_KEY_INPUT_V2), VehiclePropValue value = {.timestamp = elapsedRealtimeNano(), .areaId = area, .timestamp = elapsedRealtimeNano(), .prop = toInt(VehicleProperty::HW_KEY_INPUT_V2), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = {targetDisplay, keyCode, action, repeatCount}, .value.int64Values = {elapsedRealtimeNano()}}; Loading Loading @@ -1380,9 +1386,9 @@ VehiclePropValue FakeVehicleHardware::createHwMotionInputProp( floatValues.push_back(size[i]); } VehiclePropValue value = {.prop = toInt(VehicleProperty::HW_MOTION_INPUT), VehiclePropValue value = {.timestamp = elapsedRealtimeNano(), .areaId = area, .timestamp = elapsedRealtimeNano(), .prop = toInt(VehicleProperty::HW_MOTION_INPUT), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = intValues, .value.floatValues = floatValues, Loading Loading @@ -1451,8 +1457,9 @@ std::string FakeVehicleHardware::dumpOnePropertyByConfig(int rowNumber, std::string FakeVehicleHardware::dumpOnePropertyById(int32_t propId, int32_t areaId) { VehiclePropValue value = { .prop = propId, .areaId = areaId, .prop = propId, .value = {}, }; bool isSpecialValue = false; auto result = maybeGetSpecialValue(value, &isSpecialValue); Loading Loading @@ -1523,12 +1530,12 @@ std::vector<std::string> FakeVehicleHardware::getOptionValues( while (*index < options.size()) { std::string option = options[*index]; if (SET_PROP_OPTIONS.find(option) != SET_PROP_OPTIONS.end()) { return std::move(values); return values; } values.push_back(option); (*index)++; } return std::move(values); return values; } Result<VehiclePropValue> FakeVehicleHardware::parsePropOptions( Loading Loading @@ -1808,6 +1815,7 @@ void FakeVehicleHardware::registerOnPropertyChangeEvent( void FakeVehicleHardware::registerOnPropertySetErrorEvent( std::unique_ptr<const PropertySetErrorCallback> callback) { // In FakeVehicleHardware, we will never use mOnPropertySetErrorCallback. if (mOnPropertySetErrorCallback != nullptr) { ALOGE("registerOnPropertySetErrorEvent must only be called once"); return; Loading Loading @@ -1836,8 +1844,9 @@ StatusCode FakeVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId, // Refresh the property value. In real implementation, this should poll the latest value // from vehicle bus. Here, we are just refreshing the existing value with a new timestamp. auto result = getValue(VehiclePropValue{ .prop = propId, .areaId = areaId, .prop = propId, .value = {}, }); if (!result.ok()) { // Failed to read current value, skip refreshing. Loading automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h +4 −2 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ class GRPCVehicleHardware : public IVehicleHardware { bool waitForConnected(std::chrono::milliseconds waitTime); protected: std::shared_mutex mCallbackMutex; std::unique_ptr<const PropertyChangeCallback> mOnPropChange; private: void ValuePollingLoop(); Loading @@ -90,8 +94,6 @@ class GRPCVehicleHardware : public IVehicleHardware { std::unique_ptr<proto::VehicleServer::Stub> mGrpcStub; std::thread mValuePollingThread; std::shared_mutex mCallbackMutex; std::unique_ptr<const PropertyChangeCallback> mOnPropChange; std::unique_ptr<const PropertySetErrorCallback> mOnSetErr; std::mutex mShutdownMutex; Loading Loading
automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/include/LinearFakeValueGenerator.h +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ class LinearFakeValueGenerator : public FakeValueGenerator { float dispersion; // Defines minimum and maximum value based on initial value. float increment; // Value that we will be added to currentValue with each timer tick. int64_t interval; long lastEventTimestamp; int64_t lastEventTimestamp; }; GeneratorCfg mGenCfg; Loading
automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/LinearFakeValueGenerator.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ std::optional<VehiclePropValue> LinearFakeValueGenerator::nextEvent() { if (mGenCfg.lastEventTimestamp == 0) { mGenCfg.lastEventTimestamp = elapsedRealtimeNano(); } else { long nextEventTime = mGenCfg.lastEventTimestamp + mGenCfg.interval; int64_t nextEventTime = mGenCfg.lastEventTimestamp + mGenCfg.interval; // Prevent overflow. assert(nextEventTime > mGenCfg.lastEventTimestamp); mGenCfg.lastEventTimestamp = nextEventTime; Loading
automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h +5 −2 Original line number Diff line number Diff line Loading @@ -99,12 +99,17 @@ class FakeVehicleHardware : public IVehicleHardware { const std::shared_ptr<VehiclePropValuePool> mValuePool; const std::shared_ptr<VehiclePropertyStore> mServerSidePropStore; const std::string mDefaultConfigDir; const std::string mOverrideConfigDir; ValueResultType getValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const; VhalResult<void> setValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); bool UseOverrideConfigDir(); private: // Expose private methods to unit test. friend class FakeVehicleHardwareTestHelper; Loading Loading @@ -156,8 +161,6 @@ class FakeVehicleHardware : public IVehicleHardware { aidl::android::hardware::automotive::vehicle::SetValueRequest> mPendingSetValueRequests; const std::string mDefaultConfigDir; const std::string mOverrideConfigDir; const bool mForceOverride; bool mAddExtraTestVendorConfigs; Loading
automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +27 −18 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #include <dirent.h> #include <inttypes.h> #include <sys/types.h> #include <fstream> #include <regex> #include <unordered_set> #include <vector> Loading Loading @@ -205,9 +204,10 @@ void FakeVehicleHardware::storePropInitialValue(const ConfigDeclaration& config) // Create a separate instance for each individual zone VehiclePropValue prop = { .timestamp = elapsedRealtimeNano(), .areaId = curArea, .prop = propId, .timestamp = elapsedRealtimeNano(), .value = {}, }; if (config.initialAreaValues.empty()) { Loading Loading @@ -240,6 +240,8 @@ FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir, bool forceOverride) : mValuePool(std::make_unique<VehiclePropValuePool>()), mServerSidePropStore(new VehiclePropertyStore(mValuePool)), mDefaultConfigDir(defaultConfigDir), mOverrideConfigDir(overrideConfigDir), mFakeObd2Frame(new obd2frame::FakeObd2Frame(mServerSidePropStore)), mFakeUserHal(new FakeUserHal(mValuePool)), mRecurrentTimer(new RecurrentTimer()), Loading @@ -247,8 +249,6 @@ FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir, [this](const VehiclePropValue& value) { eventFromVehicleBus(value); })), mPendingGetValueRequests(this), mPendingSetValueRequests(this), mDefaultConfigDir(defaultConfigDir), mOverrideConfigDir(overrideConfigDir), mForceOverride(forceOverride) { init(); } Loading @@ -259,11 +259,15 @@ FakeVehicleHardware::~FakeVehicleHardware() { mGeneratorHub.reset(); } bool FakeVehicleHardware::UseOverrideConfigDir() { return mForceOverride || android::base::GetBoolProperty(OVERRIDE_PROPERTY, /*default_value=*/false); } std::unordered_map<int32_t, ConfigDeclaration> FakeVehicleHardware::loadConfigDeclarations() { std::unordered_map<int32_t, ConfigDeclaration> configsByPropId; loadPropConfigsFromDir(mDefaultConfigDir, &configsByPropId); if (mForceOverride || android::base::GetBoolProperty(OVERRIDE_PROPERTY, /*default_value=*/false)) { if (UseOverrideConfigDir()) { loadPropConfigsFromDir(mOverrideConfigDir, &configsByPropId); } return configsByPropId; Loading Loading @@ -938,7 +942,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getValue( << StringPrintf("failed to get special value: %d, error: %s", value.prop, getErrorMsg(result).c_str()); } else { return std::move(result); return result; } } Loading @@ -953,7 +957,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getValue( } } return std::move(readResult); return readResult; } DumpResult FakeVehicleHardware::dump(const std::vector<std::string>& options) { Loading Loading @@ -990,9 +994,11 @@ DumpResult FakeVehicleHardware::dump(const std::vector<std::string>& options) { } else if (EqualsIgnoreCase(option, "--genTestVendorConfigs")) { mAddExtraTestVendorConfigs = true; result.refreshPropertyConfigs = true; result.buffer = "successfully generated vendor configs"; } else if (EqualsIgnoreCase(option, "--restoreVendorConfigs")) { mAddExtraTestVendorConfigs = false; result.refreshPropertyConfigs = true; result.buffer = "successfully restored vendor configs"; } else { result.buffer = StringPrintf("Invalid option: %s\n", option.c_str()); } Loading Loading @@ -1328,9 +1334,9 @@ std::string FakeVehicleHardware::genFakeDataCommand(const std::vector<std::strin VehiclePropValue FakeVehicleHardware::createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode, int32_t targetDisplay) { VehiclePropValue value = { .prop = toInt(VehicleProperty::HW_KEY_INPUT), .areaId = 0, .timestamp = elapsedRealtimeNano(), .areaId = 0, .prop = toInt(VehicleProperty::HW_KEY_INPUT), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = {toInt(action), keyCode, targetDisplay}, }; Loading @@ -1340,9 +1346,9 @@ VehiclePropValue FakeVehicleHardware::createHwInputKeyProp(VehicleHwKeyInputActi VehiclePropValue FakeVehicleHardware::createHwKeyInputV2Prop(int32_t area, int32_t targetDisplay, int32_t keyCode, int32_t action, int32_t repeatCount) { VehiclePropValue value = {.prop = toInt(VehicleProperty::HW_KEY_INPUT_V2), VehiclePropValue value = {.timestamp = elapsedRealtimeNano(), .areaId = area, .timestamp = elapsedRealtimeNano(), .prop = toInt(VehicleProperty::HW_KEY_INPUT_V2), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = {targetDisplay, keyCode, action, repeatCount}, .value.int64Values = {elapsedRealtimeNano()}}; Loading Loading @@ -1380,9 +1386,9 @@ VehiclePropValue FakeVehicleHardware::createHwMotionInputProp( floatValues.push_back(size[i]); } VehiclePropValue value = {.prop = toInt(VehicleProperty::HW_MOTION_INPUT), VehiclePropValue value = {.timestamp = elapsedRealtimeNano(), .areaId = area, .timestamp = elapsedRealtimeNano(), .prop = toInt(VehicleProperty::HW_MOTION_INPUT), .status = VehiclePropertyStatus::AVAILABLE, .value.int32Values = intValues, .value.floatValues = floatValues, Loading Loading @@ -1451,8 +1457,9 @@ std::string FakeVehicleHardware::dumpOnePropertyByConfig(int rowNumber, std::string FakeVehicleHardware::dumpOnePropertyById(int32_t propId, int32_t areaId) { VehiclePropValue value = { .prop = propId, .areaId = areaId, .prop = propId, .value = {}, }; bool isSpecialValue = false; auto result = maybeGetSpecialValue(value, &isSpecialValue); Loading Loading @@ -1523,12 +1530,12 @@ std::vector<std::string> FakeVehicleHardware::getOptionValues( while (*index < options.size()) { std::string option = options[*index]; if (SET_PROP_OPTIONS.find(option) != SET_PROP_OPTIONS.end()) { return std::move(values); return values; } values.push_back(option); (*index)++; } return std::move(values); return values; } Result<VehiclePropValue> FakeVehicleHardware::parsePropOptions( Loading Loading @@ -1808,6 +1815,7 @@ void FakeVehicleHardware::registerOnPropertyChangeEvent( void FakeVehicleHardware::registerOnPropertySetErrorEvent( std::unique_ptr<const PropertySetErrorCallback> callback) { // In FakeVehicleHardware, we will never use mOnPropertySetErrorCallback. if (mOnPropertySetErrorCallback != nullptr) { ALOGE("registerOnPropertySetErrorEvent must only be called once"); return; Loading Loading @@ -1836,8 +1844,9 @@ StatusCode FakeVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId, // Refresh the property value. In real implementation, this should poll the latest value // from vehicle bus. Here, we are just refreshing the existing value with a new timestamp. auto result = getValue(VehiclePropValue{ .prop = propId, .areaId = areaId, .prop = propId, .value = {}, }); if (!result.ok()) { // Failed to read current value, skip refreshing. Loading
automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h +4 −2 Original line number Diff line number Diff line Loading @@ -82,6 +82,10 @@ class GRPCVehicleHardware : public IVehicleHardware { bool waitForConnected(std::chrono::milliseconds waitTime); protected: std::shared_mutex mCallbackMutex; std::unique_ptr<const PropertyChangeCallback> mOnPropChange; private: void ValuePollingLoop(); Loading @@ -90,8 +94,6 @@ class GRPCVehicleHardware : public IVehicleHardware { std::unique_ptr<proto::VehicleServer::Stub> mGrpcStub; std::thread mValuePollingThread; std::shared_mutex mCallbackMutex; std::unique_ptr<const PropertyChangeCallback> mOnPropChange; std::unique_ptr<const PropertySetErrorCallback> mOnSetErr; std::mutex mShutdownMutex; Loading