healthd: Charger info: Opt-in for battery values

Use current_now and voltage_now instead of current_max and voltage_max.

Needs HEALTHD_USE_BATTERY_INFO := true in BoardConfig.mk

Change-Id: Icef14fa8b2ea353e3ba7cd2c6d1573dbc82474a1
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index 1d05d1e..15b9ed2 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -50,6 +50,10 @@
 #define FAKE_BATTERY_TEMPERATURE 424
 #define MILLION 1.0e6
 #define DEFAULT_VBUS_VOLTAGE 5000000
+#ifdef HEALTHD_USE_BATTERY_INFO
+#define SYSFS_BATTERY_CURRENT "/sys/class/power_supply/battery/current_now"
+#define SYSFS_BATTERY_VOLTAGE "/sys/class/power_supply/battery/voltage_now"
+#endif
 
 using HealthInfo_1_0 = android::hardware::health::V1_0::HealthInfo;
 using HealthInfo_2_0 = android::hardware::health::V2_0::HealthInfo;
@@ -475,6 +479,14 @@
                     KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
                                  mChargerNames[i].c_str());
             }
+
+#ifdef HEALTHD_USE_BATTERY_INFO
+            int ChargingCurrent = (access(SYSFS_BATTERY_CURRENT, R_OK) == 0) ?
+                    abs(getIntField(String8(SYSFS_BATTERY_CURRENT))) : 0;
+
+            int ChargingVoltage = (access(SYSFS_BATTERY_VOLTAGE, R_OK) == 0) ?
+                    getIntField(String8(SYSFS_BATTERY_VOLTAGE)) : DEFAULT_VBUS_VOLTAGE;
+#else
             path.clear();
             path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
                               mChargerNames[i].c_str());
@@ -486,6 +498,7 @@
 
             int ChargingVoltage =
                     (access(path.c_str(), R_OK) == 0) ? getIntField(path) : DEFAULT_VBUS_VOLTAGE;
+#endif
 
             double power = ((double)ChargingCurrent / MILLION) *
                            ((double)ChargingVoltage / MILLION);