Use AAOS side timestamp for VehiclePropValue.
Update the timestamp set by the host-side VHAL proxy server with
the Android-side timestamp at AAOS VHAL side. This makes sure that
we always expose VehiclePropValue that is perfectly synced with
Android elapsedRealtimeNano. This CL also adds logic to deal with
cases when a property update event or a get value result is outdated.
This CL updates the unit test to cover more cases and remove the flaky
test case that requires starting a local GRPC server.
Flag: EXEMPT HAL change
Test: atest GRPCVehicleHardwareUnitTest
Bug: 349678711
Change-Id: I5e2c07e77869f7286a438cb2a04d1b6c130c3c36
diff --git a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h
index 9750f62..1edf658 100644
--- a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h
+++ b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h
@@ -20,6 +20,7 @@
#include <VehicleHalTypes.h>
#include <VehicleUtils.h>
#include <android-base/result.h>
+#include <android-base/thread_annotations.h>
#include "VehicleServer.grpc.pb.h"
#include "VehicleServer.pb.h"
@@ -33,6 +34,7 @@
#include <shared_mutex>
#include <string>
#include <thread>
+#include <unordered_map>
#include <vector>
namespace android::hardware::automotive::vehicle::virtualization {
@@ -43,9 +45,6 @@
public:
explicit GRPCVehicleHardware(std::string service_addr);
- // Only used for unit testing.
- explicit GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub);
-
~GRPCVehicleHardware();
// Get all the property configs.
@@ -94,7 +93,7 @@
std::unique_ptr<const PropertyChangeCallback> mOnPropChange;
private:
- void ValuePollingLoop();
+ friend class GRPCVehicleHardwareUnitTest;
std::string mServiceAddr;
std::shared_ptr<::grpc::Channel> mGrpcChannel;
@@ -106,6 +105,31 @@
std::mutex mShutdownMutex;
std::condition_variable mShutdownCV;
std::atomic<bool> mShuttingDownFlag{false};
+
+ mutable std::mutex mLatestUpdateTimestampsMutex;
+
+ // A map from [propId, areaId] to the latest timestamp this property is updated.
+ // The key is a tuple, the first element is the external timestamp (timestamp set by VHAL
+ // server), the second element is the Android timestamp (elapsedRealtimeNano).
+ mutable std::unordered_map<PropIdAreaId, std::pair<int64_t, int64_t>,
+ PropIdAreaIdHash> mLatestUpdateTimestamps
+ GUARDED_BY(mLatestUpdateTimestampsMutex);
+
+ // Only used for unit testing.
+ GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub,
+ bool startValuePollingLoop);
+
+ void ValuePollingLoop();
+ void pollValue();
+
+ aidlvhal::StatusCode getValuesWithRetry(const std::vector<aidlvhal::GetValueRequest>& requests,
+ std::vector<aidlvhal::GetValueResult>* results,
+ size_t retryCount) const;
+
+ // Check the external timestamp of propValue against the latest updated external timestamp, if
+ // this is an outdated value, return false. Otherwise, update the external timestamp to the
+ // Android timestamp and return true.
+ bool setAndroidTimestamp(aidlvhal::VehiclePropValue* propValue) const;
};
} // namespace android::hardware::automotive::vehicle::virtualization