MediaMetrics: Add Elem getter to Item

And minor edits.

Test: atest mediametrics_tests
Bug: 138583596
Change-Id: I9161f98f4c17516ea04fc143eb1ccbd656f17796
diff --git a/media/libmediametrics/include/MediaMetricsItem.h b/media/libmediametrics/include/MediaMetricsItem.h
index 001a8cf..5765dc5 100644
--- a/media/libmediametrics/include/MediaMetricsItem.h
+++ b/media/libmediametrics/include/MediaMetricsItem.h
@@ -128,7 +128,7 @@
 
 template<size_t N>
 static inline bool startsWith(const std::string &s, const char (&comp)[N]) {
-    return !strncmp(s.c_str(), comp, N-1);
+    return !strncmp(s.c_str(), comp, N - 1);
 }
 
 /**
@@ -798,14 +798,14 @@
     Item& operator=(Item&& other) = default;
 
     bool operator==(const Item& other) const {
-        if (mPid != other.mPid
-            || mUid != other.mUid
-            || mPkgName != other.mPkgName
-            || mPkgVersionCode != other.mPkgVersionCode
-            || mKey != other.mKey
-            || mTimestamp != other.mTimestamp
-            || mProps != other.mProps) return false;
-         return true;
+        return mPid == other.mPid
+            && mUid == other.mUid
+            && mPkgName == other.mPkgName
+            && mPkgVersionCode == other.mPkgVersionCode
+            && mKey == other.mKey
+            && mTimestamp == other.mTimestamp
+            && mProps == other.mProps
+            ;
     }
     bool operator!=(const Item& other) const {
         return !(*this == other);
@@ -935,6 +935,11 @@
         return get(key, value);
     }
 
+    const Prop::Elem* get(const char *key) const {
+        const Prop *prop = findProp(key);
+        return prop == nullptr ? nullptr : &prop->get();
+    }
+
         // Deliver the item to MediaMetrics
         bool selfrecord();
 
diff --git a/services/mediametrics/tests/mediametrics_tests.cpp b/services/mediametrics/tests/mediametrics_tests.cpp
index 55ce82b..79cb2af 100644
--- a/services/mediametrics/tests/mediametrics_tests.cpp
+++ b/services/mediametrics/tests/mediametrics_tests.cpp
@@ -262,27 +262,32 @@
           int32_t i32;
           ASSERT_TRUE(prop.get(&i32));
           ASSERT_EQ(1, i32);
+          ASSERT_EQ(1, std::get<int32_t>(prop.get()));
           mask |= 1;
       } else if (!strcmp(name, "i64")) {
           int64_t i64;
           ASSERT_TRUE(prop.get(&i64));
           ASSERT_EQ(2, i64);
+          ASSERT_EQ(2, std::get<int64_t>(prop.get()));
           mask |= 2;
       } else if (!strcmp(name, "double")) {
           double d;
           ASSERT_TRUE(prop.get(&d));
           ASSERT_EQ(3.125, d);
+          ASSERT_EQ(3.125, std::get<double>(prop.get()));
           mask |= 4;
       } else if (!strcmp(name, "string")) {
           std::string s;
           ASSERT_TRUE(prop.get(&s));
           ASSERT_EQ("abc", s);
+          ASSERT_EQ(s, std::get<std::string>(prop.get()));
           mask |= 8;
       } else if (!strcmp(name, "rate")) {
           std::pair<int64_t, int64_t> r;
           ASSERT_TRUE(prop.get(&r));
           ASSERT_EQ(11, r.first);
           ASSERT_EQ(12, r.second);
+          ASSERT_EQ(r, std::get<decltype(r)>(prop.get()));
           mask |= 16;
       } else {
           FAIL();