data activity reporting on wifi

Initial checkin, need icons to complete the feature

Bug: 3412258

Change-Id: I9a3ecc8159cc314d84707065dafe23d402409a84
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index d143243..eca06c5 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -69,6 +69,43 @@
     public static native long getMobileRxBytes();
 
     /**
+     * Get the total number of packets transmitted through the specified interface.
+     *
+     * @return number of packets.  If the statistics are not supported by this interface,
+     * {@link #UNSUPPORTED} will be returned.
+     * @hide
+     */
+    public static native long getTxPackets(String iface);
+
+    /**
+     * Get the total number of packets received through the specified interface.
+     *
+     * @return number of packets.  If the statistics are not supported by this interface,
+     * {@link #UNSUPPORTED} will be returned.
+     * @hide
+     */
+    public static native long getRxPackets(String iface);
+
+    /**
+     * Get the total number of bytes transmitted through the specified interface.
+     *
+     * @return number of bytes.  If the statistics are not supported by this interface,
+     * {@link #UNSUPPORTED} will be returned.
+     * @hide
+     */
+    public static native long getTxBytes(String iface);
+
+    /**
+     * Get the total number of bytes received through the specified interface.
+     *
+     * @return number of bytes.  If the statistics are not supported by this interface,
+     * {@link #UNSUPPORTED} will be returned.
+     * @hide
+     */
+    public static native long getRxBytes(String iface);
+
+
+    /**
      * Get the total number of packets sent through all network interfaces.
      *
      * @return the number of packets.  If the statistics are not supported by this device,
diff --git a/core/jni/android_net_TrafficStats.cpp b/core/jni/android_net_TrafficStats.cpp
index dfa36ce..0c84f11 100644
--- a/core/jni/android_net_TrafficStats.cpp
+++ b/core/jni/android_net_TrafficStats.cpp
@@ -130,6 +130,33 @@
             "/sys/class/net/ppp0/statistics/rx_bytes");
 }
 
+static jlong getData(JNIEnv* env, char *what, jstring interface) {
+    char filename[80];
+    jboolean isCopy;
+
+    const char *interfaceStr = env->GetStringUTFChars(interface, &isCopy);
+    snprintf(filename, sizeof(filename), "/sys/class/net/%s/statistics/%s", interfaceStr, what);
+
+    return readNumber(filename);
+}
+
+static jlong getTxPackets(JNIEnv* env, jobject clazz, jstring interface) {
+    return getData(env, "tx_packets", interface);
+}
+
+static jlong getRxPackets(JNIEnv* env, jobject clazz, jstring interface) {
+    return getData(env, "rx_packets", interface);
+}
+
+static jlong getTxBytes(JNIEnv* env, jobject clazz, jstring interface) {
+    return getData(env, "tx_bytes", interface);
+}
+
+static jlong getRxBytes(JNIEnv* env, jobject clazz, jstring interface) {
+    return getData(env, "rx_bytes", interface);
+}
+
+
 // Total stats are read less often, so we're willing to put up
 // with listing the directory and concatenating filenames.
 
@@ -288,6 +315,10 @@
     {"getMobileRxPackets", "()J", (void*) getMobileRxPackets},
     {"getMobileTxBytes", "()J", (void*) getMobileTxBytes},
     {"getMobileRxBytes", "()J", (void*) getMobileRxBytes},
+    {"getTxPackets", "(Ljava/lang/String;)J", (void*) getTxPackets},
+    {"getRxPackets", "(Ljava/lang/String;)J", (void*) getRxPackets},
+    {"getTxBytes", "(Ljava/lang/String;)J", (void*) getTxBytes},
+    {"getRxBytes", "(Ljava/lang/String;)J", (void*) getRxBytes},
     {"getTotalTxPackets", "()J", (void*) getTotalTxPackets},
     {"getTotalRxPackets", "()J", (void*) getTotalRxPackets},
     {"getTotalTxBytes", "()J", (void*) getTotalTxBytes},