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

Commit f51e066c authored by Kai Wang's avatar Kai Wang Committed by Android (Google) Code Review
Browse files

Merge "Add three vendor properties for e2e test"

parents e5d0a429 14fe1d90
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -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},
                        },
        },

+41 −4
Original line number Diff line number Diff line
@@ -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;
}