healthd: Read the max power supply voltage

With Type-C PD, VBUS can no longer be assumed to
to be at 5V. Read the "voltage_max" field from the
power_supply class node and export it through
BatteryProperties service.

Bug: 25229483
Change-Id: I04e32d9783a21bab375f1724758a9eeace2a047c
(cherry picked from commit 42d9133a23)
This commit is contained in:
Badhri Jagan Sridharan 2015-10-27 10:43:53 -07:00 committed by Rom Lemarchand
parent d2bbe45713
commit c911044ff8

View file

@ -40,6 +40,8 @@
#define FAKE_BATTERY_CAPACITY 42 #define FAKE_BATTERY_CAPACITY 42
#define FAKE_BATTERY_TEMPERATURE 424 #define FAKE_BATTERY_TEMPERATURE 424
#define ALWAYS_PLUGGED_CAPACITY 100 #define ALWAYS_PLUGGED_CAPACITY 100
#define MILLION 10000000.0
#define DEFAULT_VBUS_VOLTAGE 5000000
namespace android { namespace android {
@ -185,6 +187,7 @@ bool BatteryMonitor::update(void) {
props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryStatus = BATTERY_STATUS_UNKNOWN;
props.batteryHealth = BATTERY_HEALTH_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
props.maxChargingCurrent = 0; props.maxChargingCurrent = 0;
props.maxChargingVoltage = 0;
if (!mHealthdConfig->batteryPresentPath.isEmpty()) if (!mHealthdConfig->batteryPresentPath.isEmpty())
props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath);
@ -223,6 +226,7 @@ bool BatteryMonitor::update(void) {
props.batteryTechnology = String8(buf); props.batteryTechnology = String8(buf);
unsigned int i; unsigned int i;
double MaxPower = 0;
for (i = 0; i < mChargerNames.size(); i++) { for (i = 0; i < mChargerNames.size(); i++) {
String8 path; String8 path;
@ -251,11 +255,23 @@ bool BatteryMonitor::update(void) {
path.clear(); path.clear();
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH, path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
mChargerNames[i].string()); mChargerNames[i].string());
if (access(path.string(), R_OK) == 0) { int ChargingCurrent =
int maxChargingCurrent = getIntField(path); (access(path.string(), R_OK) == 0) ? getIntField(path) : 0;
if (props.maxChargingCurrent < maxChargingCurrent) {
props.maxChargingCurrent = maxChargingCurrent; 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;
} }
} }
} }
@ -385,9 +401,10 @@ void BatteryMonitor::dumpState(int fd) {
int v; int v;
char vs[128]; 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.chargerAcOnline, props.chargerUsbOnline,
props.chargerWirelessOnline, props.maxChargingCurrent); props.chargerWirelessOnline, props.maxChargingCurrent,
props.maxChargingVoltage);
write(fd, vs, strlen(vs)); write(fd, vs, strlen(vs));
snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n", snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
props.batteryStatus, props.batteryHealth, props.batteryPresent); props.batteryStatus, props.batteryHealth, props.batteryPresent);