Adds pulling for network bytes for statsd.

Adds atoms to collect network bytes transmitted and received via wifi
and mobile data. We need to get the list of correct ifaces from
BatteryStats since NetworkStatsService only tracks the mobile ifaces.
We split the atoms so that we can also capture metrics sliced on
foreground and background since they are available from the kernel.
Also adds an atom for the Kernel Wakelocks.

Test: Manually tested with adb shell cmd stats pull-source after
modifying the StatsPullerManager.cpp

Change-Id: I9467afad799c6d97560e868f8625fefae5c2b5e1
diff --git a/cmds/statsd/src/stats_events.proto b/cmds/statsd/src/stats_events.proto
index e4e18de..51244c6 100644
--- a/cmds/statsd/src/stats_events.proto
+++ b/cmds/statsd/src/stats_events.proto
@@ -35,7 +35,8 @@
  * in the format defined here and in stats_log.proto.
  */
 message StatsEvent {
-    oneof event {
+    // Pushed events start at 2.
+    oneof pushed {
         // For StatsLog reasons, 1 is illegal and will not work. Must start at 2.
         BleScanStateChanged ble_scan_state_changed = 2;
         BleUnoptimizedScanStateChanged ble_unoptimized_scan_state_changed = 3;
@@ -70,10 +71,18 @@
         WifiScanStateChanged wifi_scan_state_changed = 39;
         PhoneSignalStrengthChanged phone_signal_strength_changed = 40;
         SettingChanged setting_changed = 41;
-        KernelWakelockPulled kernel_wakelock_pulled = 42;
-        ActivityForegroundStateChanged activity_foreground_state_changed = 43;
+        ActivityForegroundStateChanged activity_foreground_state_changed = 42;
         // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
     }
+
+    // Pulled events will start at field 1000.
+    oneof pulled {
+        WifiBytesTransferred wifi_bytes_transferred = 1000;
+        WifiBytesTransferredByFgBg wifi_bytes_transferred_by_fg_bg = 1001;
+        MobileBytesTransferred mobile_bytes_transferred = 1002;
+        MobileBytesTransferredByFgBg mobile_bytes_transferred_by_fg_bg = 1003;
+        KernelWakelocksReported kernel_wakelocks_reported = 1004;
+    }
 }
 
 /**
@@ -682,18 +691,6 @@
     optional int32 user = 7;
 }
 
-/*
- * Pulls kernel wakelock changes.
- *
- * Pulled from:
-  *   frameworks/base/services/core/java/com/android/server/stats/StatsCompanionService.java
- */
-message KernelWakelockPulled {
-    optional int32 count = 1;
-    optional int32 version = 2;
-    optional int64 total_time = 3;
-    optional string name = 4;
-}
 
 /*
  * Logs activity going to foreground or background
@@ -711,3 +708,98 @@
     optional string class_name = 3;
     optional Activity activity = 4;
 }
+
+/**
+ * Pulls bytes transferred via wifi (Sum of foreground and background usage).
+ *
+ * Pulled from:
+ *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
+ */
+message WifiBytesTransferred {
+    optional int32 uid = 1;
+
+    optional int64 rx_bytes = 2;
+
+    optional int64 rx_packets = 3;
+
+    optional int64 tx_bytes = 4;
+
+    optional int64 tx_packets = 5;
+}
+
+/**
+ * Pulls bytes transferred via wifi (separated by foreground and background usage).
+ *
+ * Pulled from:
+ *   StatsCompanionService (using BatteryStats to get which interfaces are wifi)
+ */
+message WifiBytesTransferredByFgBg {
+    optional int32 uid = 1;
+
+    // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats.
+    optional int32 is_foreground = 2;
+
+    optional int64 rx_bytes = 3;
+
+    optional int64 rx_packets = 4;
+
+    optional int64 tx_bytes = 5;
+
+    optional int64 tx_packets = 6;
+}
+
+/**
+ * Pulls bytes transferred via mobile networks (Sum of foreground and background usage).
+ *
+ * Pulled from:
+ *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
+ */
+message MobileBytesTransferred {
+    optional int32 uid = 1;
+
+    optional int64 rx_bytes = 2;
+
+    optional int64 rx_packets = 3;
+
+    optional int64 tx_bytes = 4;
+
+    optional int64 tx_packets = 5;
+}
+
+/**
+ * Pulls bytes transferred via mobile networks (separated by foreground and background usage).
+ *
+ * Pulled from:
+ *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
+ */
+message MobileBytesTransferredByFgBg {
+    optional int32 uid = 1;
+
+    // 1 denotes foreground and 0 denotes background. This is called Set in NetworkStats.
+    optional int32 is_foreground = 2;
+
+    optional int64 rx_bytes = 3;
+
+    optional int64 rx_packets = 4;
+
+    optional int64 tx_bytes = 5;
+
+    optional int64 tx_packets = 6;
+}
+
+/**
+ * Pulls the kernel wakelock durations. This atom is adapted from
+ * android/internal/os/KernelWakelockStats.java
+ *
+ * Pulled from:
+ *   StatsCompanionService using KernelWakelockReader.
+ */
+message KernelWakelocksReported {
+    optional string name = 1;
+
+    optional int32 count = 2;
+
+    optional int32 version = 3;
+
+    optional int64 time = 4;
+}