@@ -98,7 +98,7 @@ public class EmmageeService extends Service {
9898 private CpuInfo cpuInfo ;
9999 private String time ;
100100 private boolean isFloating ;
101- private String processName , packageName , settingTempFile ;
101+ private String processName , packageName , settingTempFile , startActivity ;
102102 private int pid , uid ;
103103 private boolean isServiceStop = false ;
104104 private String sender , password , recipients , smtp ;
@@ -180,6 +180,7 @@ public void onStart(Intent intent, int startId) {
180180 processName = intent .getExtras ().getString ("processName" );
181181 packageName = intent .getExtras ().getString ("packageName" );
182182 settingTempFile = intent .getExtras ().getString ("settingTempFile" );
183+ startActivity = intent .getExtras ().getString ("startActivity" );
183184
184185 cpuInfo = new CpuInfo (getBaseContext (), pid , Integer .toString (uid ));
185186 readSettingInfo (intent );
@@ -205,7 +206,11 @@ public void onStart(Intent intent, int startId) {
205206 btnStop .setOnClickListener (new OnClickListener () {
206207 @ Override
207208 public void onClick (View v ) {
208- isServiceStop = true ;
209+ Intent intent = new Intent ();
210+ intent .putExtra ("isServiceStop" , true );
211+ intent .setAction ("com.netease.action.emmageeService" );
212+ sendBroadcast (intent );
213+ // isServiceStop = true;
209214 Toast .makeText (EmmageeService .this , "测试结果文件:" + resultFilePath , Toast .LENGTH_LONG ).show ();
210215 stopSelf ();
211216 }
@@ -388,23 +393,27 @@ private void getStartTimeFromLogcat() {
388393 String logcatCommand = "logcat -v time -d ActivityManager:I *:S" ;
389394 Process process = Runtime .getRuntime ().exec (logcatCommand );
390395 BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
391- // StringBuilder strBuilder = new StringBuilder();
396+ StringBuilder strBuilder = new StringBuilder ();
392397 String line = "" ;
393398
394399 while ((line = bufferedReader .readLine ()) != null ) {
395- // strBuilder.append(line);
396- // strBuilder.append("\r\n");
397- if (line .matches (".*Displayed.*\\ +(.*)ms.*" )) {
400+ strBuilder .append (line );
401+ strBuilder .append ("\r \n " );
402+ String regex = ".*Displayed.*" + startActivity + ".*\\ +(.*)ms.*" ;
403+ Log .d ("my logs" , regex );
404+ if (line .matches (regex )) {
405+ Log .w ("my logs" , line );
398406 if (line .contains ("total" )) {
399407 line = line .substring (0 , line .indexOf ("total" ));
400408 }
401409 startTime = line .substring (line .lastIndexOf ("+" ) + 1 , line .lastIndexOf ("ms" ) + 2 );
402410 Toast .makeText (EmmageeService .this , "启动时间:" + startTime , Toast .LENGTH_LONG ).show ();
403411 isGetStartTime = false ;
412+ break ;
404413 }
405414 }
406415 getStartTimeCount ++;
407- // Log.w(LOG_TAG , "Start Time Log:" + strBuilder.toString());
416+ // Log.w("my logs" , "Start Time Log:" + strBuilder.toString());
408417 Log .w (LOG_TAG , "getStartCount:" + getStartTimeCount );
409418 } catch (IOException e ) {
410419 Log .d (LOG_TAG , e .getMessage ());
@@ -424,6 +433,18 @@ private void dataRefresh() {
424433 String freeMemoryKb = fomart .format ((double ) freeMemory / 1024 );
425434 String processMemory = fomart .format ((double ) pidMemory / 1024 );
426435 String currentBatt = String .valueOf (currentInfo .getCurrentValue ());
436+ // 异常数据过滤
437+ Log .d ("my logs-before" , currentBatt );
438+ try {
439+ if (Math .abs (Double .parseDouble (currentBatt )) >= 500 ) {
440+ currentBatt = "N/A" ;
441+ } else {
442+ currentBatt = currentBatt + "mA" ;
443+ }
444+ } catch (Exception e ) {
445+ currentBatt = "N/A" ;
446+ }
447+ Log .d ("my logs-after" , currentBatt );
427448 ArrayList <String > processInfo = cpuInfo .getCpuRatioInfo (totalBatt , currentBatt , temperature , voltage );
428449 if (isFloating ) {
429450 String processCpuRatio = "0" ;
@@ -448,13 +469,13 @@ private void dataRefresh() {
448469 if (processCpuRatio != null && totalCpuRatio != null ) {
449470 txtUnusedMem .setText ("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB" );
450471 txtTotalMem .setText ("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%" );
451- String batt = "电流:" + currentBatt + "mA," ;
472+ String batt = "电流:" + currentBatt ;
452473 if ("-1" .equals (trafficSize )) {
453- txtTraffic .setText (batt + "本程序或本设备不支持流量统计 " );
474+ txtTraffic .setText (batt + ",流量:N/A " );
454475 } else if (isMb )
455- txtTraffic .setText (batt + "流量:" + fomart .format (trafficMb ) + "MB" );
476+ txtTraffic .setText (batt + ", 流量:" + fomart .format (trafficMb ) + "MB" );
456477 else
457- txtTraffic .setText (batt + "流量:" + trafficSize + "KB" );
478+ txtTraffic .setText (batt + ", 流量:" + trafficSize + "KB" );
458479 }
459480 // 当内存为0切cpu使用率为0时则是被测应用退出
460481 if ("0" .equals (processMemory ) && "0.00" .equals (processCpuRatio )) {
@@ -480,10 +501,9 @@ private void updateViewPosition() {
480501 public static void closeOpenedStream () {
481502 try {
482503 if (bw != null ) {
483- // TODO 补充一些注释
484504 bw .write ("注释:已知部分不支持的机型可在此查阅:https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported \r \n " );
485- bw .write ("电流:小于0是放电,大于0是充电,部分机型可能无数据 \r \n " );
486- bw .write ("N/A意味不支持或者数据异常 \r \n " );
505+ bw .write ("电流:小于0是放电大于0是充电 \r \n 启动时间:为空是应用已启动或者未搜集到启动时间 \r \n " );
506+ bw .write ("N/A表示不支持或者数据异常 \r \n " );
487507 bw .close ();
488508 }
489509 if (osw != null )
0 commit comments