Skip to content

Commit 11a92a9

Browse files
Vova SharaienkoAndroid (Google) Code Review
authored andcommitted
Merge "[libstatshidl] Removed dependency on libstatslog" into main
2 parents b4fbc2d + c7f6586 commit 11a92a9

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

services/stats/Android.bp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ cc_library_shared {
2929
"libexpresslog",
3030
"libhidlbase",
3131
"liblog",
32-
"libstatslog",
3332
"libstatssocket",
3433
"libutils",
3534
],
35+
generated_sources: [
36+
"statslog_hidl.cpp",
37+
],
38+
generated_headers: [
39+
"statslog_hidl.h",
40+
],
3641
export_include_dirs: [
3742
"include/",
3843
],
@@ -47,3 +52,28 @@ cc_library_shared {
4752
"android.frameworks.stats-service.xml",
4853
],
4954
}
55+
56+
genrule {
57+
name: "statslog_hidl.h",
58+
tools: ["stats-log-api-gen"],
59+
cmd: "$(location stats-log-api-gen)" +
60+
" --header $(genDir)/statslog_hidl.h" +
61+
" --module statshidl" +
62+
" --namespace android,util,statshidl",
63+
out: [
64+
"statslog_hidl.h",
65+
],
66+
}
67+
68+
genrule {
69+
name: "statslog_hidl.cpp",
70+
tools: ["stats-log-api-gen"],
71+
cmd: "$(location stats-log-api-gen)" +
72+
" --cpp $(genDir)/statslog_hidl.cpp" +
73+
" --module statshidl" +
74+
" --namespace android,util,statshidl" +
75+
" --importHeader statslog_hidl.h",
76+
out: [
77+
"statslog_hidl.cpp",
78+
],
79+
}

services/stats/StatsAidl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
#include <log/log.h>
2727
#include <stats_annotations.h>
2828
#include <stats_event.h>
29-
#include <statslog.h>
3029

31-
#include <unordered_map>
30+
#include <map>
3231

3332
namespace {
3433
static const char* g_AtomErrorMetricName =
@@ -118,8 +117,8 @@ ndk::ScopedAStatus StatsHal::reportVendorAtom(const VendorAtom& vendorAtom) {
118117
}
119118
}
120119

