Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cabe9bb authored by Yifan Hong's avatar Yifan Hong
Browse files

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
parent 2aabeed1
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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;