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

Commit 0885f9b1 authored by Hao Chen's avatar Hao Chen
Browse files

Set Timestamp By the Server when the client called 'set'

Test: Build; unit tests `atest packages/services/Car/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarPropertyTest.java`

Bug: b/141493212

Change-Id: I6686a15d6e9fa483d9b361acfe88001b7497b937
parent de6835be
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -201,6 +201,36 @@ StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value, b
    switch (value.prop) {
        case kGenerateFakeDataControllingProperty:
            return handleGenerateFakeDataRequest(value);

        // set the value from vehcile side, used in end to end test.
        case kSetIntPropertyFromVehcileForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::INT32, 1);
            updatedPropValue->prop = value.value.int32Values[0];
            updatedPropValue->value.int32Values[0] = value.value.int32Values[1];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }
        case kSetFloatPropertyFromVehcileForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::FLOAT, 1);
            updatedPropValue->prop = value.value.int32Values[0];
            updatedPropValue->value.floatValues[0] = value.value.floatValues[0];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }
        case kSetBooleanPropertyFromVehcileForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::BOOLEAN, 1);
            updatedPropValue->prop = value.value.int32Values[1];
            updatedPropValue->value.int32Values[0] = value.value.int32Values[0];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }

        case AP_POWER_STATE_REPORT:
            switch (value.value.int32Values[0]) {
                case toInt(VehicleApPowerStateReport::DEEP_SLEEP_EXIT):
@@ -237,7 +267,10 @@ StatusCode EmulatedVehicleServer::onSetProperty(const VehiclePropValue& value, b

    // In the real vhal, the value will be sent to Car ECU.
    // We just pretend it is done here and send back to HAL
    onPropertyValueFromCar(value, updateStatus);
    auto updatedPropValue = getValuePool()->obtain(value);
    updatedPropValue->timestamp = elapsedRealtimeNano();

    onPropertyValueFromCar(*updatedPropValue, updateStatus);
    return StatusCode::OK;
}

+1 −34
Original line number Diff line number Diff line
@@ -134,36 +134,6 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
    constexpr bool updateStatus = 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) {
        // Send the generator controlling request to the server.
        // 'updateStatus' flag is only for the value sent by setProperty (propValue in this case)
@@ -217,11 +187,9 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
     * After checking all conditions, such as the property is available, a real vhal will
     * sent the events to Car ECU to take actions.
     */
    VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(propValue);
    updatedPropValue->timestamp = elapsedRealtimeNano();

    // Send the value to the vehicle server, the server will talk to the (real or emulated) car
    auto setValueStatus = mVehicleClient->setProperty(*updatedPropValue, updateStatus);
    auto setValueStatus = mVehicleClient->setProperty(propValue, updateStatus);
    if (setValueStatus != StatusCode::OK) {
        return setValueStatus;
    }
@@ -312,7 +280,6 @@ void EmulatedVehicleHal::onContinuousPropertyTimer(const std::vector<int32_t>& p
        }

        if (v.get()) {
            v->timestamp = elapsedRealtimeNano();
            doHalEvent(std::move(v));
        }
    }