Atom: Pulled battery level

Atom to pull abttery level directly from health hal

Test: manual on blueline
Test: will do cts
Bug: 119686325
Change-Id: If2e40633b2bb9a6da61fbe1f63484735727e9ac2
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index fa0a018..3208d7d 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -204,6 +204,7 @@
         DeviceCalculatedPowerBlameUid device_calculated_power_blame_uid = 10040;
         DeviceCalculatedPowerBlameOther device_calculated_power_blame_other = 10041;
         ProcessMemoryHighWaterMark process_memory_high_water_mark = 10042;
+        BatteryLevel battery_level = 10043;
     }
 
     // DO NOT USE field numbers above 100,000 in AOSP.
@@ -2679,6 +2680,17 @@
 }
 
 /**
+ * Pulls battery level (percent full, from 0 to 100).
+ *
+ * Pulled from:
+ *   frameworks/base/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
+ */
+message BatteryLevel {
+    // Battery level. Should be in [0, 100].
+    optional int32 battery_level = 1;
+}
+
+/**
  * Pulls the temperature of various parts of the device.
  * The units are tenths of a degree Celsius. Eg: 30.3C is reported as 303.
  *
diff --git a/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp b/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
index ae2cf74..b878652 100644
--- a/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
+++ b/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
@@ -91,6 +91,12 @@
             ptr->write(v.legacy.batteryVoltage);
             ptr->init();
             data->push_back(ptr);
+        } else if (mTagId == android::util::BATTERY_LEVEL) {
+                     auto ptr = make_shared<LogEvent>(android::util::BATTERY_LEVEL,
+                         wallClockTimestampNs, elapsedTimestampNs);
+                     ptr->write(v.legacy.batteryLevel);
+                     ptr->init();
+                     data->push_back(ptr);
         } else {
             ALOGE("Unsupported tag in ResourceHealthManagerPuller: %d", mTagId);
         }
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index a375dd6..ab635a0 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -168,6 +168,9 @@
         // battery_voltage
         {android::util::BATTERY_VOLTAGE,
          {{}, {}, 1 * NS_PER_SEC, new ResourceHealthManagerPuller(android::util::BATTERY_VOLTAGE)}},
+         // battery_voltage
+        {android::util::BATTERY_LEVEL,
+         {{}, {}, 1 * NS_PER_SEC, new ResourceHealthManagerPuller(android::util::BATTERY_LEVEL)}},
         // process_memory_state
         {android::util::PROCESS_MEMORY_STATE,
          {{4, 5, 6, 7, 8, 9},