data activity reporting on wifi

Initial checkin, need icons to complete the feature

Bug: 3412258

Change-Id: I9a3ecc8159cc314d84707065dafe23d402409a84
This commit is contained in:
Irfan Sheriff
2011-02-15 19:30:27 -08:00
parent cfb77b9e4f
commit 042f4e10f0
2 changed files with 68 additions and 0 deletions

View File

@@ -68,6 +68,43 @@ public class TrafficStats {
*/
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.
*

View File

@@ -130,6 +130,33 @@ static jlong getMobileRxBytes(JNIEnv* env, jobject clazz) {
"/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 @@ static JNINativeMethod gMethods[] = {
{"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},