diff --git a/src/com/netease/qa/emmagee/service/EmmageeService.java b/src/com/netease/qa/emmagee/service/EmmageeService.java index 6124d48..081556a 100644 --- a/src/com/netease/qa/emmagee/service/EmmageeService.java +++ b/src/com/netease/qa/emmagee/service/EmmageeService.java @@ -389,7 +389,7 @@ private void getStartTimeFromLogcat() { while ((line = bufferedReader.readLine()) != null) { strBuilder.append(line); - strBuilder.append("\r\n"); + strBuilder.append(Constants.LINE_END); String regex = ".*Displayed.*" + startActivity + ".*\\+(.*)ms.*"; if (line.matches(regex)) { Log.w("my logs", line); @@ -434,10 +434,10 @@ private void dataRefresh() { // 异常数据过滤 try { if (Math.abs(Double.parseDouble(currentBatt)) >= 500) { - currentBatt = "N/A"; + currentBatt = Constants.NA; } } catch (Exception e) { - currentBatt = "N/A"; + currentBatt = Constants.NA; } ArrayList processInfo = cpuInfo.getCpuRatioInfo(totalBatt, currentBatt, temperature, voltage); if (isFloating) { @@ -464,7 +464,7 @@ private void dataRefresh() { txtTotalMem.setText(getString(R.string.process_overall_cpu) + processCpuRatio + "%/" + totalCpuRatio + "%"); String batt = getString(R.string.current) + currentBatt; 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) txtTraffic.setText(batt + "," + getString(R.string.traffic) + fomart.format(trafficMb) + "MB"); else @@ -498,8 +498,8 @@ private void updateViewPosition() { public void closeOpenedStream() { try { if (bw != null) { - bw.write(getString(R.string.comment1) + "\r\n" + getString(R.string.comment2) + "\r\n" + getString(R.string.comment3) + "\r\n" - + getString(R.string.comment4) + "\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) + Constants.LINE_END); bw.close(); } if (osw != null) @@ -523,7 +523,7 @@ public void onDestroy() { // replace the start time in file if (isGrantedReadLogsPermission()) { 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 { replaceFileString(resultFilePath, START_TIME, BLANK_STRING); } @@ -561,7 +561,7 @@ private void replaceFileString(String filePath, String replaceType, String repla String line = BLANK_STRING; String oldtext = BLANK_STRING; while ((line = reader.readLine()) != null) { - oldtext += line + "\r\n"; + oldtext += line + Constants.LINE_END; } reader.close(); // replace a word in a file diff --git a/src/com/netease/qa/emmagee/utils/CpuInfo.java b/src/com/netease/qa/emmagee/utils/CpuInfo.java index 21abe92..21110e3 100644 --- a/src/com/netease/qa/emmagee/utils/CpuInfo.java +++ b/src/com/netease/qa/emmagee/utils/CpuInfo.java @@ -54,7 +54,7 @@ public class CpuInfo { private SimpleDateFormat formatterFile; private MemoryInfo mi; private long totalMemorySize; - private long initialTraffic; + private long preTraffic; private long lastestTraffic; private long traffic; private TrafficInfo trafficInfo; @@ -252,17 +252,20 @@ public ArrayList getCpuRatioInfo(String totalBatt, String currentBatt, S } else mDateTime2 = formatterFile.format(cal.getTime().getTime()); if (isInitialStatics) { - initialTraffic = trafficInfo.getTrafficInfo(); + preTraffic = trafficInfo.getTrafficInfo(); isInitialStatics = false; } else { lastestTraffic = trafficInfo.getTrafficInfo(); - if (initialTraffic == -1) + if (preTraffic == -1) traffic = -1; 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, "initialTraffic===" + initialTraffic); + Log.d(LOG_TAG, "preTraffic===" + preTraffic); StringBuffer totalCpuBuffer = new StringBuffer(); if (null != totalCpu2 && totalCpu2.size() > 0) { processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0)))));