MediaMetrics: Add copy constructor to TransactionLog

Test: atest mediametrics_tests
Bug: 138583596
Change-Id: If2510ab39e89ce09b22ae4cfaebb40554fffbb2b
diff --git a/services/mediametrics/TransactionLog.h b/services/mediametrics/TransactionLog.h
index 7a520d9..0c5d12b 100644
--- a/services/mediametrics/TransactionLog.h
+++ b/services/mediametrics/TransactionLog.h
@@ -36,7 +36,7 @@
  *
  * The TransactionLog is NOT thread safe.
  */
-class TransactionLog {
+class TransactionLog final { // made final as we have copy constructor instead of dup() override.
 public:
     // In long term run, the garbage collector aims to keep the
     // Transaction Log between the Low Water Mark and the High Water Mark.
@@ -58,6 +58,30 @@
                   __func__, highWaterMark, lowWaterMark);
     }
 
+    // The TransactionLog copy constructor/assignment is effectively an
+    // instantaneous, isochronous snapshot of the other TransactionLog.
+    //
+    // The contents of the Transaction Log are shared pointers to immutable instances -
+    // std::shared_ptr<const mediametrics::Item>, so we use a shallow copy,
+    // which is more efficient in space and execution time than a deep copy,
+    // and gives the same results.
+
+    TransactionLog(const TransactionLog &other) {
+        *this = other;
+    }
+
+    TransactionLog& operator=(const TransactionLog &other) {
+        std::lock_guard lock(mLock);
+        mLog.clear();
+        mItemMap.clear();
+
+        std::lock_guard lock2(other.mLock);
+        mLog = other.mLog;
+        mItemMap = other.mItemMap;
+
+        return *this;
+    }
+
     /**
      * Put an item in the TransactionLog.
      */