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

Commit 892e1fea authored by Shrikar Amirisetty's avatar Shrikar Amirisetty Committed by Android (Google) Code Review
Browse files

Merge "Added logic for ACC properties to return NOT_AVAILABLE in standard CC." into main

parents 83bee8b1 cc3f5884
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3387,7 +3387,7 @@
            "property": "VehicleProperty::CRUISE_CONTROL_TYPE",
            "defaultValue": {
                "int32Values": [
                    "CruiseControlType::STANDARD"
                    "CruiseControlType::ADAPTIVE"
                ]
            },
            "areas": [
+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    VhalResult<void> maybeSetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue);
    VhalResult<bool> isCruiseControlTypeStandard() const;
    ValueResultType maybeGetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue) const;
+80 −7
Original line number Diff line number Diff line
@@ -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<bool> 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<void> isAdasPropertyAvailableResult;
    switch (propId) {
        case OBD2_FREEZE_FRAME:
            *isSpecialValue = true;
@@ -660,16 +675,33 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
            *isSpecialValue = true;
            return StatusError((StatusCode)VENDOR_ERROR_CODE);
        case toInt(VehicleProperty::CRUISE_CONTROL_TARGET_SPEED):
            [[fallthrough]];
            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): {
            auto isAdasPropertyAvailableResult =
            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:
@@ -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<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        }
    }

    VhalResult<void> isAdasPropertyAvailableResult;
    VhalResult<bool> isCruiseControlTypeStandardResult;
    switch (propId) {
        case toInt(VehicleProperty::AP_POWER_STATE_REPORT):
            *isSpecialValue = true;
@@ -802,7 +842,7 @@ VhalResult<void> 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,15 +850,48 @@ VhalResult<void> 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;
            }
            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
        case toInt(VehicleProperty::CLUSTER_REPORT_STATE):
+44 −1
Original line number Diff line number Diff line
@@ -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<SetSpecialValueTestCase> 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<int32_t> 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<VehiclePropValue> 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<int32_t, std::vector<int32_t>> adasEnabledPropToAdasPropWithErrorState = {
            // AEB