Merge "Stats HAL atoms use stats_write"
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 69fbf1f..9ac888b 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -1229,70 +1229,81 @@
 
 hardware::Return<void> StatsService::reportSpeakerImpedance(
         const SpeakerImpedance& speakerImpedance) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), speakerImpedance);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED,
+            speakerImpedance.speakerLocation, speakerImpedance.milliOhms);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportHardwareFailed(const HardwareFailed& hardwareFailed) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), hardwareFailed);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
+            hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportPhysicalDropDetected(
         const PhysicalDropDetected& physicalDropDetected) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), physicalDropDetected);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::PHYSICAL_DROP_DETECTED,
+            int32_t(physicalDropDetected.confidencePctg), physicalDropDetected.accelPeak,
+            physicalDropDetected.freefallDuration);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportChargeCycles(const ChargeCycles& chargeCycles) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), chargeCycles);
-    mProcessor->OnLogEvent(&event);
+    std::vector<int32_t> buckets = chargeCycles.cycleBucket;
+    int initialSize = buckets.size();
+    for (int i = 0; i < 10 - initialSize; i++) {
+        buckets.push_back(-1); // Push -1 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]);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportBatteryHealthSnapshot(
         const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(),
-                   batteryHealthSnapshotArgs);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::BATTERY_HEALTH_SNAPSHOT,
+            int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC,
+            batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA,
+            batteryHealthSnapshotArgs.openCircuitVoltageMicroV,
+            batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportSlowIo(const SlowIo& slowIo) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), slowIo);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportBatteryCausedShutdown(
         const BatteryCausedShutdown& batteryCausedShutdown) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), batteryCausedShutdown);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN,
+            batteryCausedShutdown.voltageMicroV);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportUsbPortOverheatEvent(
         const UsbPortOverheatEvent& usbPortOverheatEvent) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), usbPortOverheatEvent);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::USB_PORT_OVERHEAT_EVENT_REPORTED,
+            usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC,
+            usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis,
+            usbPortOverheatEvent.timeToInactive);
 
     return hardware::Void();
 }
 
 hardware::Return<void> StatsService::reportSpeechDspStat(
         const SpeechDspStat& speechDspStat) {
-    LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), speechDspStat);
-    mProcessor->OnLogEvent(&event);
+    android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED,
+            speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis,
+            speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount);
 
     return hardware::Void();
 }
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index dec36b5..0430e4e 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -21,6 +21,7 @@
 #include "statslog.h"
 
 #include <binder/IPCThreadState.h>
+#include <private/android_filesystem_config.h>
 
 namespace android {
 namespace os {
@@ -202,140 +203,11 @@
 }
 
 LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const SpeakerImpedance& speakerImpedance) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::SPEAKER_IMPEDANCE_REPORTED;
-
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(1)), Value(speakerImpedance.speakerLocation)));
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(2)), Value(speakerImpedance.milliOhms)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const HardwareFailed& hardwareFailed) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::HARDWARE_FAILED;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(int32_t(hardwareFailed.hardwareType))));
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(2)), Value(hardwareFailed.hardwareLocation)));
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(3)), Value(int32_t(hardwareFailed.errorCode))));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const PhysicalDropDetected& physicalDropDetected) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::PHYSICAL_DROP_DETECTED;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(int32_t(physicalDropDetected.confidencePctg))));
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(2)), Value(physicalDropDetected.accelPeak)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)),
-                                 Value(physicalDropDetected.freefallDuration)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const ChargeCycles& chargeCycles) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::CHARGE_CYCLES_REPORTED;
-
-    for (size_t i = 0; i < chargeCycles.cycleBucket.size(); i++) {
-        mValues.push_back(FieldValue(Field(mTagId, getSimpleField(i + 1)),
-                                     Value(chargeCycles.cycleBucket[i])));
-    }
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::BATTERY_HEALTH_SNAPSHOT;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(int32_t(batteryHealthSnapshotArgs.type))));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)),
-                                 Value(batteryHealthSnapshotArgs.temperatureDeciC)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)),
-                                 Value(batteryHealthSnapshotArgs.voltageMicroV)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)),
-                                 Value(batteryHealthSnapshotArgs.currentMicroA)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(5)),
-                                 Value(batteryHealthSnapshotArgs.openCircuitVoltageMicroV)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(6)),
-                                 Value(batteryHealthSnapshotArgs.resistanceMicroOhm)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(7)),
-                                 Value(batteryHealthSnapshotArgs.levelPercent)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs, const SlowIo& slowIo) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::SLOW_IO;
-
-    int pos[] = {1};
-    mValues.push_back(
-            FieldValue(Field(mTagId, getSimpleField(1)), Value(int32_t(slowIo.operation))));
-    pos[0]++;
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), Value(slowIo.count)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const SpeechDspStat& speechDspStat) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::SPEECH_DSP_STAT_REPORTED;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(speechDspStat.totalUptimeMillis)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)),
-                                 Value(speechDspStat.totalDowntimeMillis)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)),
-                                 Value(speechDspStat.totalCrashCount)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)),
-                                 Value(speechDspStat.totalRecoverCount)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const BatteryCausedShutdown& batteryCausedShutdown) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::BATTERY_CAUSED_SHUTDOWN;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(batteryCausedShutdown.voltageMicroV)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                   const UsbPortOverheatEvent& usbPortOverheatEvent) {
-    mLogdTimestampNs = wallClockTimestampNs;
-    mElapsedTimestampNs = elapsedTimestampNs;
-    mTagId = android::util::USB_PORT_OVERHEAT_EVENT_REPORTED;
-
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)),
-                                 Value(usbPortOverheatEvent.plugTemperatureDeciC)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)),
-                                 Value(usbPortOverheatEvent.maxTemperatureDeciC)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(3)),
-                                 Value(usbPortOverheatEvent.timeToOverheat)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(4)),
-                                 Value(usbPortOverheatEvent.timeToHysteresis)));
-    mValues.push_back(FieldValue(Field(mTagId, getSimpleField(5)),
-                                 Value(usbPortOverheatEvent.timeToInactive)));
-}
-
-LogEvent::LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
                    const VendorAtom& vendorAtom) {
     mLogdTimestampNs = wallClockTimestampNs;
     mElapsedTimestampNs = elapsedTimestampNs;
     mTagId = vendorAtom.atomId;
+    mLogUid = AID_STATSD;
 
     mValues.push_back(
             FieldValue(Field(mTagId, getSimpleField(1)), Value(vendorAtom.reverseDomainName)));
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h
index 111a619..2fde8b4 100644
--- a/cmds/statsd/src/logd/LogEvent.h
+++ b/cmds/statsd/src/logd/LogEvent.h
@@ -108,33 +108,6 @@
                       const std::vector<uint8_t>& experimentIds, int32_t userId);
 
     explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const SpeakerImpedance& speakerImpedance);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const HardwareFailed& hardwareFailed);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const PhysicalDropDetected& physicalDropDetected);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const ChargeCycles& chargeCycles);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const SlowIo& slowIo);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const BatteryCausedShutdown& batteryCausedShutdown);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const UsbPortOverheatEvent& usbPortOverheatEvent);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
-                      const SpeechDspStat& speechDspStat);
-
-    explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,
                       const VendorAtom& vendorAtom);
 
     explicit LogEvent(int64_t wallClockTimestampNs, int64_t elapsedTimestampNs,