本文介绍了为什么我无法通过Android ICS中的FileReader正确读取/ proc / net / xt_qtaguid / stats的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读Android ICS中的/ proc / net / xt_qtaguid / stats,该记录了所有接口和应用程序的流量统计信息。以下是代码段:

 字符串行= null; 
BufferReader reader = new BufferedReader(new FileReader(new File( / proc / net / xt_qtaguid / stats)));;

line = reader.readLine(); / *这里我可以正确读取第一行,它返回 idx iface acct_tag_hex ... * /
splitLine(line,keys);
line = reader.readLine(); // !!!!!读取下一行,它返回null!

如果我对此文件进行分类,它将显示:



'p> 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



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 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



我发现NetworkStatsFactory.java(Android原始类)也读取了此文件并使用相同的方法。
我尝试使用此类,但也无法正确读取:

  try {
NetworkStats stats = new NetworkStatsFactory()。readNetworkStatsDetail(10004);
stats.size(); //大小为零!
}
catch(IllegalStateException e){
//什么都不做
}

Google工程师是否犯了同样的错误? :)

解决方案

我已经知道了,这个虚拟文件的read_proc函数限制了uid,每个应用程序只能读取标头和它自己的行。


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? :)

解决方案

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.

这篇关于为什么我无法通过Android ICS中的FileReader正确读取/ proc / net / xt_qtaguid / stats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 10:45