提交 fd1ebf25 编写于 作者: A andrewleo

Fixed: #32 negative network traffic

上级 4c2dc6d7
...@@ -389,7 +389,7 @@ public class EmmageeService extends Service { ...@@ -389,7 +389,7 @@ public class EmmageeService extends Service {
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
strBuilder.append(line); strBuilder.append(line);
strBuilder.append("\r\n"); strBuilder.append(Constants.LINE_END);
String regex = ".*Displayed.*" + startActivity + ".*\\+(.*)ms.*"; String regex = ".*Displayed.*" + startActivity + ".*\\+(.*)ms.*";
if (line.matches(regex)) { if (line.matches(regex)) {
Log.w("my logs", line); Log.w("my logs", line);
...@@ -434,10 +434,10 @@ public class EmmageeService extends Service { ...@@ -434,10 +434,10 @@ public class EmmageeService extends Service {
// 异常数据过滤 // 异常数据过滤
try { try {
if (Math.abs(Double.parseDouble(currentBatt)) >= 500) { if (Math.abs(Double.parseDouble(currentBatt)) >= 500) {
currentBatt = "N/A"; currentBatt = Constants.NA;
} }
} catch (Exception e) { } catch (Exception e) {
currentBatt = "N/A"; currentBatt = Constants.NA;
} }
ArrayList<String> processInfo = cpuInfo.getCpuRatioInfo(totalBatt, currentBatt, temperature, voltage); ArrayList<String> processInfo = cpuInfo.getCpuRatioInfo(totalBatt, currentBatt, temperature, voltage);
if (isFloating) { if (isFloating) {
...@@ -464,7 +464,7 @@ public class EmmageeService extends Service { ...@@ -464,7 +464,7 @@ public class EmmageeService extends Service {
txtTotalMem.setText(getString(R.string.process_overall_cpu) + processCpuRatio + "%/" + totalCpuRatio + "%"); txtTotalMem.setText(getString(R.string.process_overall_cpu) + processCpuRatio + "%/" + totalCpuRatio + "%");
String batt = getString(R.string.current) + currentBatt; String batt = getString(R.string.current) + currentBatt;
if ("-1".equals(trafficSize)) { if ("-1".equals(trafficSize)) {
txtTraffic.setText(batt + "," + getString(R.string.traffic) + "N/A"); txtTraffic.setText(batt + "," + getString(R.string.traffic) + Constants.NA);
} else if (isMb) } else if (isMb)
txtTraffic.setText(batt + "," + getString(R.string.traffic) + fomart.format(trafficMb) + "MB"); txtTraffic.setText(batt + "," + getString(R.string.traffic) + fomart.format(trafficMb) + "MB");
else else
...@@ -498,8 +498,8 @@ public class EmmageeService extends Service { ...@@ -498,8 +498,8 @@ public class EmmageeService extends Service {
public void closeOpenedStream() { public void closeOpenedStream() {
try { try {
if (bw != null) { if (bw != null) {
bw.write(getString(R.string.comment1) + "\r\n" + getString(R.string.comment2) + "\r\n" + getString(R.string.comment3) + "\r\n" bw.write(getString(R.string.comment1) + Constants.LINE_END + getString(R.string.comment2) + Constants.LINE_END + getString(R.string.comment3) + Constants.LINE_END
+ getString(R.string.comment4) + "\r\n"); + getString(R.string.comment4) + Constants.LINE_END);
bw.close(); bw.close();
} }
if (osw != null) if (osw != null)
...@@ -523,7 +523,7 @@ public class EmmageeService extends Service { ...@@ -523,7 +523,7 @@ public class EmmageeService extends Service {
// replace the start time in file // replace the start time in file
if (isGrantedReadLogsPermission()) { if (isGrantedReadLogsPermission()) {
if (!BLANK_STRING.equals(startTime)) { if (!BLANK_STRING.equals(startTime)) {
replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n"); replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + Constants.LINE_END);
} else { } else {
replaceFileString(resultFilePath, START_TIME, BLANK_STRING); replaceFileString(resultFilePath, START_TIME, BLANK_STRING);
} }
...@@ -561,7 +561,7 @@ public class EmmageeService extends Service { ...@@ -561,7 +561,7 @@ public class EmmageeService extends Service {
String line = BLANK_STRING; String line = BLANK_STRING;
String oldtext = BLANK_STRING; String oldtext = BLANK_STRING;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
oldtext += line + "\r\n"; oldtext += line + Constants.LINE_END;
} }
reader.close(); reader.close();
// replace a word in a file // replace a word in a file
......
...@@ -54,7 +54,7 @@ public class CpuInfo { ...@@ -54,7 +54,7 @@ public class CpuInfo {
private SimpleDateFormat formatterFile; private SimpleDateFormat formatterFile;
private MemoryInfo mi; private MemoryInfo mi;
private long totalMemorySize; private long totalMemorySize;
private long initialTraffic; private long preTraffic;
private long lastestTraffic; private long lastestTraffic;
private long traffic; private long traffic;
private TrafficInfo trafficInfo; private TrafficInfo trafficInfo;
...@@ -252,17 +252,20 @@ public class CpuInfo { ...@@ -252,17 +252,20 @@ public class CpuInfo {
} else } else
mDateTime2 = formatterFile.format(cal.getTime().getTime()); mDateTime2 = formatterFile.format(cal.getTime().getTime());
if (isInitialStatics) { if (isInitialStatics) {
initialTraffic = trafficInfo.getTrafficInfo(); preTraffic = trafficInfo.getTrafficInfo();
isInitialStatics = false; isInitialStatics = false;
} else { } else {
lastestTraffic = trafficInfo.getTrafficInfo(); lastestTraffic = trafficInfo.getTrafficInfo();
if (initialTraffic == -1) if (preTraffic == -1)
traffic = -1; traffic = -1;
else { else {
traffic = (lastestTraffic - initialTraffic + 1023) / 1024; if (lastestTraffic > preTraffic) {
traffic += (lastestTraffic - preTraffic + 1023) / 1024;
}
} }
preTraffic = lastestTraffic;
Log.d(LOG_TAG, "lastestTraffic===" + lastestTraffic); Log.d(LOG_TAG, "lastestTraffic===" + lastestTraffic);
Log.d(LOG_TAG, "initialTraffic===" + initialTraffic); Log.d(LOG_TAG, "preTraffic===" + preTraffic);
StringBuffer totalCpuBuffer = new StringBuffer(); StringBuffer totalCpuBuffer = new StringBuffer();
if (null != totalCpu2 && totalCpu2.size() > 0) { if (null != totalCpu2 && totalCpu2.size() > 0) {
processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0))))); processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0)))));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册