diff options
-rw-r--r-- | healthd/BatteryMonitor.cpp | 72 | ||||
-rw-r--r-- | healthd/include/healthd/BatteryMonitor.h | 5 |
2 files changed, 36 insertions, 41 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 06c8176e9..57ed362b2 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -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) { - 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); - - len = strlen(dmesgline); - if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { - len += snprintf(dmesgline + len, sizeof(dmesgline) - len, - " c=%d", props.batteryCurrent); - } +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); - if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { - 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); - } - } else { - len = snprintf(dmesgline, sizeof(dmesgline), - "battery none"); + len = strlen(dmesgline); + if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { + len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d", + props.batteryCurrent); } - snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", - props.chargerAcOnline ? "a" : "", - props.chargerUsbOnline ? "u" : "", - props.chargerWirelessOnline ? "w" : ""); + if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { + len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d", + props.batteryFullCharge); + } - KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); + if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { + len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d", + props.batteryCycleCount); + } + } else { + len = snprintf(dmesgline, sizeof(dmesgline), "battery none"); } - healthd_mode_ops->battery_update(&props); + snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", + props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", + props.chargerWirelessOnline ? "w" : ""); + + KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); +} + +bool BatteryMonitor::isChargerOnline() { return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; } diff --git a/healthd/include/healthd/BatteryMonitor.h b/healthd/include/healthd/BatteryMonitor.h index 4d1d53f2c..0fd382412 100644 --- a/healthd/include/healthd/BatteryMonitor.h +++ b/healthd/include/healthd/BatteryMonitor.h @@ -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; |