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

Commit 8acfc224 authored by Enrico Granata's avatar Enrico Granata
Browse files

Teach VehiclePropertyStore to not propagate the status value when a set()...

Teach VehiclePropertyStore to not propagate the status value when a set() operation comes from Android

The status field of a property represents properties of the underlying implementation and it should thus
be read-only to Android. Add a way for VehiclePropertyStore to be told whether it does (or does not) need to
propagate the field to the stored property value.

Test: build
Bug: 76034442
Change-Id: I333fab7e296f425cf5c4a35ae136ccfbaa542379
parent c7d15e9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public:

    /* Stores provided value. Returns true if value was written returns false if config for
     * example wasn't registered. */
    bool writeValue(const VehiclePropValue& propValue);
    bool writeValue(const VehiclePropValue& propValue, bool updateStatus);

    void removeValue(const VehiclePropValue& propValue);
    void removeValuesForProperty(int32_t propId);
+5 −2
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ void VehiclePropertyStore::registerProperty(const VehiclePropConfig& config,
    mConfigs.insert({ config.prop, RecordConfig { config, tokenFunc } });
}

bool VehiclePropertyStore::writeValue(const VehiclePropValue& propValue) {
bool VehiclePropertyStore::writeValue(const VehiclePropValue& propValue,
                                        bool updateStatus) {
    MuxGuard g(mLock);
    if (!mConfigs.count(propValue.prop)) return false;

@@ -52,8 +53,10 @@ bool VehiclePropertyStore::writeValue(const VehiclePropValue& propValue) {
    } else {
        valueToUpdate->timestamp = propValue.timestamp;
        valueToUpdate->value = propValue.value;
        if (updateStatus) {
            valueToUpdate->status = propValue.status;
        }
    }
    return true;
}

+18 −6
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
}

StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
    static constexpr bool shouldUpdateStatus = false;

    if (propValue.prop == kGenerateFakeDataControllingProperty) {
        StatusCode status = handleGenerateFakeDataRequest(propValue);
        if (status != StatusCode::OK) {
@@ -182,7 +184,7 @@ StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
        return StatusCode::NOT_AVAILABLE;
    }

    if (!mPropStore->writeValue(propValue)) {
    if (!mPropStore->writeValue(propValue, shouldUpdateStatus)) {
        return StatusCode::INVALID_ARG;
    }

@@ -204,6 +206,8 @@ static bool isDiagnosticProperty(VehiclePropConfig propConfig) {

// Parse supported properties list and generate vector of property values to hold current values.
void EmulatedVehicleHal::onCreate() {
    static constexpr bool shouldUpdateStatus = true;

    for (auto& it : kVehicleProperties) {
        VehiclePropConfig cfg = it.config;
        int32_t numAreas = cfg.areaConfigs.size();
@@ -245,7 +249,7 @@ void EmulatedVehicleHal::onCreate() {
            } else {
                prop.value = it.initialValue;
            }
            mPropStore->writeValue(prop);
            mPropStore->writeValue(prop, shouldUpdateStatus);
        }
    }
    initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME));
@@ -305,6 +309,8 @@ bool EmulatedVehicleHal::isContinuousProperty(int32_t propId) const {
}

bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValue) {
    static constexpr bool shouldUpdateStatus = true;

    if (propValue.prop == kGenerateFakeDataControllingProperty) {
        StatusCode status = handleGenerateFakeDataRequest(propValue);
        if (status != StatusCode::OK) {
@@ -312,7 +318,7 @@ bool EmulatedVehicleHal::setPropertyFromVehicle(const VehiclePropValue& propValu
        }
    }

    if (mPropStore->writeValue(propValue)) {
    if (mPropStore->writeValue(propValue, shouldUpdateStatus)) {
        doHalEvent(getValuePool()->obtain(propValue));
        return true;
    } else {
@@ -373,6 +379,8 @@ StatusCode EmulatedVehicleHal::handleGenerateFakeDataRequest(const VehiclePropVa
}

void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) {
    static constexpr bool shouldUpdateStatus = false;

    VehiclePropValuePtr updatedPropValue {};
    switch (getPropType(propId)) {
        case VehiclePropertyType::FLOAT:
@@ -392,7 +400,7 @@ void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) {
        updatedPropValue->areaId = 0;  // Add area support if necessary.
        updatedPropValue->timestamp = elapsedRealtimeNano();
        updatedPropValue->status = VehiclePropertyStatus::AVAILABLE;
        mPropStore->writeValue(*updatedPropValue);
        mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus);
        auto changeMode = mPropStore->getConfigOrDie(propId)->changeMode;
        if (VehiclePropertyChangeMode::ON_CHANGE == changeMode) {
            doHalEvent(move(updatedPropValue));
@@ -421,16 +429,20 @@ void EmulatedVehicleHal::initStaticConfig() {
}

void EmulatedVehicleHal::initObd2LiveFrame(const VehiclePropConfig& propConfig) {
    static constexpr bool shouldUpdateStatus = true;

    auto liveObd2Frame = createVehiclePropValue(VehiclePropertyType::MIXED, 0);
    auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]),
                                            static_cast<size_t>(propConfig.configArray[1]));
    sensorStore->fillPropValue("", liveObd2Frame.get());
    liveObd2Frame->prop = OBD2_LIVE_FRAME;

    mPropStore->writeValue(*liveObd2Frame);
    mPropStore->writeValue(*liveObd2Frame, shouldUpdateStatus);
}

void EmulatedVehicleHal::initObd2FreezeFrame(const VehiclePropConfig& propConfig) {
    static constexpr bool shouldUpdateStatus = true;

    auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]),
                                            static_cast<size_t>(propConfig.configArray[1]));

@@ -442,7 +454,7 @@ void EmulatedVehicleHal::initObd2FreezeFrame(const VehiclePropConfig& propConfig
        sensorStore->fillPropValue(dtc, freezeFrame.get());
        freezeFrame->prop = OBD2_FREEZE_FRAME;

        mPropStore->writeValue(*freezeFrame);
        mPropStore->writeValue(*freezeFrame, shouldUpdateStatus);
    }
}