healthd: BatteryService dumpstate support

Change-Id: Ia6938b7126751801310632c995af0f96e41f5f64
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index ffd1d34..b721553 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -170,7 +170,6 @@
 }
 
 bool BatteryMonitor::update(void) {
-    struct BatteryProperties props;
     struct BatteryExtraProperties extraProps;
     bool logthis;
 
@@ -242,10 +241,6 @@
         }
     }
 
-    /* temporary while these are moved and dumpsys reworked */
-    props.batteryCurrentNow  = extraProps.batteryCurrentNow;
-    props.batteryChargeCounter = extraProps.batteryChargeCounter;
-
     logthis = !healthd_board_battery_update(&props);
 
     if (logthis) {
@@ -325,6 +320,41 @@
     return ret;
 }
 
+void BatteryMonitor::dumpState(int fd) {
+    int v;
+    char vs[128];
+
+    snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d\n",
+             props.chargerAcOnline, props.chargerUsbOnline,
+             props.chargerWirelessOnline);
+    write(fd, vs, strlen(vs));
+    snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
+             props.batteryStatus, props.batteryHealth, props.batteryPresent);
+    write(fd, vs, strlen(vs));
+    snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n",
+             props.batteryLevel, props.batteryVoltage,
+             props.batteryTemperature);
+    write(fd, vs, strlen(vs));
+
+    if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
+        v = getIntField(mHealthdConfig->batteryCurrentNowPath);
+        snprintf(vs, sizeof(vs), "current now: %d\n", v);
+        write(fd, vs, strlen(vs));
+    }
+
+    if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
+        v = getIntField(mHealthdConfig->batteryCurrentAvgPath);
+        snprintf(vs, sizeof(vs), "current avg: %d\n", v);
+        write(fd, vs, strlen(vs));
+    }
+
+    if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
+        v = getIntField(mHealthdConfig->batteryChargeCounterPath);
+        snprintf(vs, sizeof(vs), "charge counter: %d\n", v);
+        write(fd, vs, strlen(vs));
+    }
+}
+
 void BatteryMonitor::init(struct healthd_config *hc) {
     String8 path;