提交 a24e18d7 编写于 作者: A andrewleo

Fixed: #46 remove invalid code in TrafficInfo.java

上级 7cbf2b86
......@@ -46,9 +46,7 @@ public class TrafficInfo {
* @return total traffic include received and send traffic
*/
public long getTrafficInfo() {
Log.i(LOG_TAG, "get traffic information");
Log.d(LOG_TAG, "uid===" + uid);
long rcvTraffic = UNSUPPORTED;
long sndTraffic = UNSUPPORTED;
......@@ -58,40 +56,6 @@ public class TrafficInfo {
rcvTraffic = TrafficStats.getUidRxBytes(Integer.parseInt(uid));
sndTraffic = TrafficStats.getUidTxBytes(Integer.parseInt(uid));
if (rcvTraffic == UNSUPPORTED || sndTraffic == UNSUPPORTED) {
return UNSUPPORTED;
}
RandomAccessFile rafRcv = null, rafSnd = null;
String rcvPath = "/proc/uid_stat/" + uid + "/tcp_rcv";
String sndPath = "/proc/uid_stat/" + uid + "/tcp_snd";
try {
rafRcv = new RandomAccessFile(rcvPath, "r");
rafSnd = new RandomAccessFile(sndPath, "r");
rcvTraffic = Long.parseLong(rafRcv.readLine());
sndTraffic = Long.parseLong(rafSnd.readLine());
} catch (FileNotFoundException e) {
rcvTraffic = UNSUPPORTED;
sndTraffic = UNSUPPORTED;
} catch (NumberFormatException e) {
Log.e(LOG_TAG, "NumberFormatException: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
e.printStackTrace();
} finally {
try {
if (rafRcv != null) {
rafRcv.close();
}
if (rafSnd != null)
rafSnd.close();
} catch (IOException e) {
Log.w(LOG_TAG, "Close randomAccessFile exception: " + e.getMessage());
}
}
if (rcvTraffic == UNSUPPORTED || sndTraffic == UNSUPPORTED) {
return UNSUPPORTED;
} else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册