Merge "[libstatshidl] Removed dependency on libstatslog" into main
diff --git a/services/stats/Android.bp b/services/stats/Android.bp
index f698515..d588017 100644
--- a/services/stats/Android.bp
+++ b/services/stats/Android.bp
@@ -29,10 +29,15 @@
         "libexpresslog",
         "libhidlbase",
         "liblog",
-        "libstatslog",
         "libstatssocket",
         "libutils",
     ],
+    generated_sources: [
+        "statslog_hidl.cpp",
+    ],
+    generated_headers: [
+        "statslog_hidl.h",
+    ],
     export_include_dirs: [
         "include/",
     ],
@@ -47,3 +52,28 @@
         "android.frameworks.stats-service.xml",
     ],
 }
+
+genrule {
+    name: "statslog_hidl.h",
+    tools: ["stats-log-api-gen"],
+    cmd: "$(location stats-log-api-gen)" +
+        " --header $(genDir)/statslog_hidl.h" +
+        " --module statshidl" +
+        " --namespace android,util,statshidl",
+    out: [
+        "statslog_hidl.h",
+    ],
+}
+
+genrule {
+    name: "statslog_hidl.cpp",
+    tools: ["stats-log-api-gen"],
+    cmd: "$(location stats-log-api-gen)" +
+        " --cpp $(genDir)/statslog_hidl.cpp" +
+        " --module statshidl" +
+        " --namespace android,util,statshidl" +
+        " --importHeader statslog_hidl.h",
+    out: [
+        "statslog_hidl.cpp",
+    ],
+}
diff --git a/services/stats/StatsAidl.cpp b/services/stats/StatsAidl.cpp
index b22f903..66f7682 100644
--- a/services/stats/StatsAidl.cpp
+++ b/services/stats/StatsAidl.cpp
@@ -26,9 +26,8 @@
 #include <log/log.h>
 #include <stats_annotations.h>
 #include <stats_event.h>
-#include <statslog.h>
 
-#include <unordered_map>
+#include <map>
 
 namespace {
     static const char* g_AtomErrorMetricName =
@@ -118,8 +117,8 @@
         }
     }
 
-    // populate map for quickier access for VendorAtomValue associated annotations by value index
-    std::unordered_map<int, int> fieldIndexToAnnotationSetMap;
+    // populate map for quicker access for VendorAtomValue associated annotations by value index
+    std::map<int, int> fieldIndexToAnnotationSetMap;
     if (vendorAtom.valuesAnnotations) {
         const std::vector<std::optional<AnnotationSet>>& valuesAnnotations =
                 *vendorAtom.valuesAnnotations;
diff --git a/services/stats/StatsHal.cpp b/services/stats/StatsHal.cpp
index 19176d9..0ffa4c3 100644
--- a/services/stats/StatsHal.cpp
+++ b/services/stats/StatsHal.cpp
@@ -20,7 +20,7 @@
 #include "StatsHal.h"
 
 #include <log/log.h>
-#include <statslog.h>
+#include <statslog_hidl.h>
 
 namespace android {
 namespace frameworks {
@@ -32,24 +32,27 @@
 }
 
 hardware::Return<void> StatsHal::reportSpeakerImpedance(const SpeakerImpedance& speakerImpedance) {
-    android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED,
-                               speakerImpedance.speakerLocation, speakerImpedance.milliOhms);
+    android::util::statshidl::stats_write(android::util::statshidl::SPEAKER_IMPEDANCE_REPORTED,
+                                          speakerImpedance.speakerLocation,
+                                          speakerImpedance.milliOhms);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsHal::reportHardwareFailed(const HardwareFailed& hardwareFailed) {
-    android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
-                               hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
+    android::util::statshidl::stats_write(
+            android::util::statshidl::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
+            hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsHal::reportPhysicalDropDetected(
         const PhysicalDropDetected& physicalDropDetected) {
-    android::util::stats_write(
-            android::util::PHYSICAL_DROP_DETECTED, int32_t(physicalDropDetected.confidencePctg),
-            physicalDropDetected.accelPeak, physicalDropDetected.freefallDuration);
+    android::util::statshidl::stats_write(android::util::statshidl::PHYSICAL_DROP_DETECTED,
+                                          int32_t(physicalDropDetected.confidencePctg),
+                                          physicalDropDetected.accelPeak,
+                                          physicalDropDetected.freefallDuration);
 
     return hardware::Void();
 }
@@ -60,19 +63,19 @@
     for (int i = 0; i < 10 - initialSize; i++) {
         buckets.push_back(0);  // Push 0 for buckets that do not exist.
     }
-    android::util::stats_write(android::util::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1],
-                               buckets[2], buckets[3], buckets[4], buckets[5], buckets[6],
-                               buckets[7], buckets[8], buckets[9]);
+    android::util::statshidl::stats_write(
+            android::util::statshidl::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1], buckets[2],
+            buckets[3], buckets[4], buckets[5], buckets[6], buckets[7], buckets[8], buckets[9]);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsHal::reportBatteryHealthSnapshot(
         const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) {
-    android::util::stats_write(
-            android::util::BATTERY_HEALTH_SNAPSHOT, int32_t(batteryHealthSnapshotArgs.type),
-            batteryHealthSnapshotArgs.temperatureDeciC, batteryHealthSnapshotArgs.voltageMicroV,
-            batteryHealthSnapshotArgs.currentMicroA,
+    android::util::statshidl::stats_write(
+            android::util::statshidl::BATTERY_HEALTH_SNAPSHOT,
+            int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC,
+            batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA,
             batteryHealthSnapshotArgs.openCircuitVoltageMicroV,
             batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent);
 
@@ -80,23 +83,24 @@
 }
 
 hardware::Return<void> StatsHal::reportSlowIo(const SlowIo& slowIo) {
-    android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count);
+    android::util::statshidl::stats_write(android::util::statshidl::SLOW_IO,
+                                          int32_t(slowIo.operation), slowIo.count);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsHal::reportBatteryCausedShutdown(
         const BatteryCausedShutdown& batteryCausedShutdown) {
-    android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN,
-                               batteryCausedShutdown.voltageMicroV);
+    android::util::statshidl::stats_write(android::util::statshidl::BATTERY_CAUSED_SHUTDOWN,
+                                          batteryCausedShutdown.voltageMicroV);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsHal::reportUsbPortOverheatEvent(
         const UsbPortOverheatEvent& usbPortOverheatEvent) {
-    android::util::stats_write(
-            android::util::USB_PORT_OVERHEAT_EVENT_REPORTED,
+    android::util::statshidl::stats_write(
+            android::util::statshidl::USB_PORT_OVERHEAT_EVENT_REPORTED,
             usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC,
             usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis,
             usbPortOverheatEvent.timeToInactive);
@@ -105,9 +109,10 @@
 }
 
 hardware::Return<void> StatsHal::reportSpeechDspStat(const SpeechDspStat& speechDspStat) {
-    android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED,
-                               speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis,
-                               speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount);
+    android::util::statshidl::stats_write(
+            android::util::statshidl::SPEECH_DSP_STAT_REPORTED, speechDspStat.totalUptimeMillis,
+            speechDspStat.totalDowntimeMillis, speechDspStat.totalCrashCount,
+            speechDspStat.totalRecoverCount);
 
     return hardware::Void();
 }