Skip to content

Commit e384d9a

Browse files
author
andrewleo
committed
Added: 优化启动时间,优化界面
1 parent 5b2c7e3 commit e384d9a

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

src/com/netease/qa/emmagee/activity/MainPageActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.DialogInterface;
3131
import android.content.Intent;
3232
import android.content.IntentFilter;
33+
import android.content.pm.ResolveInfo;
3334
import android.os.Bundle;
3435
import android.util.Log;
3536
import android.view.KeyEvent;
@@ -92,6 +93,7 @@ public void onClick(View v) {
9293
if ("开始测试".equals(btnTest.getText().toString())) {
9394
if (isRadioChecked) {
9495
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
96+
String startActivity = "";
9597
Log.d(LOG_TAG, packageName);
9698
//clear logcat
9799
try {
@@ -100,8 +102,9 @@ public void onClick(View v) {
100102
Log.d(LOG_TAG, e.getMessage());
101103
}
102104
try {
105+
startActivity = intent.resolveActivity(getPackageManager()).getShortClassName();
103106
startActivity(intent);
104-
} catch (NullPointerException e) {
107+
} catch (Exception e) {
105108
Toast.makeText(MainPageActivity.this, "该程序无法启动", Toast.LENGTH_LONG).show();
106109
return;
107110
}
@@ -111,6 +114,7 @@ public void onClick(View v) {
111114
monitorService.putExtra("uid", uid);
112115
monitorService.putExtra("packageName", packageName);
113116
monitorService.putExtra("settingTempFile", settingTempFile);
117+
monitorService.putExtra("startActivity", startActivity);
114118
startService(monitorService);
115119
btnTest.setText("停止测试");
116120
} else {

src/com/netease/qa/emmagee/service/EmmageeService.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/com/netease/qa/emmagee/utils/ProcessInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import android.app.ActivityManager;
2424
import android.app.ActivityManager.RunningAppProcessInfo;
2525
import android.content.Context;
26+
import android.content.Intent;
2627
import android.content.pm.ApplicationInfo;
2728
import android.content.pm.PackageManager;
29+
import android.content.pm.ResolveInfo;
2830
import android.util.Log;
2931

3032
/**
@@ -66,6 +68,15 @@ public List<Programe> getRunningProcess(Context context) {
6668
break;
6769
}
6870
}
71+
// Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
72+
// mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
73+
// List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, PackageManager.MATCH_DEFAULT_ONLY);
74+
// for (ResolveInfo temp : appList) {
75+
// Log.d("my logs", temp.activityInfo.packageName);
76+
// if (temp.activityInfo.packageName.toLowerCase().contains("uc")) {
77+
// Log.v("my logs", "package and activity name = " + temp.activityInfo.packageName + " " + temp.activityInfo.name);
78+
// }
79+
// }
6980
programe.setPackageName(appinfo.processName);
7081
programe.setProcessName(appinfo.loadLabel(pm).toString());
7182
programe.setIcon(appinfo.loadIcon(pm));

0 commit comments

Comments
 (0)