我想要实现扩展android.net.TrafficStats
以测量每个APN或每个APN每个应用程序的数据流量。该方法的原型如下:
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)
我阅读了android.net.TrafficStats.java
,它调用了android_net_TrafficStats.cpp
中的本机方法,而本机方法从以下一些文件中读取流量统计信息:
总的流量统计文件位于文件夹
/sys/class/net/
中,该文件夹中有一些子文件夹如:eth0、ip6tnl0、rmnet0、rmnet1、rmnet2、rmnet3,详细的统计文件保存在这些文件夹中。每个应用程序的流量统计文件位于
/proc/uid_stat/[uid]/
中。
我的问题:
文件夹
rmnet0、rmnet1、rmnet2、rmnet3..
是否与每个APN匹配?如果匹配,那么匹配规则是什么?如果不匹配,那么我如何获取每个APN的流量统计信息?在
/proc/uid_stat/[uid]/
文件夹中,只有两个文件:tcp_rcv
和tcp_snd
,我如何获取每个应用程序在每个APN上的流量统计数据?