mediametrics: locally aggregate legacy drm metrics

Bug: 134789967
Test: statsd_testdrive
Change-Id: I053e58d2bccc1a14fafcb2fcb0bd40ec7d1fad17
diff --git a/services/mediametrics/statsd_drm.cpp b/services/mediametrics/statsd_drm.cpp
index b12f4f3..4f2e861 100644
--- a/services/mediametrics/statsd_drm.cpp
+++ b/services/mediametrics/statsd_drm.cpp
@@ -35,6 +35,9 @@
 
 #include <statslog.h>
 
+#include <array>
+#include <string>
+
 namespace android {
 
 // mediadrm
@@ -107,8 +110,14 @@
 // drmmanager
 bool statsd_drmmanager(const mediametrics::Item *item)
 {
+    using namespace std::string_literals;
     if (item == NULL) return false;
 
+    if (!enabled_statsd) {
+        ALOGV("NOT sending: drmmanager data");
+        return true;
+    }
+
     const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
@@ -123,16 +132,22 @@
     char *mime_types = NULL;
     (void) item->getCString("mime_types", &mime_types);
 
-    if (enabled_statsd) {
-        android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
-                                   timestamp, pkgName.c_str(), pkgVersionCode,
-                                   mediaApexVersion,
-                                   plugin_id, description,
-                                   method_id, mime_types);
-    } else {
-        ALOGV("NOT sending: drmmanager data");
+    // Corresponds to the 13 APIs tracked in the MediametricsDrmManagerReported statsd proto
+    // Please see also DrmManager::kMethodIdMap
+    std::array<int64_t, 13> methodCounts{};
+    for (size_t i = 0; i < methodCounts.size() ; i++) {
+        item->getInt64(("method"s + std::to_string(i)).c_str(), &methodCounts[i]);
     }
 
+    android::util::stats_write(android::util::MEDIAMETRICS_DRMMANAGER_REPORTED,
+                               timestamp, pkgName.c_str(), pkgVersionCode, mediaApexVersion,
+                               plugin_id, description, method_id, mime_types,
+                               methodCounts[0], methodCounts[1], methodCounts[2],
+                               methodCounts[3], methodCounts[4], methodCounts[5],
+                               methodCounts[6], methodCounts[7], methodCounts[8],
+                               methodCounts[9], methodCounts[10], methodCounts[11],
+                               methodCounts[12]);
+
     free(plugin_id);
     free(description);
     free(mime_types);