About Android Traffic
- Traffic statistics File: path/proc/net/dev
Open the file, where Lo is the local traffic, Rmnet0 is 3G/2G traffic, Wlan0 is wireless traffic.
- You can find a directory of related categories, such as Rmnet0, under/sys/class/net/. Statistics downstream rx_bytes and Tx_bytes records send and receive traffic in their subdirectories.
- In/PROC/UID_STAT/{UID}/TCP_RCV record the UID app download traffic bytes,/proc/uid_stat/{uid}/tcp_snd have the Uid app upload traffic bytes
Trafficstats Learning
- Trafficstats Google Develop documentation
- Trafficstats source File View
- Important API:
Static long getmobilerxbytes () //Gets the total number of bytes received through the mobile connection and does not contain wifi
Static Long getmobilerxpackets () //Gets the total number of packets received by the mobile connection
Static long Getmobiletxbytes () //mobile The total number of bytes sent
Static long getmobiletxpackets () //mobile the total number of packets sent
Static long gettotalrxbytes () //Gets the total number of accepted bytes, Includes mobile and WiFi ,
Static long gettotalrxpackets () //total number of accepted packets, including mobile and WiFi, etc.
Static long gettotaltxbytes () //The total number of bytes sent, including mobile and WiFi
Static long gettotaltxpackets () //The total number of packets sent, including mobile and WiFi
Static long getuidrxbytes (int uid) //Gets the number of accepted bytes for a network UID
Static long getuidtxbytes ( int uid)//Gets the number of bytes sent for a network UID [/mw_shl_code]
Note: The Trafficstats class appears after the Android 2.2 API level (8).
When doing GXB, the method of checking traffic is based on the UID query system file:
/proc/uid_stat/uid/tcp_send Upload Traffic
/PROC/UID_STAT/UID/TCP_RCV Download Traffic
When doing AVT, it is the method of calling the system through the UID to query the traffic:
proc/uid_stat/10086
Long tx = Trafficstats.getuidtxbytes (UID);//upload traffic sent by byte
Long rx = trafficstats.getuidrxbytes (UID);//Download Traffic byte
Trafficstats.getmobiletxbytes ();//Get the total traffic of mobile 3g/2g network uploads
Trafficstats.getmobilerxbytes ();//Mobile 2g/3g Total Download traffic
Trafficstats.gettotaltxbytes ();//Mobile phone all network interface including WIFI,3G, 2g upload Total traffic
Trafficstats.gettotalrxbytes ();//Mobile all network interface including WIFI,3G, 2g download Total traffic
The essence is the same.
[Android Traffic] Android traffic calculation method