diff options
author | Kazuhiro Ondo <kazuhiro.ondo@motorola.com> | 2011-07-10 16:16:54 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-07-10 16:16:54 -0700 |
commit | 99cd66711b99272d4b5d8017eb6ed5fc688c2e4d (patch) | |
tree | c7ee32b2f8fa33c7639717bb7ff57e0c347ea2ff /core/jni | |
parent | d9f91425fc740bc85a8629a27b68b48acaf85962 (diff) | |
parent | 64ba5eaa40614877c679b3fbaaa3c2efd17d50d2 (diff) | |
download | frameworks_base-99cd66711b99272d4b5d8017eb6ed5fc688c2e4d.zip frameworks_base-99cd66711b99272d4b5d8017eb6ed5fc688c2e4d.tar.gz frameworks_base-99cd66711b99272d4b5d8017eb6ed5fc688c2e4d.tar.bz2 |
am 64ba5eaa: Concurrent multi-PDP support in TrafficStats
* commit '64ba5eaa40614877c679b3fbaaa3c2efd17d50d2':
Concurrent multi-PDP support in TrafficStats
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_net_TrafficStats.cpp | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/core/jni/android_net_TrafficStats.cpp b/core/jni/android_net_TrafficStats.cpp index 0c84f11..12150b4 100644 --- a/core/jni/android_net_TrafficStats.cpp +++ b/core/jni/android_net_TrafficStats.cpp @@ -66,10 +66,35 @@ static jlong readNumber(char const* filename) { #endif } -// Return the number from the first file which exists and contains data -static jlong tryBoth(char const* a, char const* b) { - jlong num = readNumber(a); - return num >= 0 ? num : readNumber(b); +static const char* mobile_iface_list[] = { + "rmnet0", + "rmnet1", + "rmnet2", + "rmnet3", + "ppp0", + 0 +}; + +static jlong getAll(const char** iface_list, const char* what) { + + char filename[80]; + int idx = 0; + bool supported = false; + jlong total = 0; + while (iface_list[idx] != 0) { + + snprintf(filename, sizeof(filename), "/sys/class/net/%s/statistics/%s", + iface_list[idx], what); + jlong number = readNumber(filename); + if (number >= 0) { + supported = true; + total += number; + } + idx++; + } + if (supported) return total; + + return -1; } // Returns the sum of numbers from the specified path under /sys/class/net/*, @@ -107,30 +132,22 @@ static jlong readTotal(char const* suffix) { // each file every time (rather than caching which ones exist). static jlong getMobileTxPackets(JNIEnv* env, jobject clazz) { - return tryBoth( - "/sys/class/net/rmnet0/statistics/tx_packets", - "/sys/class/net/ppp0/statistics/tx_packets"); + return getAll(mobile_iface_list, "tx_packets"); } static jlong getMobileRxPackets(JNIEnv* env, jobject clazz) { - return tryBoth( - "/sys/class/net/rmnet0/statistics/rx_packets", - "/sys/class/net/ppp0/statistics/rx_packets"); + return getAll(mobile_iface_list, "rx_packets"); } static jlong getMobileTxBytes(JNIEnv* env, jobject clazz) { - return tryBoth( - "/sys/class/net/rmnet0/statistics/tx_bytes", - "/sys/class/net/ppp0/statistics/tx_bytes"); + return getAll(mobile_iface_list, "tx_bytes"); } static jlong getMobileRxBytes(JNIEnv* env, jobject clazz) { - return tryBoth( - "/sys/class/net/rmnet0/statistics/rx_bytes", - "/sys/class/net/ppp0/statistics/rx_bytes"); + return getAll(mobile_iface_list, "rx_bytes"); } -static jlong getData(JNIEnv* env, char *what, jstring interface) { +static jlong getData(JNIEnv* env, const char *what, jstring interface) { char filename[80]; jboolean isCopy; |