Merge "Fix a destruction of Enumerator objects" into rvc-qpr-dev
diff --git a/evs/manager/1.1/Enumerator.cpp b/evs/manager/1.1/Enumerator.cpp
index fdf3500..61cfec9 100644
--- a/evs/manager/1.1/Enumerator.cpp
+++ b/evs/manager/1.1/Enumerator.cpp
@@ -61,6 +61,12 @@
 using CameraDesc_1_0 = ::android::hardware::automotive::evs::V1_0::CameraDesc;
 using CameraDesc_1_1 = ::android::hardware::automotive::evs::V1_1::CameraDesc;
 
+Enumerator::~Enumerator() {
+    if (mClientsMonitor != nullptr) {
+        mClientsMonitor->stopCollection();
+    }
+}
+
 bool Enumerator::init(const char* hardwareServiceName) {
     LOG(DEBUG) << "init";
 
diff --git a/evs/manager/1.1/Enumerator.h b/evs/manager/1.1/Enumerator.h
index 7708295..3d3a253 100644
--- a/evs/manager/1.1/Enumerator.h
+++ b/evs/manager/1.1/Enumerator.h
@@ -78,6 +78,9 @@
     // Implementation details
     bool init(const char* hardwareServiceName);
 
+    // Destructor
+    virtual ~Enumerator();
+
 private:
     bool inline                     checkPermission();
     bool                            isLogicalCamera(const camera_metadata_t *metadata);
diff --git a/evs/manager/1.1/stats/StatsCollector.cpp b/evs/manager/1.1/stats/StatsCollector.cpp
index b57f928..4733871 100644
--- a/evs/manager/1.1/stats/StatsCollector.cpp
+++ b/evs/manager/1.1/stats/StatsCollector.cpp
@@ -107,9 +107,15 @@
                                                    CollectionInfo* info) {
     AutoMutex lock(mMutex);
     if (mCurrentCollectionEvent != event) {
-        LOG(WARNING) << "Skipping " << toString(event) << " collection event "
-                     << "on collection event " << toString(mCurrentCollectionEvent);
-        return {};
+        if (mCurrentCollectionEvent != CollectionEvent::TERMINATED) {
+            LOG(WARNING) << "Skipping " << toString(event) << " collection event "
+                         << "on collection event " << toString(mCurrentCollectionEvent);
+
+            return {};
+        } else {
+            return Error() << "A collection has been terminated "
+                           << "while a current event was pending in the message queue.";
+        }
     }
 
     if (info->maxCacheSize < 1) {