121-
// populate map for quickier access for VendorAtomValue associated annotations by value index
122-
std::unordered_map<int, int> fieldIndexToAnnotationSetMap;
120+
// populate map for quicker access for VendorAtomValue associated annotations by value index
121+
std::map<int, int> fieldIndexToAnnotationSetMap;
123122
if (vendorAtom.valuesAnnotations) {
124123
const std::vector<std::optional<AnnotationSet>>& valuesAnnotations =
125124
*vendorAtom.valuesAnnotations;

services/stats/StatsHal.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "StatsHal.h"
2121

2222
#include <log/log.h>
23-
#include <statslog.h>
23+
#include <statslog_hidl.h>
2424

2525
namespace android {
2626
namespace frameworks {
@@ -32,24 +32,27 @@ StatsHal::StatsHal() {
3232
}
3333

3434
hardware::Return<void> StatsHal::reportSpeakerImpedance(const SpeakerImpedance& speakerImpedance) {
35-
android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED,
36-
speakerImpedance.speakerLocation, speakerImpedance.milliOhms);
35+
android::util::statshidl::stats_write(android::util::statshidl::SPEAKER_IMPEDANCE_REPORTED,
36+
speakerImpedance.speakerLocation,
37+
speakerImpedance.milliOhms);
3738

3839
return hardware::Void();
3940
}
4041

4142
hardware::Return<void> StatsHal::reportHardwareFailed(const HardwareFailed& hardwareFailed) {
42-
android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
43-
hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
43+
android::util::statshidl::stats_write(
44+
android::util::statshidl::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
45+
hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
4446

4547
return hardware::Void();
4648
}
4749

4850
hardware::Return<void> StatsHal::reportPhysicalDropDetected(
4951
const PhysicalDropDetected& physicalDropDetected) {
50-
android::util::stats_write(
51-
android::util::PHYSICAL_DROP_DETECTED, int32_t(physicalDropDetected.confidencePctg),
52-
physicalDropDetected.accelPeak, physicalDropDetected.freefallDuration);
52+
android::util::statshidl::stats_write(android::util::statshidl::PHYSICAL_DROP_DETECTED,
53+
int32_t(physicalDropDetected.confidencePctg),
54+
physicalDropDetected.accelPeak,
55+
physicalDropDetected.freefallDuration);
5356

5457
return hardware::Void();
5558
}
@@ -60,43 +63,44 @@ hardware::Return<void> StatsHal::reportChargeCycles(const ChargeCycles& chargeCy
6063
for (int i = 0; i < 10 - initialSize; i++) {
6164
buckets.push_back(0); // Push 0 for buckets that do not exist.
6265
}
63-
android::util::stats_write(android::util::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1],
64-
buckets[2], buckets[3], buckets[4], buckets[5], buckets[6],
65-
buckets[7], buckets[8], buckets[9]);
66+
android::util::statshidl::stats_write(
67+
android::util::statshidl::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1], buckets[2],
68+
buckets[3], buckets[4], buckets[5], buckets[6], buckets[7], buckets[8], buckets[9]);
6669

6770
return hardware::Void();
6871
}
6972

7073
hardware::Return<void> StatsHal::reportBatteryHealthSnapshot(
7174
const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) {
72-
android::util::stats_write(
73-
android::util::BATTERY_HEALTH_SNAPSHOT, int32_t(batteryHealthSnapshotArgs.type),
74-
batteryHealthSnapshotArgs.temperatureDeciC, batteryHealthSnapshotArgs.voltageMicroV,
75-
batteryHealthSnapshotArgs.currentMicroA,
75+
android::util::statshidl::stats_write(
76+
android::util::statshidl::BATTERY_HEALTH_SNAPSHOT,
77+
int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC,
78+
batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA,
7679
batteryHealthSnapshotArgs.openCircuitVoltageMicroV,
7780
batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent);
7881

7982
return hardware::Void();
8083
}
8184

8285
hardware::Return<void> StatsHal::reportSlowIo(const SlowIo& slowIo) {
83-
android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count);
86+
android::util::statshidl::stats_write(android::util::statshidl::SLOW_IO,
87+
int32_t(slowIo.operation), slowIo.count);
8488

8589
return hardware::Void();
8690
}
8791

8892
hardware::Return<void> StatsHal::reportBatteryCausedShutdown(
8993
const BatteryCausedShutdown& batteryCausedShutdown) {
90-
android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN,
91-
batteryCausedShutdown.voltageMicroV);
94+
android::util::statshidl::stats_write(android::util::statshidl::BATTERY_CAUSED_SHUTDOWN,
95+
batteryCausedShutdown.voltageMicroV);
9296

9397
return hardware::Void();
9498
}
9599

96100
hardware::Return<void> StatsHal::reportUsbPortOverheatEvent(
97101
const UsbPortOverheatEvent& usbPortOverheatEvent) {
98-
android::util::stats_write(
99-
android::util::USB_PORT_OVERHEAT_EVENT_REPORTED,
102+
android::util::statshidl::stats_write(
103+
android::util::statshidl::USB_PORT_OVERHEAT_EVENT_REPORTED,
100104
usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC,
101105
usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis,
102106
usbPortOverheatEvent.timeToInactive);
@@ -105,9 +109,10 @@ hardware::Return<void> StatsHal::reportUsbPortOverheatEvent(
105109
}
106110

107111
hardware::Return<void> StatsHal::reportSpeechDspStat(const SpeechDspStat& speechDspStat) {
108-
android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED,
109-
speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis,
110-
speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount);
112+
android::util::statshidl::stats_write(
113+
android::util::statshidl::SPEECH_DSP_STAT_REPORTED, speechDspStat.totalUptimeMillis,
114+
speechDspStat.totalDowntimeMillis, speechDspStat.totalCrashCount,
115+
speechDspStat.totalRecoverCount);
111116

112117
return hardware::Void();
113118
}

0 commit comments

Comments
 (0)