Stats HAL atoms use stats_write
Stats HAL atoms were not setting the loguid in LogEvent, resulting in
many events not passing our whitelisting logic. This fixes that by
simplifying the logic to use stats_write, which sets the uid to
AID_STATSD. VendorAtom still has the custom constructor in LogEvent, but
the loguid set to AID_STATSD.
Test: used stats client to log atoms. diffed print-logs for each atom to
ensure the uid was the only difference
Test: used localdrive to locally push the stats hal config and verified
the output was formatted correctly and accurate
Change-Id: Idff3ee3d5b78722da03b4ea2b0e36c213d285535
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();
}