From 605e7d20ee12f2b7ca84b0c2e4cf01e060ff7ea9 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 8 Feb 2021 15:14:48 -0800 Subject: [PATCH] BatteryMonitor: Add helper of logValues() ... that logs values for an arbitrary health info and health config. This allows health 2.1 HAL implementation to log the updated health info struct, which is not stored in BatteryMonitor. Test: healthd kernel log has correct values Bug: 179326883 Change-Id: I394ef3f317229f94f4db82de5635d9380c183394 --- healthd/BatteryMonitor.cpp | 13 +++++++++---- healthd/include/healthd/BatteryMonitor.h | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index fd810cbf7..377acb75e 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -349,9 +349,14 @@ void BatteryMonitor::updateValues(void) { } void BatteryMonitor::logValues(void) { + logValues(*mHealthInfo, *mHealthdConfig); +} + +void BatteryMonitor::logValues(const android::hardware::health::V2_1::HealthInfo& health_info, + const struct healthd_config& healthd_config) { char dmesgline[256]; size_t len; - const HealthInfo_1_0& props = mHealthInfo->legacy.legacy; + const HealthInfo_1_0& props = health_info.legacy.legacy; 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 ? "-" : "", @@ -359,17 +364,17 @@ void BatteryMonitor::logValues(void) { props.batteryHealth, props.batteryStatus); len = strlen(dmesgline); - if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { + if (!healthd_config.batteryCurrentNowPath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d", props.batteryCurrent); } - if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { + if (!healthd_config.batteryFullChargePath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d", props.batteryFullCharge); } - if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { + if (!healthd_config.batteryCycleCountPath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d", props.batteryCycleCount); } diff --git a/healthd/include/healthd/BatteryMonitor.h b/healthd/include/healthd/BatteryMonitor.h index fadb5a58c..3cda727be 100644 --- a/healthd/include/healthd/BatteryMonitor.h +++ b/healthd/include/healthd/BatteryMonitor.h @@ -66,6 +66,9 @@ class BatteryMonitor { void logValues(void); bool isChargerOnline(); + static void logValues(const android::hardware::health::V2_1::HealthInfo& health_info, + const struct healthd_config& healthd_config); + private: struct healthd_config *mHealthdConfig; Vector mChargerNames;