diff options
author | Badhri Jagan Sridharan <Badhri@google.com> | 2016-02-25 20:30:12 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-25 20:30:12 +0000 |
commit | ef375c65832f01640b59d109c480e617216412ec (patch) | |
tree | 6bb497ff1ce7574ce2fceb7d05e9d79d27f936d7 /healthd | |
parent | 73c6fd1af2b0f03fac107f1e1ab3d46cb483aac4 (diff) | |
parent | df09aefc1603903429d8fa7c4838a38a7c6dc8d3 (diff) | |
download | system_core-ef375c65832f01640b59d109c480e617216412ec.tar.gz system_core-ef375c65832f01640b59d109c480e617216412ec.tar.bz2 system_core-ef375c65832f01640b59d109c480e617216412ec.zip |
Merge "healthd: Read the max power supply voltage" into nyc-dev
am: df09aefc16
* commit 'df09aefc1603903429d8fa7c4838a38a7c6dc8d3':
healthd: Read the max power supply voltage
Diffstat (limited to 'healthd')
-rw-r--r-- | healthd/BatteryMonitor.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 51235050a..91943146a 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -40,6 +40,8 @@ #define FAKE_BATTERY_CAPACITY 42 #define FAKE_BATTERY_TEMPERATURE 424 #define ALWAYS_PLUGGED_CAPACITY 100 +#define MILLION 10000000.0 +#define DEFAULT_VBUS_VOLTAGE 5000000 namespace android { @@ -62,6 +64,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; @@ -255,6 +258,7 @@ bool BatteryMonitor::update(void) { props.batteryTechnology = String8(buf); unsigned int i; + double MaxPower = 0; for (i = 0; i < mChargerNames.size(); i++) { String8 path; @@ -283,11 +287,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; } } } @@ -416,9 +432,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); |