Merge "BatteryMonitor: init health info properly." am: af7999097e am: fcd4a47e70
am: 9fd3837aa2
Change-Id: I9ff8f7e67f73ca197d2324470c3791fc476f36fb
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index 9e168e9..e80f368 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -73,12 +73,25 @@
return std::nullopt;
}
+static void initHealthInfo(HealthInfo_2_1* health_info_2_1) {
+ *health_info_2_1 = HealthInfo_2_1{};
+
+ // HIDL enum values are zero initialized, so they need to be initialized
+ // properly.
+ health_info_2_1->batteryCapacityLevel = BatteryCapacityLevel::UNKNOWN;
+ auto* props = &health_info_2_1->legacy.legacy;
+ props->batteryStatus = BatteryStatus::UNKNOWN;
+ props->batteryHealth = BatteryHealth::UNKNOWN;
+}
+
BatteryMonitor::BatteryMonitor()
: mHealthdConfig(nullptr),
mBatteryDevicePresent(false),
mBatteryFixedCapacity(0),
mBatteryFixedTemperature(0),
- mHealthInfo(std::make_unique<HealthInfo_2_1>()) {}
+ mHealthInfo(std::make_unique<HealthInfo_2_1>()) {
+ initHealthInfo(mHealthInfo.get());
+}
BatteryMonitor::~BatteryMonitor() {}
@@ -198,7 +211,7 @@
}
void BatteryMonitor::updateValues(void) {
- *mHealthInfo = HealthInfo_2_1{};
+ initHealthInfo(mHealthInfo.get());
HealthInfo_1_0& props = mHealthInfo->legacy.legacy;