Skip to content

Commit

Permalink
refine javadoc and add apache license
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Feb 4, 2013
1 parent 95aa373 commit 81834cf
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 46 deletions.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2012-2013 NetEase, Inc. and other contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
25 changes: 21 additions & 4 deletions src/com/netease/qa/emmagee/activity/MainPageActivity.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.activity;

import java.io.BufferedWriter;
Expand Down Expand Up @@ -77,6 +93,7 @@ public void onClick(View v) {
if (isRadioChecked == true) {
Intent intent = getPackageManager()
.getLaunchIntentForPackage(packageName);
Log.d(LOG_TAG, packageName);
startActivity(intent);
waitForAppStart(packageName);
MonitorService.putExtra("processName", processName);
Expand Down Expand Up @@ -125,10 +142,10 @@ private void createNewFile() {
}

/**
* wait for test app start , timeout is 20s
* wait for test application started , timeout is 20s
*
* @param packageName
* the package name of test app
* package name of test application
*/
private void waitForAppStart(String packageName) {
Log.d(LOG_TAG, "wait for app start");
Expand All @@ -154,7 +171,7 @@ private void waitForAppStart(String packageName) {
}

/**
* override return key to implement a dialog appeared
* override return key to show a dialog
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
Expand Down Expand Up @@ -221,7 +238,7 @@ public void onClick(DialogInterface dialog,
}

/**
* custom adapter
* customizing adapter
*
*/
private class ListAdapter extends BaseAdapter {
Expand Down
16 changes: 16 additions & 0 deletions src/com/netease/qa/emmagee/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.activity;

import java.io.BufferedWriter;
Expand Down
76 changes: 47 additions & 29 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.service;

import java.io.BufferedWriter;
Expand Down Expand Up @@ -39,7 +55,7 @@
import com.netease.qa.emmagee.R;

public class EmmageeService extends Service {

private final static String LOG_TAG = "Emmagee-"
+ EmmageeService.class.getSimpleName();

Expand All @@ -64,9 +80,9 @@ public class EmmageeService extends Service {
private Handler handler = new Handler();
private CpuInfo cpuInfo;
private String time;
private boolean isFloating;
private String processName,packageName,settingTempFile;
private int pid,uid;
private boolean isFloating;
private String processName, packageName, settingTempFile;
private int pid, uid;

public static BufferedWriter bw;
public static FileOutputStream out;
Expand All @@ -88,14 +104,14 @@ public void onStart(Intent intent, int startId) {
Log.i(LOG_TAG, "onStart");
setForeground(true);
super.onStart(intent, startId);

pid = intent.getExtras().getInt("pid");
uid = intent.getExtras().getInt("uid");
processName = intent.getExtras().getString("processName");
packageName = intent.getExtras().getString("packageName");
settingTempFile = intent.getExtras().getString("settingTempFile");
cpuInfo = new CpuInfo(getBaseContext(), pid,Integer.toString(uid));

cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid));
readSettingInfo(intent);
delaytime = Integer.parseInt(time) * 1000;
if (isFloating) {
Expand Down Expand Up @@ -127,15 +143,16 @@ public void onStart(Intent intent, int startId) {
}

/**
* read config file
* read configuration file
*
* @throws IOException
*/
private void readSettingInfo(Intent intent) {
try {
RandomAccessFile raf = new RandomAccessFile(new File(settingTempFile), "r");
RandomAccessFile raf = new RandomAccessFile(new File(
settingTempFile), "r");
time = raf.readLine();
isFloating = raf.readLine().equals("true")?true:false;
isFloating = raf.readLine().equals("true") ? true : false;
} catch (IOException e) {
time = "5";
isFloating = true;
Expand All @@ -158,8 +175,9 @@ private void createResultCsv() {
+ File.separator
+ "Emmagee_TestResult_" + mDateTime + ".csv";
} else {
resultFilePath = getBaseContext().getFilesDir().getPath() + File.separator
+ "Emmagee_TestResult_" + mDateTime + ".csv";
resultFilePath = getBaseContext().getFilesDir().getPath()
+ File.separator + "Emmagee_TestResult_" + mDateTime
+ ".csv";
}
try {
File resultFile = new File(resultFilePath);
Expand All @@ -169,14 +187,12 @@ private void createResultCsv() {
bw = new BufferedWriter(osw);
long totalMemorySize = memoryInfo.getTotalMemory();
String totalMemory = fomart.format((double) totalMemorySize / 1024);
bw.write("指定应用的CPU内存监控情况\r\n" + "应用包名:,"
+ packageName + "\r\n"
+ "应用名称: ," + processName + "\r\n"
+ "应用PID: ," + pid + "\r\n"
+ "机器内存大小(MB):," + totalMemory + "MB\r\n" + "机器CPU型号:,"
+ cpuInfo.getCpuName() + "\r\n" + "机器android系统版本:,"
+ memoryInfo.getSDKVersion() + "\r\n" + "手机型号:,"
+ memoryInfo.getPhoneType() + "\r\n" + "UID:,"
bw.write("指定应用的CPU内存监控情况\r\n" + "应用包名:," + packageName + "\r\n"
+ "应用名称: ," + processName + "\r\n" + "应用PID: ," + pid
+ "\r\n" + "机器内存大小(MB):," + totalMemory + "MB\r\n"
+ "机器CPU型号:," + cpuInfo.getCpuName() + "\r\n"
+ "机器android系统版本:," + memoryInfo.getSDKVersion() + "\r\n"
+ "手机型号:," + memoryInfo.getPhoneType() + "\r\n" + "UID:,"
+ uid + "\r\n");
bw.write("时间" + "," + "应用占用内存PSS(MB)" + "," + "应用占用内存比(%)" + ","
+ " 机器剩余内存(MB)" + "," + "应用占用CPU率(%)" + "," + "CPU总使用率(%)"
Expand All @@ -195,11 +211,12 @@ private void createFloatingWindow() {
SharedPreferences.Editor editor = shared.edit();
editor.putInt("float", 1);
editor.commit();
windowManager = (WindowManager) getApplicationContext().getSystemService("window");
windowManager = (WindowManager) getApplicationContext()
.getSystemService("window");
wmParams = ((MyApplication) getApplication()).getMywmParams();
wmParams.type = 2002;
wmParams.flags |= 8;
wmParams.gravity = Gravity.LEFT | Gravity.TOP;
wmParams.gravity = Gravity.LEFT | Gravity.TOP;
wmParams.x = 0;
wmParams.y = 0;
wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
Expand All @@ -209,7 +226,7 @@ private void createFloatingWindow() {
viFloatingWindow.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
x = event.getRawX();
y = event.getRawY() - 25;
y = event.getRawY() - 25;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// state = MotionEvent.ACTION_DOWN;
Expand All @@ -226,7 +243,7 @@ public boolean onTouch(View v, MotionEvent event) {
break;

case MotionEvent.ACTION_UP:
//state = MotionEvent.ACTION_UP;
// state = MotionEvent.ACTION_UP;
updateViewPosition();
showImg();
mTouchStartX = mTouchStartY = 0;
Expand All @@ -242,7 +259,8 @@ public void onClick(View v) {
try {
btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi);
String buttonText = (String) btnWifi.getText();
String wifiText = getResources().getString(R.string.openwifi);
String wifiText = getResources().getString(
R.string.openwifi);
if (buttonText.equals(wifiText)) {
wifiManager.setWifiEnabled(true);
btnWifi.setText(R.string.closewifi);
Expand Down Expand Up @@ -281,14 +299,14 @@ public void run() {
};

/**
* refresh the data displayed in floating window
* refresh the data showing in floating window
*
* @throws FileNotFoundException
*
* @throws IOException
*/
private void dataRefresh() {
int pidMemory = memoryInfo.getPidMemorySize(pid,getBaseContext());
int pidMemory = memoryInfo.getPidMemorySize(pid, getBaseContext());
long freeMemory = memoryInfo.getFreeMemorySize(getBaseContext());
String freeMemoryKb = fomart.format((double) freeMemory / 1024);
String processMemory = fomart.format((double) pidMemory / 1024);
Expand All @@ -314,8 +332,8 @@ private void dataRefresh() {
}
}
if (processCpuRatio != null && totalCpuRatio != null) {
txtUnusedMem.setText("占用内存:" + processMemory + "MB" + ",机器剩余:" + freeMemoryKb
+ "MB");
txtUnusedMem.setText("占用内存:" + processMemory + "MB" + ",机器剩余:"
+ freeMemoryKb + "MB");
txtTotalMem.setText("占用CPU:" + processCpuRatio + "%"
+ ",总体CPU:" + totalCpuRatio + "%");
if (trafficSize.equals("-1")) {
Expand Down
30 changes: 24 additions & 6 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.utils;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -49,7 +65,7 @@ public CpuInfo(Context context, int pid, String uid) {
}

/**
* read the stat of Cpu
* read the status of CPU
*
* @throws FileNotFoundException
*/
Expand Down Expand Up @@ -94,9 +110,9 @@ public void readCpuStat() {
}

/**
* get the name of current cpu
* get CPU name
*
* @return
* @return CPU name
*/
public String getCpuName() {
try {
Expand All @@ -111,9 +127,11 @@ public String getCpuName() {
}

/**
* reserve process Cpu and total Cpu use ratio
* reserve used ratio of process CPU and total CPU, meanwhile collect
* network traffic
*
* @return
* @return network traffic ,used ratio of process CPU and total CPU in
* certain interval
*/
public ArrayList<String> getCpuRatioInfo() {

Expand Down Expand Up @@ -178,7 +196,7 @@ public ArrayList<String> getCpuRatioInfo() {

}

//TODO coming soon
// TODO coming soon
// public String cpuinfo() {
// String sys_info = "";
// String s;
Expand Down
16 changes: 16 additions & 0 deletions src/com/netease/qa/emmagee/utils/MemoryInfo.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.utils;

import java.io.BufferedReader;
Expand Down
16 changes: 16 additions & 0 deletions src/com/netease/qa/emmagee/utils/MyApplication.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.utils;

import android.app.Application;
Expand Down
Loading

0 comments on commit 81834cf

Please sign in to comment.