Add on-property-set listener to VNS

Change-Id: Id0b0fb15f42e1af0ca4899ea625bcc77f1320db7
Fix: b/31656523
diff --git a/tests/libvehiclenetwork-native-test/IVehicleNetworkTestListener.h b/tests/libvehiclenetwork-native-test/IVehicleNetworkTestListener.h
index 47a3a28..a25b9da 100644
--- a/tests/libvehiclenetwork-native-test/IVehicleNetworkTestListener.h
+++ b/tests/libvehiclenetwork-native-test/IVehicleNetworkTestListener.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_IVEHICLENETWORK_TEST_LISTER_H
 #define ANDROID_IVEHICLENETWORK_TEST_LISTER_H
 
+#include <queue>
+
 #include <IVehicleNetworkListener.h>
 
 namespace android {
@@ -24,7 +26,9 @@
 class IVehicleNetworkTestListener : public BnVehicleNetworkListener {
 public:
     IVehicleNetworkTestListener() :
-        mHalRestartCount(0) {};
+        mHalRestartCount(0),
+        mOnPropertySetValues()
+    {};
 
     virtual void onEvents(sp<VehiclePropValueListHolder>& events) {
         String8 msg("events ");
@@ -60,6 +64,16 @@
         mHalRestartCondition.signal();
     }
 
+    virtual void onPropertySet(const vehicle_prop_value_t& value) {
+        Mutex::Autolock autolock(mOnPropertySetLock);
+
+        std::unique_ptr<ScopedVehiclePropValue> scopedValue(new ScopedVehiclePropValue);
+        VehiclePropValueUtil::copyVehicleProp(&scopedValue->value,
+                                              value);
+        mOnPropertySetValues.push(std::move(scopedValue));
+        mOnPropertySetCondition.signal();
+    }
+
     void waitForEvents(nsecs_t reltime) {
         Mutex::Autolock autolock(mLock);
         mCondition.waitRelative(mLock, reltime);
@@ -99,6 +113,21 @@
         mHalErrorCondition.waitRelative(mHalErrorLock, reltime);
     }
 
+    status_t waitForOnPropertySet(nsecs_t reltime, std::unique_ptr<ScopedVehiclePropValue>* out) {
+        Mutex::Autolock autolock(mOnPropertySetLock);
+
+        status_t r = mOnPropertySetValues.empty()
+                     ? mOnPropertySetCondition.waitRelative(mOnPropertySetLock, reltime)
+                     : NO_ERROR;
+
+        if (r == NO_ERROR) {
+            VehiclePropValueUtil::copyVehicleProp(&(*out)->value,  /* dest */
+                                                  mOnPropertySetValues.back()->value /* src */);
+            mOnPropertySetValues.pop();
+        }
+        return r;
+    }
+
     bool isErrorMatching(int32_t errorCode, int32_t property, int32_t operation) {
         Mutex::Autolock autolock(mHalErrorLock);
         return mErrorCode == errorCode && mProperty == property && mOperation == operation;
@@ -129,6 +158,10 @@
     int32_t mErrorCode;
     int32_t mProperty;
     int32_t mOperation;
+
+    Mutex mOnPropertySetLock;
+    Condition mOnPropertySetCondition;
+    std::queue<std::unique_ptr<ScopedVehiclePropValue>> mOnPropertySetValues;
 };
 
 }; // namespace android