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
This commit is contained in:
Kai
2019-07-31 16:12:35 -07:00
parent 25ac507bbc
commit 244e794ffe
2 changed files with 13 additions and 7 deletions

View File

@@ -50,12 +50,18 @@ bool VehiclePropertyStore::writeValue(const VehiclePropValue& propValue,
VehiclePropValue* valueToUpdate = const_cast<VehiclePropValue*>(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;
}

View File

@@ -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;