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 Original line Diff line number Diff line
@@ -3387,7 +3387,7 @@
            "property": "VehicleProperty::CRUISE_CONTROL_TYPE",
            "property": "VehicleProperty::CRUISE_CONTROL_TYPE",
            "defaultValue": {
            "defaultValue": {
                "int32Values": [
                "int32Values": [
                    "CruiseControlType::STANDARD"
                    "CruiseControlType::ADAPTIVE"
                ]
                ]
            },
            },
            "areas": [
            "areas": [
+1 −0
Original line number Original line Diff line number Diff line
@@ -189,6 +189,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    VhalResult<void> maybeSetSpecialValue(
    VhalResult<void> maybeSetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue);
            bool* isSpecialValue);
    VhalResult<bool> isCruiseControlTypeStandard() const;
    ValueResultType maybeGetSpecialValue(
    ValueResultType maybeGetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue) const;
            bool* isSpecialValue) const;
+80 −7
Original line number Original line Diff line number Diff line
@@ -52,6 +52,8 @@ namespace fake {


namespace {
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::ErrorState;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueResult;
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(
FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
        const VehiclePropValue& value, bool* isSpecialValue) const {
        const VehiclePropValue& value, bool* isSpecialValue) const {
    *isSpecialValue = false;
    *isSpecialValue = false;
@@ -638,6 +652,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
        return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) << "hvac not available";
        return StatusError(StatusCode::NOT_AVAILABLE_DISABLED) << "hvac not available";
    }
    }


    VhalResult<void> isAdasPropertyAvailableResult;
    switch (propId) {
    switch (propId) {
        case OBD2_FREEZE_FRAME:
        case OBD2_FREEZE_FRAME:
            *isSpecialValue = true;
            *isSpecialValue = true;
@@ -660,16 +675,33 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
            *isSpecialValue = true;
            *isSpecialValue = true;
            return StatusError((StatusCode)VENDOR_ERROR_CODE);
            return StatusError((StatusCode)VENDOR_ERROR_CODE);
        case toInt(VehicleProperty::CRUISE_CONTROL_TARGET_SPEED):
        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):
        case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP):
            [[fallthrough]];
            [[fallthrough]];
        case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE): {
        case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_LEAD_VEHICLE_MEASURED_DISTANCE): {
            auto isAdasPropertyAvailableResult =
            isAdasPropertyAvailableResult =
                    isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE));
                    isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE));
            if (!isAdasPropertyAvailableResult.ok()) {
            if (!isAdasPropertyAvailableResult.ok()) {
                *isSpecialValue = true;
                *isSpecialValue = true;
                return isAdasPropertyAvailableResult.error();
                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;
            return nullptr;
        }
        }
        default:
        default:
@@ -730,7 +762,13 @@ void FakeVehicleHardware::sendAdasPropertiesState(int32_t propertyId, int32_t st
        }
        }
        auto& dependentPropConfig = dependentPropConfigResult.value();
        auto& dependentPropConfig = dependentPropConfigResult.value();
        for (auto& areaConfig : dependentPropConfig->areaConfigs) {
        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.
            // This will trigger a property change event for the current ADAS property value.
            mServerSidePropStore->writeValue(std::move(propValue), /*updateStatus=*/true,
            mServerSidePropStore->writeValue(std::move(propValue), /*updateStatus=*/true,
                                             VehiclePropertyStore::EventMode::ALWAYS);
                                             VehiclePropertyStore::EventMode::ALWAYS);
@@ -777,6 +815,8 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
        }
        }
    }
    }


    VhalResult<void> isAdasPropertyAvailableResult;
    VhalResult<bool> isCruiseControlTypeStandardResult;
    switch (propId) {
    switch (propId) {
        case toInt(VehicleProperty::AP_POWER_STATE_REPORT):
        case toInt(VehicleProperty::AP_POWER_STATE_REPORT):
            *isSpecialValue = true;
            *isSpecialValue = true;
@@ -802,7 +842,7 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
            *isSpecialValue = true;
            *isSpecialValue = true;
            return setHvacTemperatureValueSuggestion(value);
            return setHvacTemperatureValueSuggestion(value);
        case toInt(VehicleProperty::LANE_CENTERING_ASSIST_COMMAND): {
        case toInt(VehicleProperty::LANE_CENTERING_ASSIST_COMMAND): {
            auto isAdasPropertyAvailableResult =
            isAdasPropertyAvailableResult =
                    isAdasPropertyAvailable(toInt(VehicleProperty::LANE_CENTERING_ASSIST_STATE));
                    isAdasPropertyAvailable(toInt(VehicleProperty::LANE_CENTERING_ASSIST_STATE));
            if (!isAdasPropertyAvailableResult.ok()) {
            if (!isAdasPropertyAvailableResult.ok()) {
                *isSpecialValue = true;
                *isSpecialValue = true;
@@ -810,15 +850,48 @@ VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValu
            return isAdasPropertyAvailableResult;
            return isAdasPropertyAvailableResult;
        }
        }
        case toInt(VehicleProperty::CRUISE_CONTROL_COMMAND):
        case toInt(VehicleProperty::CRUISE_CONTROL_COMMAND):
            [[fallthrough]];
            isAdasPropertyAvailableResult =
        case toInt(VehicleProperty::ADAPTIVE_CRUISE_CONTROL_TARGET_TIME_GAP): {
            auto isAdasPropertyAvailableResult =
                    isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE));
                    isAdasPropertyAvailable(toInt(VehicleProperty::CRUISE_CONTROL_STATE));
            if (!isAdasPropertyAvailableResult.ok()) {
            if (!isAdasPropertyAvailableResult.ok()) {
                *isSpecialValue = true;
                *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;
                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
#ifdef ENABLE_VEHICLE_HAL_TEST_PROPERTIES
        case toInt(VehicleProperty::CLUSTER_REPORT_STATE):
        case toInt(VehicleProperty::CLUSTER_REPORT_STATE):
+44 −1
Original line number Original line Diff line number Diff line
@@ -62,6 +62,8 @@ namespace vehicle {
namespace fake {
namespace fake {
namespace {
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::ErrorState;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::GetValueResult;
using ::aidl::android::hardware::automotive::vehicle::GetValueResult;
@@ -1454,7 +1456,7 @@ std::vector<SetSpecialValueTestCase> setSpecialValueTestCases() {
                                    },
                                    },
                                    VehiclePropValue{
                                    VehiclePropValue{
                                            .prop = toInt(VehicleProperty::CRUISE_CONTROL_TYPE),
                                            .prop = toInt(VehicleProperty::CRUISE_CONTROL_TYPE),
                                            .value.int32Values = {1},
                                            .value.int32Values = {2},
                                    },
                                    },
                                    VehiclePropValue{
                                    VehiclePropValue{
                                            .prop = toInt(VehicleProperty::CRUISE_CONTROL_STATE),
                                            .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) {
TEST_F(FakeVehicleHardwareTest, testSendAdasPropertiesState) {
    std::unordered_map<int32_t, std::vector<int32_t>> adasEnabledPropToAdasPropWithErrorState = {
    std::unordered_map<int32_t, std::vector<int32_t>> adasEnabledPropToAdasPropWithErrorState = {
            // AEB
            // AEB