Why I can't read /proc/net/xt_qtaguid/stats correctly by FileReader in Android ICS

对着背影说爱祢 提交于 2019-12-24 02:23:30

问题


I want to read /proc/net/xt_qtaguid/stats in Android ICS, which records all interfaces and applications traffic stats. following is the code snippet:

String line = null;
BufferReader reader = new BufferedReader(new FileReader(new File("/proc/net/xt_qtaguid/stats")));

line = reader.readLine();/*Here I can read the 1st line correctly, it return "idx  iface acct_tag_hex..."*/
splitLine(line, keys);
line = reader.readLine();//!!!!!Read next line, it returns null!!!!!!

If I cat this file, it will show:

idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets

2 rmnet0 0x0 0 0 6266 105 8882 121 1428 30 4838 75 0 0 208 4 2552 44 6122 73

3 rmnet0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4 rmnet0 0x0 1000 0 0 0 2262 39 0 0 0 0 0 0 0 0 2262 39 0 0

5 rmnet0 0x0 1000 1 0 0 290 5 0 0 0 0 0 0 0 0 290 5 0 0

6 rmnet0 0x0 10004 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

7 rmnet0 0x0 10004 1 20177 36 7037 81 20177 36 0 0 0 0 7037 81 0 0 0 0

And I found that the NetworkStatsFactory.java(Android original class) also read this file and use the same method. I try to use this class, and it also can't read correctly:

try{
    NetworkStats stats = new NetworkStatsFactory().readNetworkStatsDetail(10004);
    stats.size();//size is ZERO!
}
catch(IllegalStateException e){
    //Do nothing
}

Did Google engineer make same mistake? :)


回答1:


I've gotten the answer, this virtual file's read_proc function limit the uid, every application can only read the header and its own line.



来源:https://stackoverflow.com/questions/9080229/why-i-cant-read-proc-net-xt-qtaguid-stats-correctly-by-filereader-in-android-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!