diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h index 4a42d79b0b..c8e11e3c30 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h @@ -84,6 +84,28 @@ constexpr int WHEEL_REAR_RIGHT = (int)VehicleAreaWheel::RIGHT_REAR; const int32_t kGenerateFakeDataControllingProperty = 0x0666 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED; +/** + * This property is used for test purpose to set properties' value from vehicle. + * For example: Mocking hard button press triggering a HVAC fan speed change. + * Android set kSetPropertyFromVehcileForTest with an array of integer {HVAC_FAN_SPEED, value of + * fan speed} and a long value indicates the timestamp of the events . + * It only works with integer type properties. + */ +const int32_t kSetIntPropertyFromVehcileForTest = + 0x1112 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED; +/** + * This property is used for test purpose to set properties' value from vehicle. + * It only works with float type properties. + */ +const int32_t kSetFloatPropertyFromVehcileForTest = + 0x1113 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED; +/** + * This property is used for test purpose to set properties' value from vehicle. + * It only works with boolean type properties. + */ +const int32_t kSetBooleanPropertyFromVehcileForTest = + 0x1114 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED; + /** * This property is used for test purpose. End to end tests use this property to test set and get * method for MIXED type properties. @@ -636,6 +658,37 @@ const ConfigDeclaration kVehicleProperties[]{ .prop = kGenerateFakeDataControllingProperty, .access = VehiclePropertyAccess::WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {1, 0, 0, 2, 0, 0, 0, 0, 0}, + }, + }, + + { + .config = + { + .prop = kSetIntPropertyFromVehcileForTest, + .access = VehiclePropertyAccess::WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {0, 0, 0, 2, 1, 0, 0, 0, 0}, + }, + }, + + { + .config = + { + .prop = kSetFloatPropertyFromVehcileForTest, + .access = VehiclePropertyAccess::WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {0, 0, 1, 0, 1, 0, 1, 0, 0}, + }, + }, + + { + .config = + { + .prop = kSetBooleanPropertyFromVehcileForTest, + .access = VehiclePropertyAccess::WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {0, 1, 1, 0, 1, 0, 0, 0, 0}, }, }, diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp index b4f1f07323..9d249be954 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp @@ -131,6 +131,36 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { static constexpr bool shouldUpdateStatus = false; + // set the value from vehcile side, used in end to end test. + if (propValue.prop == kSetIntPropertyFromVehcileForTest) { + auto mockValue = createVehiclePropValue(VehiclePropertyType::INT32, 1); + mockValue->prop = propValue.value.int32Values[0]; + mockValue->value.int32Values[0] = propValue.value.int32Values[1]; + mockValue->timestamp = propValue.value.int64Values[0]; + mockValue->areaId = propValue.areaId; + setPropertyFromVehicle(*mockValue); + return StatusCode::OK; + } + + if (propValue.prop == kSetFloatPropertyFromVehcileForTest) { + auto mockValue = createVehiclePropValue(VehiclePropertyType::FLOAT, 1); + mockValue->prop = propValue.value.int32Values[0]; + mockValue->value.floatValues[0] = propValue.value.floatValues[0]; + mockValue->timestamp = propValue.value.int64Values[0]; + mockValue->areaId = propValue.areaId; + setPropertyFromVehicle(*mockValue); + return StatusCode::OK; + } + if (propValue.prop == kSetBooleanPropertyFromVehcileForTest) { + auto mockValue = createVehiclePropValue(VehiclePropertyType::BOOLEAN, 1); + mockValue->prop = propValue.value.int32Values[1]; + mockValue->value.int32Values[0] = propValue.value.int32Values[0]; + mockValue->timestamp = propValue.value.int64Values[0]; + mockValue->areaId = propValue.areaId; + setPropertyFromVehicle(*mockValue); + return StatusCode::OK; + } + if (propValue.prop == kGenerateFakeDataControllingProperty) { StatusCode status = handleGenerateFakeDataRequest(propValue); if (status != StatusCode::OK) { @@ -198,12 +228,19 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) { return StatusCode::NOT_AVAILABLE; } - if (!mPropStore->writeValue(propValue, shouldUpdateStatus)) { - return StatusCode::INVALID_ARG; + /** + * After checking all conditions, such as the property is available, a real vhal will + * sent the events to Car ECU to take actions. + * Google HAL will just add a timestamp for the value and triggle the callback to android. + */ + VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(propValue); + updatedPropValue->timestamp = elapsedRealtimeNano(); + if (!mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus)) { + return StatusCode::INTERNAL_ERROR; } - getEmulatorOrDie()->doSetValueFromClient(propValue); - doHalEvent(getValuePool()->obtain(propValue)); + getEmulatorOrDie()->doSetValueFromClient(*updatedPropValue); + doHalEvent(std::move(updatedPropValue)); return StatusCode::OK; }