Fix JSON result reporter to skip duplicates

The JSON Result Reporter was reporting duplicate metric values when
multiple performance tests were being executed in the same test plan.
For example, if cold and hot app start up tests were being run for
dialer and settings in a single test plan, the metrics for dialer were
being reported twice. This was because the test metrics utility object
was holding on to the metrics after writing them to the file. Erasing
the already reported metrics from the object solved the problem

Test: make catbox
This change has been tested manually by executing the test on a locally
connected reference device.

Bug: 278581155
Change-Id: I149dbdc8b3b609041d64f7865ed554bdf8ad8074
diff --git a/report/src/com/android/catbox/result/JsonResultReporter.java b/report/src/com/android/catbox/result/JsonResultReporter.java
index 6e9b9c3..05ef83a 100644
--- a/report/src/com/android/catbox/result/JsonResultReporter.java
+++ b/report/src/com/android/catbox/result/JsonResultReporter.java
@@ -178,6 +178,12 @@
         mTestMetricsUtil.setIterationSeparator(mTestIterationSeparator);
     }
 
+    /** Re-initialize object to erase all existing test metrics */
+    private void reInitializeTestMetricsUtil() {
+        mTestMetricsUtil = initializeTestMetricsUtil();
+        mTestMetricsUtil.setIterationSeparator(mTestIterationSeparator);
+    }
+
     /** Write Test Metrics to JSON */
     private void writeTestMetrics(
             String classMethodName, Map<String, String> metrics) {
@@ -332,6 +338,9 @@
                 writeTestMetrics(testName, aggregatedMetrics.get(testName));
             }
         }
+
+        // Avoid reporting duplicate metrics by erasing metrics from previous runs
+        reInitializeTestMetricsUtil();
     }
 
     /** {@inheritDoc} */