Fix ValueMetric should only pull on real state changes

In ValueMetricProducer, we now map the new and old state values from
onStateChanged to their correct group ids (no mapping happens if the
metric has no state map). We then check if the group ids are the same
and return if they are. Having the same group id means that the state
values are in the same group and no pull is needed.

onStateChanged was updated to take state values stored in FieldValue
objects instead of as ints. This makes it easier to utilize the
mapStateValue function in MetricProducer.

Bug: b/156428844
Test: m statsd_test && adb sync data && adb shell
data/nativetest/statsd_test/statsd_test

Change-Id: Id8f110db593470b8923e7c4259d70cc5f5bc9147
diff --git a/cmds/statsd/src/metrics/DurationMetricProducer.cpp b/cmds/statsd/src/metrics/DurationMetricProducer.cpp
index 0de92f3..6633659 100644
--- a/cmds/statsd/src/metrics/DurationMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/DurationMetricProducer.cpp
@@ -161,13 +161,12 @@
 
 void DurationMetricProducer::onStateChanged(const int64_t eventTimeNs, const int32_t atomId,
                                             const HashableDimensionKey& primaryKey,
-                                            const int32_t oldState, const int32_t newState) {
-    // Create a FieldValue object to hold the new state.
-    FieldValue value;
-    value.mValue.setInt(newState);
+                                            const FieldValue& oldState,
+                                            const FieldValue& newState) {
     // Check if this metric has a StateMap. If so, map the new state value to
     // the correct state group id.
-    mapStateValue(atomId, &value);
+    FieldValue newStateCopy = newState;
+    mapStateValue(atomId, &newStateCopy);
 
     flushIfNeededLocked(eventTimeNs);
 
@@ -185,7 +184,7 @@
         if (!containsLinkedStateValues(whatIt.first, primaryKey, mMetric2StateLinks, atomId)) {
             continue;
         }
-        whatIt.second->onStateChanged(eventTimeNs, atomId, value);
+        whatIt.second->onStateChanged(eventTimeNs, atomId, newStateCopy);
     }
 }