diff --git a/automotive/vehicle/aidl/impl/default_config/config/DefaultProperties.json b/automotive/vehicle/aidl/impl/default_config/config/DefaultProperties.json index 0dfb123b4b..b9f784b717 100644 --- a/automotive/vehicle/aidl/impl/default_config/config/DefaultProperties.json +++ b/automotive/vehicle/aidl/impl/default_config/config/DefaultProperties.json @@ -3387,7 +3387,7 @@ "property": "VehicleProperty::CRUISE_CONTROL_TYPE", "defaultValue": { "int32Values": [ - "CruiseControlType::STANDARD" + "CruiseControlType::ADAPTIVE" ] }, "areas": [ diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h b/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h index 502d957ef4..f130fa4615 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h @@ -189,6 +189,7 @@ class FakeVehicleHardware : public IVehicleHardware { VhalResult maybeSetSpecialValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value, bool* isSpecialValue); + VhalResult isCruiseControlTypeStandard() const; ValueResultType maybeGetSpecialValue( const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value, bool* isSpecialValue) const; diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp index 4934771363..efd7f8e6a3 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp @@ -52,6 +52,8 @@ namespace fake { namespace { +using ::aidl::android::hardware::automotive::vehicle::CruiseControlCommand; +using ::aidl::android::hardware::automotive::vehicle::CruiseControlType; using ::aidl::android::hardware::automotive::vehicle::ErrorState; using ::aidl::android::hardware::automotive::vehicle::GetValueRequest; using ::aidl::android::hardware::automotive::vehicle::GetValueResult; @@ -611,6 +613,18 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::getUserHalProp( } } +VhalResult FakeVehicleHardware::isCruiseControlTypeStandard() const { + auto isCruiseControlTypeAvailableResult = + isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_TYPE)); + if (!isCruiseControlTypeAvailableResult.ok()) { + return isCruiseControlTypeAvailableResult.error(); + } + auto cruiseControlTypeValue = + mServerSidePropStore->readValue(toInt(VehicleProperty::CRUISE_CONTROL_TYPE)); + return cruiseControlTypeValue.value()->value.int32Values[0] == + toInt(CruiseControlType::STANDARD); +} + FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue( const VehiclePropValue& value, bool* isSpecialValue) const { *isSpecialValue = false; @@ -638,6 +652,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue( return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) << "hvac not available"; } + VhalResult isAdasPropertyAvailableResult; switch (propId) { case OBD2_FREEZE_FRAME: *isSpecialValue = true; @@ -660,17 +675,34 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue( *isSpecialValue = true; return StatusError((StatusCode)VENDOR_ERROR_CODE); case toInt(VehicleProperty::CRUISE_CONTROL_TARGET_SPEED): - [[fallthrough]]; - case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP): - [[fallthrough]]; - case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE): { - auto isAdasPropertyAvailableResult = + isAdasPropertyAvailableResult = isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE)); if (!isAdasPropertyAvailableResult.ok()) { *isSpecialValue = true; return isAdasPropertyAvailableResult.error(); } return nullptr; + case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP): + [[fallthrough]]; + case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE): { + isAdasPropertyAvailableResult = + isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE)); + if (!isAdasPropertyAvailableResult.ok()) { + *isSpecialValue = true; + return isAdasPropertyAvailableResult.error(); + } + auto isCruiseControlTypeStandardResult = isCruiseControlTypeStandard(); + if (!isCruiseControlTypeStandardResult.ok()) { + *isSpecialValue = true; + return isCruiseControlTypeStandardResult.error(); + } + if (isCruiseControlTypeStandardResult.value()) { + *isSpecialValue = true; + return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) + << "tried to get target time gap or lead vehicle measured distance value " + << "while on a standard CC setting"; + } + return nullptr; } default: // Do nothing. @@ -730,7 +762,13 @@ void FakeVehicleHardware::sendAdasPropertiesState(int32_t propertyId, int32_t st } auto& dependentPropConfig = dependentPropConfigResult.value(); for (auto& areaConfig : dependentPropConfig->areaConfigs) { - auto propValue = createAdasStateReq(dependentPropId, areaConfig.areaId, state); + int32_t hardcoded_state = state; + // TODO: restore old/initial values here instead of hardcoded value (b/295542701) + if (state == 1 && dependentPropId == toInt(VehicleProperty::CRUISE_CONTROL_TYPE)) { + hardcoded_state = toInt(CruiseControlType::ADAPTIVE); + } + auto propValue = + createAdasStateReq(dependentPropId, areaConfig.areaId, hardcoded_state); // This will trigger a property change event for the current ADAS property value. mServerSidePropStore->writeValue(std::move(propValue), /*updateStatus=*/true, VehiclePropertyStore::EventMode::ALWAYS); @@ -777,6 +815,8 @@ VhalResult FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu } } + VhalResult isAdasPropertyAvailableResult; + VhalResult isCruiseControlTypeStandardResult; switch (propId) { case toInt(VehicleProperty::AP_POWER_STATE_REPORT): *isSpecialValue = true; @@ -802,7 +842,7 @@ VhalResult FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu *isSpecialValue = true; return setHvacTemperatureValueSuggestion(value); case toInt(VehicleProperty::LANE_CENTERING_ASSIST_COMMAND): { - auto isAdasPropertyAvailableResult = + isAdasPropertyAvailableResult = isAdasPropertyAvailable(toInt(VehicleProperty::LANE_CENTERING_ASSIST_STATE)); if (!isAdasPropertyAvailableResult.ok()) { *isSpecialValue = true; @@ -810,14 +850,47 @@ VhalResult FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu return isAdasPropertyAvailableResult; } case toInt(VehicleProperty::CRUISE_CONTROL_COMMAND): - [[fallthrough]]; - case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP): { - auto isAdasPropertyAvailableResult = + isAdasPropertyAvailableResult = isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE)); if (!isAdasPropertyAvailableResult.ok()) { *isSpecialValue = true; + return isAdasPropertyAvailableResult; } - return isAdasPropertyAvailableResult; + isCruiseControlTypeStandardResult = isCruiseControlTypeStandard(); + if (!isCruiseControlTypeStandardResult.ok()) { + *isSpecialValue = true; + return isCruiseControlTypeStandardResult.error(); + } + if (isCruiseControlTypeStandardResult.value() && + (value.value.int32Values[0] == + toInt(CruiseControlCommand::INCREASE_TARGET_TIME_GAP) || + value.value.int32Values[0] == + toInt(CruiseControlCommand::DECREASE_TARGET_TIME_GAP))) { + *isSpecialValue = true; + return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) + << "tried to use a change target time gap command while on a standard CC " + << "setting"; + } + return {}; + case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP): { + isAdasPropertyAvailableResult = + isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE)); + if (!isAdasPropertyAvailableResult.ok()) { + *isSpecialValue = true; + return isAdasPropertyAvailableResult; + } + isCruiseControlTypeStandardResult = isCruiseControlTypeStandard(); + if (!isCruiseControlTypeStandardResult.ok()) { + *isSpecialValue = true; + return isCruiseControlTypeStandardResult.error(); + } + if (isCruiseControlTypeStandardResult.value()) { + *isSpecialValue = true; + return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) + << "tried to set target time gap or lead vehicle measured distance value " + << "while on a standard CC setting"; + } + return {}; } #ifdef ENABLE_VEHICLE_HAL_TEST_PROPERTIES diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp index ae1c0f681a..a77d565d6e 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp @@ -62,6 +62,8 @@ namespace vehicle { namespace fake { namespace { +using ::aidl::android::hardware::automotive::vehicle::CruiseControlCommand; +using ::aidl::android::hardware::automotive::vehicle::CruiseControlType; using ::aidl::android::hardware::automotive::vehicle::ErrorState; using ::aidl::android::hardware::automotive::vehicle::GetValueRequest; using ::aidl::android::hardware::automotive::vehicle::GetValueResult; @@ -1454,7 +1456,7 @@ std::vector setSpecialValueTestCases() { }, VehiclePropValue{ .prop = toInt(VehicleProperty::CRUISE_CONTROL_TYPE), - .value.int32Values = {1}, + .value.int32Values = {2}, }, VehiclePropValue{ .prop = toInt(VehicleProperty::CRUISE_CONTROL_STATE), @@ -1834,6 +1836,47 @@ TEST_F(FakeVehicleHardwareTest, testSetAdasPropNotAvailable) { } } +TEST_F(FakeVehicleHardwareTest, testGetAccPropertiesOnStandardCc) { + std::vector ccTypeDependentProperties = { + toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP), + toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE), + }; + + StatusCode status = + setValue(VehiclePropValue{.prop = toInt(VehicleProperty::CRUISE_CONTROL_TYPE), + .value.int32Values = {toInt(CruiseControlType::STANDARD)}}); + EXPECT_EQ(status, StatusCode::OK); + + for (int32_t dependentProp : ccTypeDependentProperties) { + auto getValueResult = getValue(VehiclePropValue{.prop = dependentProp}); + EXPECT_FALSE(getValueResult.ok()); + EXPECT_EQ(getValueResult.error(), StatusCode::NOT_AVAILABLE_DISABLED); + } +} + +TEST_F(FakeVehicleHardwareTest, testSetAccPropertiesOnStandardCc) { + std::vector testVehiclePropValues = { + VehiclePropValue{ + .prop = toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP), + .value.int32Values = {3}}, + VehiclePropValue{ + .prop = toInt(VehicleProperty::CRUISE_CONTROL_COMMAND), + .value.int32Values = {toInt(CruiseControlCommand::INCREASE_TARGET_TIME_GAP)}}, + VehiclePropValue{ + .prop = toInt(VehicleProperty::CRUISE_CONTROL_COMMAND), + .value.int32Values = {toInt(CruiseControlCommand::DECREASE_TARGET_TIME_GAP)}}}; + + StatusCode status = + setValue(VehiclePropValue{.prop = toInt(VehicleProperty::CRUISE_CONTROL_TYPE), + .value.int32Values = {toInt(CruiseControlType::STANDARD)}}); + EXPECT_EQ(status, StatusCode::OK); + + for (auto value : testVehiclePropValues) { + status = setValue(value); + EXPECT_EQ(status, StatusCode::NOT_AVAILABLE_DISABLED); + } +} + TEST_F(FakeVehicleHardwareTest, testSendAdasPropertiesState) { std::unordered_map> adasEnabledPropToAdasPropWithErrorState = { // AEB