?????????
?????????о?IOS ????????????????????ü??????????????????????????????????????????????????
????Android 2.2??
????????Android2.2 ?????? ?汾??????????????????????? proc/net/dev?????? proc/self/net/dev??????£???????????????н?????????????????????????????proc/uid_stat/uid /tcp_rcv ??????н??????????????2????????????????????????????????????????????????????????
????adb devices                         ?г??????豸
????adb -s ?豸???? shell                ?????????豸
????cd proc                             ?????豸????????
????cd uid_stat                         ???? user id ???????????ó??????????????????????÷??????????? uid
????ls                                  ?г? uid_stat ??????????????? user id ??
????cd uid                              ?????????? uid ??
????ls                                  ????? uid ???μ? tcp_rcv ?? tcp_snd ??
????cat tcp_rcv                         ??????y???????????
????cat tcp_snd                         ??????÷???????????
????Android 2.2???
???????????????????
?????????
???????PID?????net/dev
?????????????PID
????adb shell ps
??????????PID:21896 ??????/proc???μ?PID/net/dev??????????
????adb shell cat /proc/"+Pid+"/net/dev"
????????wlan0????wifi ????????????! ???????????λ????????/1024?????KB
???????????????????????? ??????? ?? ?????????? ???????
????С?????wlan0??Щ???γ????0 ??? ??????????????????0??
?????????
???????proc/net/xt_qtaguid/stats
???????????????????????????????????????uid
????uid??????????????PID???????status???????鵽uid
????adb shell cat /proc/<pid>/status
????????????????????PackageManager????
????try {
????PackageManager pm = getPackageManager();
????ApplicationInfo ai = pm.getApplicationInfo("PackageName"?? PackageManager.GET_ACTIVITIES);
????Log.d("!!"?? "!!" + ai.uid);
????} catch (NameNotFoundException e) {
????e.printStackTrace();
????}
???????UID?????????
????adb shell cat /proc/net/xt_qtaguid/stats | grep uid
???????е?6??8??? rx_bytes?????????????tx_bytes???????????????tcp??udp???????????????????????
???????uid????????? ???????????????????????????????С?
??????java???????
?????????????????PID???????????????PID??????????????GetFlow??????!
????????????????????????????????????????????????????
????//???PID
public static String PID(String PackageName) throws IOException {
String PID=null;
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("adb shell ps |grep "+PackageName);
try {
if (proc.waitFor() != 0) {
System.err.println("exit value = " + proc.exitValue());
}
BufferedReader in = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
stringBuffer.append(line+" ");
}
String str1=stringBuffer.toString();
String str2=str1.substring(str1.indexOf(" "+PackageName)-46??str1.indexOf(" "+PackageName));
String str3 =str2.substring(0??7);
str3 = str3.trim();
PID=str3;
} catch (InterruptedException e) {
System.err.println(e);
}finally{
try {
proc.destroy();
} catch (Exception e2) {
}
}
return PID;
}
????//???????????
public static double GetFlow(String PackageName) throws IOException {
double FlowSize=0;
String Pid=PID(PackageName);
try{
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("adb shell cat /proc/"+Pid+"/net/dev");
try {
if (proc.waitFor() != 0) {
System.err.println("exit value = " + proc.exitValue());
}
BufferedReader in = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
stringBuffer.append(line+" ");
}
String str1=stringBuffer.toString();
String str2=str1.substring(str1.indexOf("wlan0:")??str1.indexOf("wlan0:")+90);
String str4=str2.substring(7??16);
str4 = str4.trim();
int Flow=Integer.parseInt(str4);
FlowSize=Flow/1024;
} catch (InterruptedException e) {
System.err.println(e);
}finally{
try {
proc.destroy();
} catch (Exception e2) {
}
}
}
catch (Exception StringIndexOutOfBoundsException)
{
}
return FlowSize;
}