diff options
Diffstat (limited to 'healthd/BatteryMonitor.cpp')
| -rw-r--r-- | healthd/BatteryMonitor.cpp | 81 |
1 files changed, 66 insertions, 15 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 688c7ff..6827062 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -18,7 +18,6 @@ #include "healthd.h" #include "BatteryMonitor.h" -#include "BatteryPropertiesRegistrar.h" #include <dirent.h> #include <errno.h> @@ -28,6 +27,7 @@ #include <unistd.h> #include <batteryservice/BatteryService.h> #include <cutils/klog.h> +#include <utils/Errors.h> #include <utils/String8.h> #include <utils/Vector.h> @@ -171,6 +171,7 @@ int BatteryMonitor::getIntField(const String8& path) { bool BatteryMonitor::update(void) { struct BatteryProperties props; + struct BatteryExtraProperties extraProps; bool logthis; props.chargerAcOnline = false; @@ -178,8 +179,8 @@ bool BatteryMonitor::update(void) { props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; - props.batteryCurrentNow = INT_MIN; - props.batteryChargeCounter = INT_MIN; + extraProps.batteryCurrentNow = INT_MIN; + extraProps.batteryChargeCounter = INT_MIN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); @@ -190,10 +191,11 @@ bool BatteryMonitor::update(void) { props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) - props.batteryCurrentNow = getIntField(mHealthdConfig->batteryCurrentNowPath); + extraProps.batteryCurrentNow = getIntField(mHealthdConfig->batteryCurrentNowPath); + /* temporary while dumpsys being reworked */ if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) - props.batteryChargeCounter = getIntField(mHealthdConfig->batteryChargeCounterPath); + extraProps.batteryChargeCounter = getIntField(mHealthdConfig->batteryChargeCounterPath); props.batteryTemperature = getIntField(mHealthdConfig->batteryTemperaturePath); @@ -240,6 +242,10 @@ bool BatteryMonitor::update(void) { } } + /* temporary while these are moved and dumpsys reworked */ + props.batteryCurrentNow = extraProps.batteryCurrentNow; + props.batteryChargeCounter = extraProps.batteryChargeCounter; + logthis = !healthd_board_battery_update(&props); if (logthis) { @@ -255,7 +261,7 @@ bool BatteryMonitor::update(void) { if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { char b[20]; - snprintf(b, sizeof(b), " c=%d", props.batteryCurrentNow / 1000); + snprintf(b, sizeof(b), " c=%d", extraProps.batteryCurrentNow / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } @@ -265,14 +271,56 @@ bool BatteryMonitor::update(void) { props.chargerWirelessOnline ? "w" : ""); } - if (mBatteryPropertiesRegistrar != NULL) - mBatteryPropertiesRegistrar->notifyListeners(props); - + healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; } -void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) { +status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { + status_t ret = BAD_VALUE; + + switch(id) { + case BATTERY_PROP_CHARGE_COUNTER: + if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) { + val->valueInt = + getIntField(mHealthdConfig->batteryChargeCounterPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_CURRENT_NOW: + if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { + val->valueInt = + getIntField(mHealthdConfig->batteryCurrentNowPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_CURRENT_AVG: + if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { + val->valueInt = + getIntField(mHealthdConfig->batteryCurrentAvgPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + default: + break; + } + + if (ret != NO_ERROR) + val->valueInt = INT_MIN; + + return ret; +} + +void BatteryMonitor::init(struct healthd_config *hc) { String8 path; mHealthdConfig = hc; @@ -358,6 +406,14 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) { mHealthdConfig->batteryCurrentNowPath = path; } + if (mHealthdConfig->batteryCurrentAvgPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/current_avg", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->batteryCurrentAvgPath = path; + } + if (mHealthdConfig->batteryChargeCounterPath.isEmpty()) { path.clear(); path.appendFormat("%s/%s/charge_counter", @@ -414,11 +470,6 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) { KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); if (mHealthdConfig->batteryTechnologyPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); - - if (nosvcmgr == false) { - mBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(this); - mBatteryPropertiesRegistrar->publish(); - } } }; // namespace android |
