13

I want to implement an extention to android.net.TrafficStats to measure the data traffic per APN or per APN per application. the methods prototype looks like:

getInterfaceTxPackets(String interface)
getInterfaceRxPackets(String interface)
getInterfaceTxBytes(String interface)
getInterfaceRxBytes(String interface)
getUidInterfaceTxPackets(int uid,String interface)
getUidInterfaceRxPackets(int uid,String interface)
getUidInterfaceTxBytes(int uid,String interface)
getUidInterfaceRxBytes(int uid,String interface)

I read the android.net.TrafficStats.java, it call the native methods in android_net_TrafficStats.cpp, and the native methods read the traffic statistics from some files:

  • the total traffic statistic files are in folder /sys/class/net/, in this folder there are some sub folders like: eth0, ip6tnl0, rmnet0, rmnet1, rmnet2, rmnet3., the detailed statistic files are saved in these folders.

  • the per application traffic statistic files are in /proc/uid_stat/[uid]/

My questions:

  1. Do the folder rmnet0, rmnet1, rmnet2, rmnet3... match each APN? If do, what's the match rule? if don't, how can I get each APN traffic statistic?

  2. In folder /proc/uid_stat/[uid]/, there are only two files: tcp_rcv and tcp_snd, how can I get each applicaton on each APN traffic stats?

razlebe
  • 7,134
  • 6
  • 42
  • 57
freeman
  • 233
  • 3
  • 8
  • Are you on ICS? In my opinion, application traffic stats are available only on ICS, see http://developer.android.com/sdk/android-4.0-highlights.html#data-dev – ChrLipp Jan 11 '12 at 13:17
  • 2
    I have found NetworkStatsFactory.java on ICS which can meet this requirement. Thanks – freeman Jan 29 '12 at 05:49

1 Answers1

0

Please switch over to Android 4.0, where for the data usage monitoring this has been beefed up. These APIs now sit on top of a much more complicated service that collects per-interface per-uid traffic information.

Note that there is no meaning associated with each of the interface names, so you can't just assume that a particular name you find on one device means the same thing on another.

hackbod
  • 90,665
  • 16
  • 140
  • 154