提交 bc8f6730 编写于 作者: A andrewleo2013

refine code

上级 7c495fb7
......@@ -59,7 +59,7 @@ public class MainPageActivity extends Activity {
+ MainPageActivity.class.getSimpleName();
private final int TIMEOUT = 20000;
private List<Programe> processList;
private ProcessInfo processInfo;
private Intent MonitorService;
......@@ -90,7 +90,7 @@ public class MainPageActivity extends Activity {
MonitorService.setClass(MainPageActivity.this,
EmmageeService.class);
if (isTesting) {
if (isRadioChecked == true) {
if (isRadioChecked) {
Intent intent = getPackageManager()
.getLaunchIntentForPackage(packageName);
Log.d(LOG_TAG, packageName);
......@@ -129,7 +129,7 @@ public class MainPageActivity extends Activity {
settingTempFile = getBaseContext().getFilesDir().getPath()
+ "\\Emmagee_Settings.txt";
File settingFile = new File(settingTempFile);
if (!settingFile.exists())
if (!settingFile.exists()) {
try {
settingFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
......@@ -139,13 +139,14 @@ public class MainPageActivity extends Activity {
} catch (IOException e) {
Log.d(LOG_TAG, "create new file exception :" + e.getMessage());
}
}
}
/**
* wait for test application started
* wait for test application started.
*
* @param packageName
* package name of test application
* package name of test application
*/
private void waitForAppStart(String packageName) {
Log.d(LOG_TAG, "wait for app start");
......@@ -165,13 +166,14 @@ public class MainPageActivity extends Activity {
}
}
}
if (isProcessStarted)
if (isProcessStarted) {
break;
}
}
}
/**
* show a dialog when click return key
* show a dialog when click return key.
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
......@@ -181,7 +183,9 @@ public class MainPageActivity extends Activity {
}
/**
* set menu options
* set menu options.
*
* @return true
*/
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, Menu.FIRST, 0, "退出").setIcon(
......@@ -191,6 +195,11 @@ public class MainPageActivity extends Activity {
return true;
}
/**
* trigger menu options.
*
* @return false
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getOrder()) {
case 0:
......@@ -209,7 +218,9 @@ public class MainPageActivity extends Activity {
}
/**
* create a dialog
* create a dialog.
*
* @return a dialog
*/
protected Dialog onCreateDialog(int id) {
switch (id) {
......@@ -238,7 +249,7 @@ public class MainPageActivity extends Activity {
}
/**
* customizing adapter
* customizing adapter.
*
*/
private class ListAdapter extends BaseAdapter {
......
......@@ -40,7 +40,7 @@ public class SettingsActivity extends Activity {
private final String LOG_TAG = "Emmagee-"
+ SettingsActivity.class.getSimpleName();
private CheckBox chkFloat;
private EditText edtTime;
private String time;
......@@ -54,34 +54,37 @@ public class SettingsActivity extends Activity {
Intent intent = this.getIntent();
settingTempFile = intent.getStringExtra("settingTempFile");
chkFloat = (CheckBox) findViewById(R.id.floating);
edtTime = (EditText) findViewById(R.id.time);
Button btnSave = (Button) findViewById(R.id.save);
boolean floatingTag = true;
RandomAccessFile raf ;
try {
RandomAccessFile raf = new RandomAccessFile(settingTempFile, "r");
raf = new RandomAccessFile(settingTempFile, "r");
String f = raf.readLine();
if (f == null || (f != null && f.equals(""))) {
time = "5";
} else
} else {
time = f;
}
String tag = raf.readLine();
if (tag != null && tag.equals("false"))
if (tag != null && tag.equals("false")) {
floatingTag = false;
}
raf.close();
} catch (FileNotFoundException e) {
Log.e(LOG_TAG,
"FileNotFoundException: " + e.getMessage());
Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
e.printStackTrace();
}
edtTime.setText(time);
chkFloat.setChecked(floatingTag);
// edtTime.setInputType(InputType.TYPE_CLASS_NUMBER);
// edtTime.setInputType(InputType.TYPE_CLASS_NUMBER);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
......@@ -131,11 +134,11 @@ public class SettingsActivity extends Activity {
}
/**
* is input a number
* is input a number.
*
* @param inputStr
* input string
* @return
* @return true is numeric
*/
private boolean isNumeric(String inputStr) {
for (int i = inputStr.length(); --i >= 0;) {
......
......@@ -18,7 +18,6 @@ package com.netease.qa.emmagee.service;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
......@@ -143,7 +142,7 @@ public class EmmageeService extends Service {
}
/**
* read configuration file
* read configuration file.
*
* @throws IOException
*/
......@@ -153,15 +152,16 @@ public class EmmageeService extends Service {
settingTempFile), "r");
time = raf.readLine();
isFloating = raf.readLine().equals("true") ? true : false;
raf.close();
} catch (IOException e) {
time = "5";
isFloating = true;
Log.e(LOG_TAG, e.getMessage());
}
}
}
/**
* write the test result to csv format report
* write the test result to csv format report.
*/
private void createResultCsv() {
Calendar cal = Calendar.getInstance();
......@@ -203,7 +203,7 @@ public class EmmageeService extends Service {
}
/**
* create a floating window to show real-time data
* create a floating window to show real-time data.
*/
private void createFloatingWindow() {
SharedPreferences shared = getSharedPreferences("float_flag",
......@@ -278,7 +278,7 @@ public class EmmageeService extends Service {
}
/**
* show the image
* show the image.
*/
private void showImg() {
if (Math.abs(x - startX) < 1.5 && Math.abs(y - startY) < 1.5
......@@ -299,7 +299,7 @@ public class EmmageeService extends Service {
};
/**
* refresh the performance data showing in floating window
* refresh the performance data showing in floating window.
*
* @throws FileNotFoundException
*
......@@ -348,7 +348,7 @@ public class EmmageeService extends Service {
}
/**
* update the position of floating window
* update the position of floating window.
*/
private void updateViewPosition() {
wmParams.x = (int) (x - mTouchStartX);
......@@ -357,7 +357,7 @@ public class EmmageeService extends Service {
}
/**
* close all opened stream
* close all opened stream.
*/
public static void closeOpenedStream() {
try {
......
......@@ -65,7 +65,7 @@ public class CpuInfo {
}
/**
* read the status of CPU
* read the status of CPU.
*
* @throws FileNotFoundException
*/
......@@ -110,15 +110,16 @@ public class CpuInfo {
}
/**
* get CPU name
* get CPU name.
*
* @return CPU name
*/
public String getCpuName() {
try {
RandomAccessFile cpu_stat = new RandomAccessFile("/proc/cpuinfo",
RandomAccessFile cpuStat = new RandomAccessFile("/proc/cpuinfo",
"r");
String[] cpu = cpu_stat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
......@@ -128,7 +129,7 @@ public class CpuInfo {
/**
* reserve used ratio of process CPU and total CPU, meanwhile collect
* network traffic
* network traffic.
*
* @return network traffic ,used ratio of process CPU and total CPU in
* certain interval
......
......@@ -31,7 +31,7 @@ public class MemoryInfo {
+ MemoryInfo.class.getSimpleName();
/**
* get total memory of certain device
* get total memory of certain device.
*
* @return total memory of device
*/
......@@ -49,6 +49,7 @@ public class MemoryInfo {
memTotal = total[1].trim();
}
}
localBufferedReader.close();
String[] memKb = memTotal.split(" ");
memTotal = memKb[0].trim();
Log.d(LOG_TAG, "memTotal: " + memTotal);
......@@ -60,7 +61,7 @@ public class MemoryInfo {
}
/**
* get free memory
* get free memory.
*
* @return free memory of device
*
......@@ -75,7 +76,7 @@ public class MemoryInfo {
}
/**
* get the memory of process with certain pid
* get the memory of process with certain pid.
*
* @param pid
* pid of process
......@@ -98,7 +99,7 @@ public class MemoryInfo {
}
/**
* get the sdk version of phone
* get the sdk version of phone.
*
* @return sdk version
*/
......@@ -107,7 +108,7 @@ public class MemoryInfo {
}
/**
* get phone type
* get phone type.
*
* @return phone type
*/
......
......@@ -37,7 +37,7 @@ public class ProcessInfo {
/**
* get information of all running processes,including package name ,process
* name ,icon ,pid and uid
* name ,icon ,pid and uid.
*
* @param context
* context of activity
......@@ -73,7 +73,7 @@ public class ProcessInfo {
}
programe.setPackageName(appinfo.processName);
programe.setProcessName(appinfo.loadLabel(pm).toString());
if (launchTag == true) {
if (launchTag) {
programe.setIcon(appinfo.loadIcon(pm));
}
progressList.add(programe);
......@@ -82,7 +82,7 @@ public class ProcessInfo {
}
/**
* get information of all applications
* get information of all applications.
*
* @param context
* context of activity
......
......@@ -26,27 +26,29 @@ public class TrafficInfo {
private static final String LOG_TAG = "Emmagee-"
+ TrafficInfo.class.getSimpleName();
private String uid;
public TrafficInfo(String uid){
public TrafficInfo(String uid) {
this.uid = uid;
}
/**
* get total network traffic, which is the sum of upload and download traffic
* get total network traffic, which is the sum of upload and download
* traffic.
*
* @return total traffic include received and send traffic
*/
public long getTrafficInfo() {
Log.i(LOG_TAG,"get traffic information");
Log.i(LOG_TAG, "get traffic information");
RandomAccessFile rafRcv = null, rafSnd = null;
String rcvPath = "/proc/uid_stat/" + uid + "/tcp_rcv";
String sndPath = "/proc/uid_stat/" + uid + "/tcp_snd";
long rcvTraffic = -1;
long sndTraffic = -1;
try {
RandomAccessFile rafRcv = new RandomAccessFile(rcvPath, "r");
RandomAccessFile rafSnd = new RandomAccessFile(sndPath, "r");
rafRcv = new RandomAccessFile(rcvPath, "r");
rafSnd = new RandomAccessFile(sndPath, "r");
rcvTraffic = Long.parseLong(rafRcv.readLine());
sndTraffic = Long.parseLong(rafSnd.readLine());
} catch (FileNotFoundException e) {
......@@ -58,6 +60,14 @@ public class TrafficInfo {
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
e.printStackTrace();
} finally {
try {
rafRcv.close();
rafSnd.close();
} catch (IOException e) {
Log.i(LOG_TAG,
"close randomAccessFile exception: " + e.getMessage());
}
}
if (rcvTraffic == -1 || sndTraffic == -1) {
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册