From 244e794ffe68ed2b22ccdb92f45e56eb6e6c535c Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 31 Jul 2019 16:12:35 -0700 Subject: [PATCH] Check timestamp before updating the value Check timestamp before updating property value. Use timestamp in generating fake property event. Bug: 134963097 Test: end to end test in VehcileHal_test Change-Id: I60f8c0eb3a19db2c165469bb45b3b80b39388b37 --- .../common/src/VehiclePropertyStore.cpp | 18 ++++++++++++------ .../impl/vhal_v2_0/EmulatedVehicleHal.cpp | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/automotive/vehicle/2.0/default/common/src/VehiclePropertyStore.cpp b/automotive/vehicle/2.0/default/common/src/VehiclePropertyStore.cpp index 94ace455cc..24b777c75f 100644 --- a/automotive/vehicle/2.0/default/common/src/VehiclePropertyStore.cpp +++ b/automotive/vehicle/2.0/default/common/src/VehiclePropertyStore.cpp @@ -50,12 +50,18 @@ bool VehiclePropertyStore::writeValue(const VehiclePropValue& propValue, VehiclePropValue* valueToUpdate = const_cast(getValueOrNullLocked(recId)); if (valueToUpdate == nullptr) { mPropertyValues.insert({ recId, propValue }); - } else { - valueToUpdate->timestamp = propValue.timestamp; - valueToUpdate->value = propValue.value; - if (updateStatus) { - valueToUpdate->status = propValue.status; - } + return true; + } + + // propValue is outdated and drops it. + if (valueToUpdate->timestamp > propValue.timestamp) { + return false; + } + // update the propertyValue. + valueToUpdate->timestamp = propValue.timestamp; + valueToUpdate->value = propValue.value; + if (updateStatus) { + valueToUpdate->status = propValue.status; } return true; } diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp index ba81a521a0..b4f1f07323 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp @@ -455,7 +455,7 @@ void EmulatedVehicleHal::onFakeValueGenerated(const VehiclePropValue& value) { VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(value); if (updatedPropValue) { - updatedPropValue->timestamp = elapsedRealtimeNano(); + updatedPropValue->timestamp = value.timestamp; updatedPropValue->status = VehiclePropertyStatus::AVAILABLE; mPropStore->writeValue(*updatedPropValue, shouldUpdateStatus); auto changeMode = mPropStore->getConfigOrDie(value.prop)->changeMode;