BatteryMonitor: init health info properly.

HIDL enum values are zero initialized, not the first value
of the enum. They need to be initialized properly.

Test: pass
Change-Id: I2adb8b851e6ac607ac4f547a6a6600604d07816f
This commit is contained in:
Yifan Hong 2019-11-05 17:04:50 -08:00
parent 2aabeed1fd
commit 6cabe9bbc7

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;