diff options
Diffstat (limited to 'healthd')
-rw-r--r-- | healthd/BatteryMonitor.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index d1c547df9..f81e7d9bf 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -42,6 +42,8 @@ #define FAKE_BATTERY_CAPACITY 42 #define FAKE_BATTERY_TEMPERATURE 424 #define ALWAYS_PLUGGED_CAPACITY 100 +#define MILLION 1.0e6 +#define DEFAULT_VBUS_VOLTAGE 5000000 namespace android { @@ -64,6 +66,7 @@ static void initBatteryProperties(BatteryProperties* props) { props->chargerUsbOnline = false; props->chargerWirelessOnline = false; props->maxChargingCurrent = 0; + props->maxChargingVoltage = 0; props->batteryStatus = BATTERY_STATUS_UNKNOWN; props->batteryHealth = BATTERY_HEALTH_UNKNOWN; props->batteryPresent = false; @@ -73,6 +76,7 @@ static void initBatteryProperties(BatteryProperties* props) { props->batteryCurrent = 0; props->batteryCycleCount = 0; props->batteryFullCharge = 0; + props->batteryChargeCounter = 0; props->batteryTechnology.clear(); } @@ -207,6 +211,9 @@ bool BatteryMonitor::update(void) { if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) props.batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath); + if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) + props.batteryChargeCounter = getIntField(mHealthdConfig->batteryChargeCounterPath); + props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); @@ -232,12 +239,12 @@ bool BatteryMonitor::update(void) { props.batteryTechnology = String8(buf.c_str()); unsigned int i; + double MaxPower = 0; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); - if (getIntField(path)) { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, @@ -259,11 +266,23 @@ bool BatteryMonitor::update(void) { path.clear(); path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); - if (access(path.string(), R_OK) == 0) { - int maxChargingCurrent = getIntField(path); - if (props.maxChargingCurrent < maxChargingCurrent) { - props.maxChargingCurrent = maxChargingCurrent; - } + int ChargingCurrent = + (access(path.string(), R_OK) == 0) ? getIntField(path) : 0; + + path.clear(); + path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH, + mChargerNames[i].string()); + + int ChargingVoltage = + (access(path.string(), R_OK) == 0) ? getIntField(path) : + DEFAULT_VBUS_VOLTAGE; + + double power = ((double)ChargingCurrent / MILLION) * + ((double)ChargingVoltage / MILLION); + if (MaxPower < power) { + props.maxChargingCurrent = ChargingCurrent; + props.maxChargingVoltage = ChargingVoltage; + MaxPower = power; } } } @@ -390,9 +409,10 @@ void BatteryMonitor::dumpState(int fd) { int v; char vs[128]; - snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d current_max: %d\n", + snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d current_max: %d voltage_max: %d\n", props.chargerAcOnline, props.chargerUsbOnline, - props.chargerWirelessOnline, props.maxChargingCurrent); + props.chargerWirelessOnline, props.maxChargingCurrent, + props.maxChargingVoltage); write(fd, vs, strlen(vs)); snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n", props.batteryStatus, props.batteryHealth, props.batteryPresent); @@ -611,7 +631,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); if (mHealthdConfig->batteryTechnologyPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); - if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) + if (mHealthdConfig->batteryCurrentNowPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryCurrentNowPath not found\n"); if (mHealthdConfig->batteryFullChargePath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryFullChargePath not found\n"); |