Merge "BatteryMonitor: init health info properly."

This commit is contained in:
Treehugger Robot 2019-11-07 00:52:55 +00:00 committed by Gerrit Code Review
commit af7999097e
1 changed files with 15 additions and 2 deletions

View File

@ -73,12 +73,25 @@ static std::optional<T> mapSysfsString(const char* str, SysfsStringEnumMap<T> ma
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 @@ int BatteryMonitor::getIntField(const String8& path) {
}
void BatteryMonitor::updateValues(void) {
*mHealthInfo = HealthInfo_2_1{};
initHealthInfo(mHealthInfo.get());
HealthInfo_1_0& props = mHealthInfo->legacy.legacy;