From 347a9e7a7356fbca387e11abecf551b106c046dd Mon Sep 17 00:00:00 2001 From: Ramakrishnan Ganesh Date: Fri, 15 Nov 2013 16:40:49 -0800 Subject: healthd: Reinitialize mChargerNames for every battery update Booting up the device without usb, the kernel sets the usb power supply type as UNKNOWN. The type of usb power supply changes at run-time as various chargers are plugged in/out. However, healthd initilizes the charger list only at bootup. Change it such that it checks for charger type changes with every battery or usb uevent. While at it, the kernel may have a power supply type which is not known to healthd. This is perfectly fine. Update healthd to not print a warning. Change-Id: I2ec9f9a420ca61814d43c316b418ce94de3691bc --- healthd/BatteryMonitor.cpp | 78 +++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 25 deletions(-) (limited to 'healthd') diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 7ea8250..2f0fefe 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -209,35 +209,63 @@ bool BatteryMonitor::update(void) { if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); - unsigned int i; + // reinitialize the mChargerNames vector everytime there is an update + String8 path; + DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); + if (dir == NULL) { + KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); + } else { + struct dirent* entry; + // reconstruct the charger strings + mChargerNames.clear(); + while ((entry = readdir(dir))) { + const char* name = entry->d_name; - for (i = 0; i < mChargerNames.size(); i++) { - String8 path; - path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, - mChargerNames[i].string()); + if (!strcmp(name, ".") || !strcmp(name, "..")) + continue; - if (readFromFile(path, buf, SIZE) > 0) { - if (buf[0] != '0') { + // Look for "type" file in each subdirectory + path.clear(); + path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); + switch(readPowerSupplyType(path)) { + case ANDROID_POWER_SUPPLY_TYPE_AC: + case ANDROID_POWER_SUPPLY_TYPE_USB: + case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: path.clear(); - path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, - mChargerNames[i].string()); - switch(readPowerSupplyType(path)) { - case ANDROID_POWER_SUPPLY_TYPE_AC: - props.chargerAcOnline = true; - break; - case ANDROID_POWER_SUPPLY_TYPE_USB: - props.chargerUsbOnline = true; - break; - case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: - props.chargerWirelessOnline = true; - break; - default: - KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", - mChargerNames[i].string()); + path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); + if (access(path.string(), R_OK) == 0) { + mChargerNames.add(String8(name)); + if (readFromFile(path, buf, SIZE) > 0) { + if (buf[0] != '0') { + path.clear(); + path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, + name); + switch(readPowerSupplyType(path)) { + case ANDROID_POWER_SUPPLY_TYPE_AC: + props.chargerAcOnline = true; + break; + case ANDROID_POWER_SUPPLY_TYPE_USB: + props.chargerUsbOnline = true; + break; + case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: + props.chargerWirelessOnline = true; + break; + default: + KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", + name); + } + } + } } - } - } - } + break; + case ANDROID_POWER_SUPPLY_TYPE_BATTERY: + break; + default: + break; + } //switch + } //while + closedir(dir); + }//else logthis = !healthd_board_battery_update(&props); -- cgit v1.1 From e8dd797fa233f4a127b1c146601a47cba1f6e02d Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Tue, 6 Jan 2015 18:08:03 -0800 Subject: healthd: Add support for HVDCP and Wipower chargers HVDCP charger is high voltage DCP chargers. Add support to recognize it and treat them as AC power source. Also, Wipower charging is a wireless charger where the power transfer is via resonance and power control messages are exchanged over BLE. Treat Wipower as a wireless charger. CRs-Fixed: 775241 Change-Id: Id49bc31111825721ffce5a71c29f79659c5fddf0 --- healthd/BatteryMonitor.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'healthd') diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 2f0fefe..a6725a2 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -134,7 +134,9 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String { "USB_DCP", ANDROID_POWER_SUPPLY_TYPE_AC }, { "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC }, { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC }, + { "USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC }, { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, + { "Wipower", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { NULL, 0 }, }; -- cgit v1.1 From 725a8913291aa88d1ba55f4ca888a5f0bf06c742 Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Mon, 14 Sep 2015 16:35:26 -0700 Subject: healthd: Add support for HVDCP_3 chargers HVDCP_3 is a high voltage DCP charger where the charger's voltage can be changed by issuing pulses on the D+/D- lines. Add support to recognize it and treat it as an AC power source. Change-Id: Ib719529904e8b7a676bbdc5f5953f0f9da6df3fa --- healthd/BatteryMonitor.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'healthd') diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index a6725a2..b0e9a4d 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -135,6 +135,7 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String { "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC }, { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC }, { "USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC }, + { "USB_HVDCP_3", ANDROID_POWER_SUPPLY_TYPE_AC }, { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { "Wipower", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { NULL, 0 }, -- cgit v1.1