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

Commit 1353e702 authored by Yifan Hong's avatar Yifan Hong
Browse files

[REFACTOR] healthd: BatteryMonitor::update split into 3 funcs

split bool update() into three functions:

void update()
void logValues()
bool isChargerOnline

... so that it doesn't depend on healthd_board_battery_update and
healthd_mode_ops, which are deprecated.

Test: health 2.0 VTS test
Bug: 142260281
Change-Id: I65908a04bae00654213efb4b5569ced0a7e76076
parent 59a9cef6
Loading
Loading
Loading
Loading
+32 −40
Original line number Diff line number Diff line
@@ -200,9 +200,7 @@ int BatteryMonitor::getIntField(const String8& path) {
    return value;
}

bool BatteryMonitor::update(void) {
    bool logthis;

void BatteryMonitor::updateValues(void) {
    initBatteryProperties(&props);

    if (!mHealthdConfig->batteryPresentPath.isEmpty())
@@ -289,50 +287,44 @@ bool BatteryMonitor::update(void) {
            }
        }
    }
}

    logthis = !healthd_board_battery_update(&props);

    if (logthis) {
void BatteryMonitor::logValues(void) {
    char dmesgline[256];
    size_t len;
    if (props.batteryPresent) {
            snprintf(dmesgline, sizeof(dmesgline),
                 "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
                 props.batteryLevel, props.batteryVoltage,
                 props.batteryTemperature < 0 ? "-" : "",
                 abs(props.batteryTemperature / 10),
                 abs(props.batteryTemperature % 10), props.batteryHealth,
                 props.batteryStatus);
        snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
                 props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "",
                 abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10),
                 props.batteryHealth, props.batteryStatus);

        len = strlen(dmesgline);
        if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
                len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
                                " c=%d", props.batteryCurrent);
            len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d",
                            props.batteryCurrent);
        }

        if (!mHealthdConfig->batteryFullChargePath.isEmpty()) {
                len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
                                " fc=%d", props.batteryFullCharge);
            len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d",
                            props.batteryFullCharge);
        }

        if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) {
                len += snprintf(dmesgline + len, sizeof(dmesgline) - len,
                                " cc=%d", props.batteryCycleCount);
            len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d",
                            props.batteryCycleCount);
        }
    } else {
            len = snprintf(dmesgline, sizeof(dmesgline),
                 "battery none");
        len = snprintf(dmesgline, sizeof(dmesgline), "battery none");
    }

    snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s",
                 props.chargerAcOnline ? "a" : "",
                 props.chargerUsbOnline ? "u" : "",
             props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "",
             props.chargerWirelessOnline ? "w" : "");

    KLOG_WARNING(LOG_TAG, "%s\n", dmesgline);
}

    healthd_mode_ops->battery_update(&props);
bool BatteryMonitor::isChargerOnline() {
    return props.chargerAcOnline | props.chargerUsbOnline |
            props.chargerWirelessOnline;
}
+4 −1
Original line number Diff line number Diff line
@@ -38,12 +38,15 @@ class BatteryMonitor {

    BatteryMonitor();
    void init(struct healthd_config *hc);
    bool update(void);
    int getChargeStatus();
    status_t getProperty(int id, struct BatteryProperty *val);
    void dumpState(int fd);
    friend struct BatteryProperties getBatteryProperties(BatteryMonitor* batteryMonitor);

    void updateValues(void);
    void logValues(void);
    bool isChargerOnline();

  private:
    struct healthd_config *mHealthdConfig;
    Vector<String8> mChargerNames;