diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 0e2700d..3b97244 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,45 +1,46 @@
-
+ android:versionCode="30"
+ android:versionName="2.0" >
-
+
+
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.NoTitleBar">
+ android:name=".activity.MainPageActivity"
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleInstance"
+ android:screenOrientation="portrait">
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
-
+
-
-
+
+
\ No newline at end of file
diff --git a/gen/com/netease/qa/emmagee/R.java b/gen/com/netease/qa/emmagee/R.java
deleted file mode 100644
index a8efacc..0000000
--- a/gen/com/netease/qa/emmagee/R.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/* AUTO-GENERATED FILE. DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found. It
- * should not be modified by hand.
- */
-
-package com.netease.qa.emmagee;
-
-public final class R {
- public static final class attr {
- }
- public static final class drawable {
- public static final int button_bg=0x7f020000;
- public static final int close=0x7f020001;
- public static final int ic_launcher=0x7f020002;
- public static final int icon=0x7f020003;
- public static final int meminfo=0x7f020004;
- }
- public static final class id {
- public static final int Lin=0x7f050003;
- public static final int b=0x7f050001;
- public static final int cpu1=0x7f050017;
- public static final int cpu2=0x7f050018;
- public static final int cpu_info=0x7f050000;
- public static final int floating=0x7f050015;
- public static final int floating_Window=0x7f050014;
- public static final int image=0x7f05000a;
- public static final int img1=0x7f050002;
- public static final int memoryinfo=0x7f05000e;
- public static final int memtotal=0x7f050005;
- public static final int memunused=0x7f050004;
- public static final int password=0x7f050011;
- public static final int processList=0x7f05000c;
- public static final int rb=0x7f050009;
- public static final int recipients=0x7f050013;
- public static final int save=0x7f050016;
- public static final int sender=0x7f050010;
- public static final int smtp=0x7f050012;
- public static final int stop=0x7f050008;
- public static final int test=0x7f05000d;
- public static final int text=0x7f05000b;
- public static final int time=0x7f05000f;
- public static final int traffic=0x7f050006;
- public static final int wifi=0x7f050007;
- }
- public static final class layout {
- public static final int cpu=0x7f030000;
- public static final int floating=0x7f030001;
- public static final int list_item=0x7f030002;
- public static final int mainpage=0x7f030003;
- public static final int memory=0x7f030004;
- public static final int settings=0x7f030005;
- public static final int systemstat=0x7f030006;
- }
- public static final class string {
- public static final int app_name=0x7f040001;
- public static final int app_name1=0x7f040002;
- public static final int app_name2=0x7f040003;
- public static final int app_name3=0x7f040004;
- public static final int app_name4=0x7f040005;
- public static final int bg=0x7f040009;
- public static final int closewifi=0x7f040015;
- public static final int collect=0x7f04000c;
- public static final int cpu=0x7f040008;
- public static final int hello=0x7f040000;
- public static final int memoryinfo=0x7f04000b;
- public static final int ok=0x7f040013;
- public static final int openwifi=0x7f040014;
- public static final int password=0x7f04000f;
- public static final int receiver=0x7f04000d;
- public static final int seconds=0x7f040011;
- public static final int sender=0x7f04000e;
- public static final int smtp=0x7f040010;
- public static final int start=0x7f040007;
- public static final int stopTest=0x7f040016;
- public static final int system=0x7f040006;
- public static final int testmemory=0x7f04000a;
- public static final int window=0x7f040012;
- }
-}
diff --git a/project.properties b/project.properties
index f049142..ea89160 100644
--- a/project.properties
+++ b/project.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-10
+target=android-8
diff --git a/res/drawable-hdpi/actionbar_bg.9.png b/res/drawable-hdpi/actionbar_bg.9.png
new file mode 100644
index 0000000..ea41b6e
Binary files /dev/null and b/res/drawable-hdpi/actionbar_bg.9.png differ
diff --git a/res/drawable-hdpi/bottom_bg.png b/res/drawable-hdpi/bottom_bg.png
new file mode 100644
index 0000000..fa426fe
Binary files /dev/null and b/res/drawable-hdpi/bottom_bg.png differ
diff --git a/res/drawable-hdpi/btn_back.png b/res/drawable-hdpi/btn_back.png
new file mode 100644
index 0000000..d154f5d
Binary files /dev/null and b/res/drawable-hdpi/btn_back.png differ
diff --git a/res/drawable-hdpi/btn_save.png b/res/drawable-hdpi/btn_save.png
new file mode 100644
index 0000000..43fc20e
Binary files /dev/null and b/res/drawable-hdpi/btn_save.png differ
diff --git a/res/drawable-hdpi/btn_test.png b/res/drawable-hdpi/btn_test.png
new file mode 100644
index 0000000..e497a64
Binary files /dev/null and b/res/drawable-hdpi/btn_test.png differ
diff --git a/res/drawable-hdpi/btn_test_press.png b/res/drawable-hdpi/btn_test_press.png
new file mode 100644
index 0000000..f87e0db
Binary files /dev/null and b/res/drawable-hdpi/btn_test_press.png differ
diff --git a/res/drawable-hdpi/checked_icon.png b/res/drawable-hdpi/checked_icon.png
new file mode 100644
index 0000000..66727de
Binary files /dev/null and b/res/drawable-hdpi/checked_icon.png differ
diff --git a/res/drawable-hdpi/goback.png b/res/drawable-hdpi/goback.png
new file mode 100644
index 0000000..1472206
Binary files /dev/null and b/res/drawable-hdpi/goback.png differ
diff --git a/res/drawable-hdpi/right_arrow.png b/res/drawable-hdpi/right_arrow.png
new file mode 100644
index 0000000..ca9c12d
Binary files /dev/null and b/res/drawable-hdpi/right_arrow.png differ
diff --git a/res/drawable-hdpi/seekbar_thumb_normal.png b/res/drawable-hdpi/seekbar_thumb_normal.png
new file mode 100644
index 0000000..91b9362
Binary files /dev/null and b/res/drawable-hdpi/seekbar_thumb_normal.png differ
diff --git a/res/drawable-hdpi/seekbar_thumb_pressed.png b/res/drawable-hdpi/seekbar_thumb_pressed.png
new file mode 100644
index 0000000..b897d22
Binary files /dev/null and b/res/drawable-hdpi/seekbar_thumb_pressed.png differ
diff --git a/res/drawable-hdpi/settings.png b/res/drawable-hdpi/settings.png
new file mode 100644
index 0000000..79f590b
Binary files /dev/null and b/res/drawable-hdpi/settings.png differ
diff --git a/res/drawable-hdpi/settings_pressed.png b/res/drawable-hdpi/settings_pressed.png
new file mode 100644
index 0000000..6c8cfe1
Binary files /dev/null and b/res/drawable-hdpi/settings_pressed.png differ
diff --git a/res/drawable-hdpi/unchecked_icon.png b/res/drawable-hdpi/unchecked_icon.png
new file mode 100644
index 0000000..ef99cc5
Binary files /dev/null and b/res/drawable-hdpi/unchecked_icon.png differ
diff --git a/res/drawable/custom_checkbox.xml b/res/drawable/custom_checkbox.xml
new file mode 100644
index 0000000..faaac8f
--- /dev/null
+++ b/res/drawable/custom_checkbox.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/custom_seekbar.xml b/res/drawable/custom_seekbar.xml
new file mode 100644
index 0000000..00981cc
--- /dev/null
+++ b/res/drawable/custom_seekbar.xml
@@ -0,0 +1,17 @@
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/float_button.xml b/res/drawable/float_button.xml
new file mode 100644
index 0000000..bf1fc3c
--- /dev/null
+++ b/res/drawable/float_button.xml
@@ -0,0 +1,23 @@
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/seekbar_thumb.xml b/res/drawable/seekbar_thumb.xml
new file mode 100644
index 0000000..a0028b4
--- /dev/null
+++ b/res/drawable/seekbar_thumb.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/settings_button.xml b/res/drawable/settings_button.xml
new file mode 100644
index 0000000..a7bf01a
--- /dev/null
+++ b/res/drawable/settings_button.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
diff --git a/res/drawable/test_button.xml b/res/drawable/test_button.xml
new file mode 100644
index 0000000..36582e6
--- /dev/null
+++ b/res/drawable/test_button.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
diff --git a/res/layout/about.xml b/res/layout/about.xml
new file mode 100644
index 0000000..0d6c386
--- /dev/null
+++ b/res/layout/about.xml
@@ -0,0 +1,125 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/cpu.xml b/res/layout/cpu.xml
deleted file mode 100644
index e3f23ec..0000000
--- a/res/layout/cpu.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/floating.xml b/res/layout/floating.xml
index 3425037..67f3277 100644
--- a/res/layout/floating.xml
+++ b/res/layout/floating.xml
@@ -55,18 +55,23 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.4">
-
+
+ android:layout_width="60dp"
+ android:layout_height="30dp"
+ android:layout_marginRight="@dimen/image_padding_small"
+ android:textColor="@color/black"
+ android:background="@drawable/float_button" />
+ android:layout_width="60dp"
+ android:layout_height="30dp"
+ android:textColor="@color/black"
+ android:background="@drawable/float_button" />
diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml
index 9457e7e..5883313 100644
--- a/res/layout/list_item.xml
+++ b/res/layout/list_item.xml
@@ -11,14 +11,21 @@
+ android:layout_marginRight="10dp"
+ android:layout_marginLeft="10dp" />
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:textColor="#5B5B5B"
+ android:gravity="center_vertical"/>
\ No newline at end of file
diff --git a/res/layout/mail_settings.xml b/res/layout/mail_settings.xml
new file mode 100644
index 0000000..19bd1fc
--- /dev/null
+++ b/res/layout/mail_settings.xml
@@ -0,0 +1,143 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/mainpage.xml b/res/layout/mainpage.xml
index 10ceb82..d22ac55 100644
--- a/res/layout/mainpage.xml
+++ b/res/layout/mainpage.xml
@@ -2,29 +2,46 @@
+
+
+
+
+
+ android:layout_weight="1"
+ android:cacheColorHint="@color/light_purple"
+ android:listSelector="@color/light_purple" />
+ android:layout_height="@dimen/layout_height_test"
+ android:background="@drawable/bottom_bg" >
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_marginBottom="@dimen/layout_marginBottom_test"
+ android:layout_marginLeft="@dimen/layout_marginLeft_test"
+ android:layout_marginRight="@dimen/layout_marginRight_test"
+ android:layout_marginTop="@dimen/layout_marginTop_test"
+ android:background="@drawable/test_button"
+ android:text="@string/start_test"
+ android:textColor="@color/white"
+ android:textSize="@dimen/text_size_test" />
\ No newline at end of file
diff --git a/res/layout/memory.xml b/res/layout/memory.xml
deleted file mode 100644
index 0b2cd2b..0000000
--- a/res/layout/memory.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/navigation_bar.xml b/res/layout/navigation_bar.xml
new file mode 100644
index 0000000..e17a466
--- /dev/null
+++ b/res/layout/navigation_bar.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/settings.xml b/res/layout/settings.xml
index 3a355f9..c6fa242 100644
--- a/res/layout/settings.xml
+++ b/res/layout/settings.xml
@@ -2,6 +2,7 @@
-
-
-
-
-
-
-
-
-
-
-
+ layout="@layout/navigation_bar" />
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+ android:layout_marginTop="@dimen/textview_horizontal_margin"
+ android:background="@color/white"
+ android:orientation="vertical" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/systemstat.xml b/res/layout/systemstat.xml
deleted file mode 100644
index 3da4953..0000000
--- a/res/layout/systemstat.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
new file mode 100644
index 0000000..a229a73
--- /dev/null
+++ b/res/values-zh-rCN/strings.xml
@@ -0,0 +1,76 @@
+
+
+
+ Emmagee
+ 设置
+ 退出
+
+ 开始测试
+ 停止测试
+
+ 采集频率(s)
+ 发件人:
+ 密码:
+ SMTP服务器:
+ 收件人(多人以空格分割):
+ 是否显示浮窗
+ 保存
+
+ 计算中...
+ 开启WIFI
+ 关闭WIFI
+ 应用/剩余内存:
+ 应用/总体CPU:
+ 启动时间:
+ 总使用率(%)
+ 应用包名
+ 应用名称
+ 应用PID
+ 机器内存大小(MB)
+ 机器CPU型号
+ Android系统版本
+ 手机型号
+ 时间
+ 应用占用内存PSS(MB)
+ 应用占用内存比(%)
+ 机器剩余内存(MB)
+ 应用占用CPU率(%)
+ CPU总使用率(%)
+ 流量(KB)
+ 电量(%)
+ 电流(mA)
+ 温度(C)
+ 电压(V)
+ 统计出错
+
+ 注释:已知部分不支持的机型可在此查阅:https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported
+ 电流: 小于0是放电大于0是充电
+ 启动时间: 为空是应用已启动或者未搜集到启动时间
+ N/A: 不支持或者数据异常
+
+ 该程序无法启动
+ 请选择需要测试的应用程序
+ 测试结果文件:
+ 保存成功
+ 发件人邮箱:
+ 收件人邮箱:
+ 格式不正确
+ 配置不完整
+ 设置WIFI失败
+ 测试结果报表已发送至邮箱:
+ 测试结果未成功发送至邮箱,结果保存在:
+
+ 确定
+ 取消
+ 确定退出程序?
+ 再点击一次退出应用
+
+ 关于
+ 邮件配置
+ 版本
+ Emmagee是一个简单易上手的Android性能监测小工具,
+ 主要用于监控单个App的CPU,内存,流量,电量,电流以及整体性能状态,
+ 同时支持自定义的监控频率以及性能数据的实时显示.
+ 开发团队:网易(杭州)质量保障部
+ 项目地址:https://github.com/NetEase/Emmagee
+
diff --git a/res/values/colors.xml b/res/values/colors.xml
new file mode 100644
index 0000000..e040738
--- /dev/null
+++ b/res/values/colors.xml
@@ -0,0 +1,16 @@
+
+
+
+ #FFFFFF
+ #000000
+ #EFEFF4
+ #818181
+ #D2D1D5
+ #A6A6A6
+ #0079FF
+ #FF0000
+ #00C378
+ #1D9C00
+ #CECED2
+ #FF4500
+
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
new file mode 100644
index 0000000..9887524
--- /dev/null
+++ b/res/values/dimens.xml
@@ -0,0 +1,38 @@
+
+
+
+ 16dp
+ 16dp
+ 15dp
+ 30dp
+ 20dp
+ 10dp
+ 10dp
+ 3dp
+ 3dp
+ 16sp
+ 12sp
+ 12sp
+ 20sp
+ 30sp
+
+ 140dp
+ 40dp
+
+ 10dp
+ 5dp
+
+ 1px
+
+ 5px
+
+ 60dp
+
+ 50dp
+ 6dp
+ 2dp
+ 30dp
+ 30dp
+ 16sp
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d0392c9..9168303 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1,28 +1,77 @@
-
-
-
- Hello World, RunningTaskActivity!
- Emmagee
- Main
- 系统信息
- 测试
- 设置
- 检测系统信息
- 启动程序
- 开始测试
- 开始测试
- 测试内存
- memoryInfo
- 采集频率:
- 收件人(多人以空格分割):
- 发件人:
- 密码:
- smtp服务器:
- 秒
- 是否显示浮窗
- 保存
- 开启wifi
- 关闭wifi
- 停止测试
-
-
\ No newline at end of file
+
+
+
+ Emmagee
+ Settings
+ Exit
+
+ Start Test
+ Stop Test
+
+ Collecting Interval(s)
+ Sender:
+ Password:
+ SMTP Server:
+ Receivers(separated by space):
+ Show Floating Window
+ Save
+
+ Calculating...
+ WIFI Off
+ WIFI On
+ App/Available Memory:
+ App/System CPU:
+ Start Time:
+ \u0020Total Usage(%)
+ Package Name
+ App Name
+ App PID
+ Device Memory Size(MB)
+ Device CPU Type
+ Android Version
+ Device Brand/Model
+ Timestamp
+ App Used Memory PSS(MB)
+ App Used Memory(%)
+ System Available Memory(MB)
+ App Used CPU(%)
+ Total Used CPU(%)
+ Net Traffic(KB)
+ Battery(%)
+ Current(mA)
+ Temperature(C)
+ Voltage(V)
+ Stat Error
+
+ Note: for unsupported devices refer to: https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported
+ Current: negative for discharging while positive for charging
+ Start time: empty means either the app has been started or failed to fetch start time
+ N/A: not supported or data exception
+
+ The app can not be launched
+ Please select target app
+ Test result file:
+ Saved
+ Sender\'s email:
+ Receiver\'s email:
+ Invalid email format
+ Incomplete email settings
+ Failed to set WIFI
+ Test result has been sent to:
+ Test result failed to be sent to your mailbox, saved at:
+
+ OK
+ Cancel
+ Are you sure to exit?
+ Click again to exit
+
+ About
+ Mail Settings
+ Version
+ Emmagee is a practical, handy performance test tool for specified
+ Android App, which can monitor CPU, memory, network traffic, battery current and status.
+ Additionally, it also provides several cool features such as customizing interval of collecting
+ data, rendering real-time process status in a floating window, and much more.
+ Team:QA, Netease(Hangzhou)
+ Project Address:https://github.com/NetEase/Emmagee
+
diff --git a/res/values/styles.xml b/res/values/styles.xml
new file mode 100644
index 0000000..35cf030
--- /dev/null
+++ b/res/values/styles.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/netease/qa/emmagee/activity/AboutActivity.java b/src/com/netease/qa/emmagee/activity/AboutActivity.java
new file mode 100644
index 0000000..129f6b4
--- /dev/null
+++ b/src/com/netease/qa/emmagee/activity/AboutActivity.java
@@ -0,0 +1,100 @@
+/*
+ * 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 android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.netease.qa.emmagee.R;
+
+/**
+ * About Page of Emmagee
+ *
+ * @author andrewleo
+ */
+public class AboutActivity extends Activity {
+
+ private static final String LOG_TAG = "Emmagee-"
+ + AboutActivity.class.getSimpleName();
+
+ private TextView appVersion;
+ private ImageView goBack;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ Log.i(LOG_TAG, "onCreate");
+ super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ setContentView(R.layout.about);
+
+ appVersion = (TextView)findViewById(R.id.app_version);
+ appVersion.setText(getVersion());
+
+ TextView title = (TextView)findViewById(R.id.nb_title);
+ title.setText(R.string.about);
+
+ ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
+ btnSave.setVisibility(ImageView.INVISIBLE);
+
+ goBack = (ImageView)findViewById(R.id.go_back);
+ LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
+
+ layGoBack.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ AboutActivity.this.finish();
+ }
+ });
+ }
+
+ /**
+ * get app version
+ * @return app version
+ */
+ public String getVersion() {
+ try {
+ PackageManager manager = this.getPackageManager();
+ PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
+ String version = info.versionName;
+ return version;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "-";
+ }
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+}
diff --git a/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java
new file mode 100644
index 0000000..0678be8
--- /dev/null
+++ b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java
@@ -0,0 +1,214 @@
+/*
+ * 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.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.netease.qa.emmagee.R;
+import com.netease.qa.emmagee.utils.EncryptData;
+
+/**
+ * Mail Setting Page of Emmagee
+ *
+ * @author andrewleo
+ */
+public class MailSettingsActivity extends Activity {
+
+ private static final String LOG_TAG = "Emmagee-"
+ + MailSettingsActivity.class.getSimpleName();
+
+ private EditText edtRecipients;
+ private EditText edtSender;
+ private EditText edtPassword;
+ private EditText edtSmtp;
+ private String sender;
+ private String prePassword, curPassword;
+ private String settingTempFile;
+ private String recipients, smtp;
+ private String[] receivers;
+ private TextView title;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ Log.i(LOG_TAG, "onCreate");
+ super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ setContentView(R.layout.mail_settings);
+
+ final EncryptData des = new EncryptData("emmagee");
+ Intent intent = this.getIntent();
+ settingTempFile = getBaseContext().getFilesDir().getPath()
+ + "\\EmmageeSettings.properties";
+ ;
+
+ edtSender = (EditText) findViewById(R.id.sender);
+ edtPassword = (EditText) findViewById(R.id.password);
+ edtRecipients = (EditText) findViewById(R.id.recipients);
+ edtSmtp = (EditText) findViewById(R.id.smtp);
+ title = (TextView)findViewById(R.id.nb_title);
+ ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
+ LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
+ LinearLayout layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set);
+
+ boolean floatingTag = true;
+
+ title.setText(R.string.mail_settings);
+
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(settingTempFile));
+ sender = (null == properties.getProperty("sender")) ? ""
+ : properties.getProperty("sender").trim();
+ prePassword = (null == properties.getProperty("password")) ? ""
+ : properties.getProperty("password").trim();
+ recipients = (null == properties.getProperty("recipients")) ? ""
+ : properties.getProperty("recipients").trim();
+ smtp = (null == properties.getProperty("smtp")) ? "" : properties
+ .getProperty("smtp").trim();
+ } catch (FileNotFoundException e) {
+ Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
+ e.printStackTrace();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "IOException: " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ edtRecipients.setText(recipients);
+ edtSender.setText(sender);
+ edtPassword.setText(prePassword);
+ edtSmtp.setText(smtp);
+
+ layGoBack.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ MailSettingsActivity.this.finish();
+ }
+ });
+ layBtnSet.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ sender = edtSender.getText().toString().trim();
+ if (!"".equals(sender) && !checkMailFormat(sender)) {
+ Toast.makeText(MailSettingsActivity.this, getString(R.string.sender_mail_toast) + getString(R.string.format_incorrect_format),
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ recipients = edtRecipients.getText().toString().trim();
+ receivers = recipients.split("\\s+");
+ for (int i = 0; i < receivers.length; i++) {
+ if (!"".equals(receivers[i])
+ && !checkMailFormat(receivers[i])) {
+ Toast.makeText(MailSettingsActivity.this,
+ getString(R.string.receiver_mail_toast) + "[" + receivers[i] + "]" + getString(R.string.format_incorrect_format),
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ }
+ curPassword = edtPassword.getText().toString().trim();
+ smtp = edtSmtp.getText().toString().trim();
+ if (checkMailConfig(sender, recipients, smtp, curPassword) == -1) {
+ Toast.makeText(MailSettingsActivity.this,
+ getString(R.string.info_incomplete_toast), Toast.LENGTH_LONG).show();
+ return;
+ }
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(settingTempFile));
+ properties.setProperty("sender", sender);
+ Log.d(LOG_TAG, "sender=" + sender);
+ try {
+ properties.setProperty(
+ "password",
+ curPassword.equals(prePassword) ? curPassword
+ : ("".equals(curPassword) ? "" : des
+ .encrypt(curPassword)));
+ } catch (Exception e) {
+ properties.setProperty("password", "");
+ }
+ properties.setProperty("recipients", recipients);
+ properties.setProperty("smtp", smtp);
+ FileOutputStream fos = new FileOutputStream(settingTempFile);
+ properties.store(fos, "Setting Data");
+ fos.close();
+ Toast.makeText(MailSettingsActivity.this, getString(R.string.save_success_toast),
+ Toast.LENGTH_LONG).show();
+ Intent intent = new Intent();
+ setResult(Activity.RESULT_FIRST_USER, intent);
+ MailSettingsActivity.this.finish();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ private int checkMailConfig(String sender, String recipients, String smtp,
+ String curPassword) {
+ if (!"".equals(curPassword) && !"".equals(sender)
+ && !"".equals(recipients) && !"".equals(smtp)) {
+ return 1;
+ } else if ("".equals(curPassword) && "".equals(sender)
+ && "".equals(recipients) && "".equals(smtp)) {
+ return 0;
+ } else
+ return -1;
+ }
+
+ /**
+ * check mail format
+ *
+ * @return true: valid email address
+ */
+ private boolean checkMailFormat(String mail) {
+ String strPattern = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*"
+ + "[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
+ Pattern p = Pattern.compile(strPattern);
+ Matcher m = p.matcher(mail);
+ return m.matches();
+ }
+}
diff --git a/src/com/netease/qa/emmagee/activity/MainPageActivity.java b/src/com/netease/qa/emmagee/activity/MainPageActivity.java
index 063a9eb..d60bb9c 100644
--- a/src/com/netease/qa/emmagee/activity/MainPageActivity.java
+++ b/src/com/netease/qa/emmagee/activity/MainPageActivity.java
@@ -23,27 +23,21 @@
import java.util.Properties;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.Button;
-import android.widget.CompoundButton;
+import android.view.Window;
+import android.widget.*;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
@@ -76,36 +70,43 @@ public class MainPageActivity extends Activity {
private boolean isServiceStop = false;
private UpdateReceiver receiver;
+ private TextView nbTitle;
+ private ImageView ivGoBack;
+ private ImageView ivBtnSet;
+ private LinearLayout layBtnSet;
+ private Long mExitTime = (long) 0;
+
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "MainActivity::onCreate");
super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainpage);
+ initTitleLayout();
createNewFile();
+
processInfo = new ProcessInfo();
- lstViProgramme = (ListView) findViewById(R.id.processList);
- btnTest = (Button) findViewById(R.id.test);
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
monitorService = new Intent();
monitorService.setClass(MainPageActivity.this, EmmageeService.class);
- if ("开始测试".equals(btnTest.getText().toString())) {
+ if (getString(R.string.start_test).equals(btnTest.getText().toString())) {
if (isRadioChecked) {
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
String startActivity = "";
Log.d(LOG_TAG, packageName);
- //clear logcat
- try {
- Runtime.getRuntime().exec("logcat -c");
- } catch (IOException e) {
- Log.d(LOG_TAG, e.getMessage());
- }
+ // clear logcat
+ try {
+ Runtime.getRuntime().exec("logcat -c");
+ } catch (IOException e) {
+ Log.d(LOG_TAG, e.getMessage());
+ }
try {
startActivity = intent.resolveActivity(getPackageManager()).getShortClassName();
startActivity(intent);
} catch (Exception e) {
- Toast.makeText(MainPageActivity.this, "该程序无法启动", Toast.LENGTH_LONG).show();
+ Toast.makeText(MainPageActivity.this, getString(R.string.can_not_start_app_toast), Toast.LENGTH_LONG).show();
return;
}
waitForAppStart(packageName);
@@ -116,18 +117,45 @@ public void onClick(View v) {
monitorService.putExtra("settingTempFile", settingTempFile);
monitorService.putExtra("startActivity", startActivity);
startService(monitorService);
- btnTest.setText("停止测试");
+ btnTest.setText(getString(R.string.stop_test));
} else {
- Toast.makeText(MainPageActivity.this, "请选择需要测试的应用程序", Toast.LENGTH_LONG).show();
+ Toast.makeText(MainPageActivity.this, getString(R.string.choose_app_toast), Toast.LENGTH_LONG).show();
}
} else {
- btnTest.setText("开始测试");
- Toast.makeText(MainPageActivity.this, "测试结果文件:" + EmmageeService.resultFilePath, Toast.LENGTH_LONG).show();
+ btnTest.setText(getString(R.string.start_test));
+ Toast.makeText(MainPageActivity.this, getString(R.string.test_result_file_toast) + EmmageeService.resultFilePath,
+ Toast.LENGTH_LONG).show();
stopService(monitorService);
}
}
});
lstViProgramme.setAdapter(new ListAdapter());
+ lstViProgramme.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
+ RadioButton rdBtn = (RadioButton) ((LinearLayout) view).getChildAt(0);
+ rdBtn.setChecked(true);
+ }
+ });
+
+ nbTitle.setText(getString(R.string.app_name));
+ ivGoBack.setVisibility(ImageView.INVISIBLE);
+ ivBtnSet.setImageResource(R.drawable.settings_button);
+ layBtnSet.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ goToSettingsActivity();
+ }
+ });
+ }
+
+ private void initTitleLayout() {
+ ivGoBack = (ImageView) findViewById(R.id.go_back);
+ nbTitle = (TextView) findViewById(R.id.nb_title);
+ ivBtnSet = (ImageView) findViewById(R.id.btn_set);
+ lstViProgramme = (ListView) findViewById(R.id.processList);
+ btnTest = (Button) findViewById(R.id.test);
+ layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set);
}
/**
@@ -141,7 +169,7 @@ public class UpdateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
isServiceStop = intent.getExtras().getBoolean("isServiceStop");
if (isServiceStop) {
- btnTest.setText("开始测试");
+ btnTest.setText(getString(R.string.start_test));
}
}
}
@@ -161,7 +189,7 @@ public void onResume() {
super.onResume();
Log.d(LOG_TAG, "onResume");
if (EmmageeService.isStop) {
- btnTest.setText("开始测试");
+ btnTest.setText(getString(R.string.start_test));
}
}
@@ -229,69 +257,28 @@ private void waitForAppStart(String packageName) {
* should continue to be propagated.
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
- showDialog(0);
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ if ((System.currentTimeMillis() - mExitTime) > 2000) {
+ Toast.makeText(this, R.string.quite_alert, Toast.LENGTH_SHORT).show();
+ mExitTime = System.currentTimeMillis();
+ } else {
+ if (monitorService != null) {
+ Log.d(LOG_TAG, "stop service");
+ stopService(monitorService);
+ }
+ Log.d(LOG_TAG, "exit Emmagee");
+ finish();
+ }
+ return true;
}
return super.onKeyDown(keyCode, event);
}
- /**
- * set menu options,including cancel and setting options.
- *
- * @return true
- */
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, Menu.FIRST, 0, "退出").setIcon(android.R.drawable.ic_menu_delete);
- menu.add(0, Menu.FIRST, 1, "设置").setIcon(android.R.drawable.ic_menu_directions);
- return true;
- }
-
- /**
- * trigger menu options.
- *
- * @return false
- */
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getOrder()) {
- case 0:
- showDialog(0);
- break;
- case 1:
- Intent intent = new Intent();
- intent.setClass(MainPageActivity.this, SettingsActivity.class);
- intent.putExtra("settingTempFile", settingTempFile);
- startActivityForResult(intent, Activity.RESULT_FIRST_USER);
- break;
- default:
- break;
- }
- return false;
- }
-
- /**
- * create a dialog.
- *
- * @return a dialog
- */
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case 0:
- return new AlertDialog.Builder(this).setTitle("确定退出程序?").setPositiveButton("确定", new android.content.DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (monitorService != null) {
- Log.d(LOG_TAG, "stop service");
- stopService(monitorService);
- }
- Log.d(LOG_TAG, "exit Emmagee");
- EmmageeService.closeOpenedStream();
- finish();
- System.exit(0);
- }
- }).setNegativeButton("取消", null).create();
- default:
- return null;
- }
+ private void goToSettingsActivity() {
+ Intent intent = new Intent();
+ intent.setClass(MainPageActivity.this, SettingsActivity.class);
+ intent.putExtra("settingTempFile", settingTempFile);
+ startActivityForResult(intent, Activity.RESULT_FIRST_USER);
}
/**
@@ -335,12 +322,19 @@ public long getItemId(int position) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
+ Programe pr = (Programe) programe.get(position);
Viewholder holder = new Viewholder();
final int i = position;
convertView = MainPageActivity.this.getLayoutInflater().inflate(R.layout.list_item, null);
+
holder.imgViAppIcon = (ImageView) convertView.findViewById(R.id.image);
+ holder.imgViAppIcon.setImageDrawable(pr.getIcon());
+
holder.txtAppName = (TextView) convertView.findViewById(R.id.text);
+ holder.txtAppName.setText(pr.getProcessName());
+
holder.rdoBtnApp = (RadioButton) convertView.findViewById(R.id.rb);
+ holder.rdoBtnApp.setFocusable(false);
holder.rdoBtnApp.setId(position);
holder.rdoBtnApp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
@@ -365,9 +359,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!holder.rdoBtnApp.isChecked())
holder.rdoBtnApp.setChecked(true);
}
- Programe pr = (Programe) programe.get(position);
- holder.imgViAppIcon.setImageDrawable(pr.getIcon());
- holder.txtAppName.setText(pr.getProcessName());
+
return convertView;
}
}
diff --git a/src/com/netease/qa/emmagee/activity/SettingsActivity.java b/src/com/netease/qa/emmagee/activity/SettingsActivity.java
index 80fcec6..9df67aa 100644
--- a/src/com/netease/qa/emmagee/activity/SettingsActivity.java
+++ b/src/com/netease/qa/emmagee/activity/SettingsActivity.java
@@ -19,21 +19,22 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
+import android.view.Window;
import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.CheckBox;
-import android.widget.EditText;
-import android.widget.Toast;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.utils.EncryptData;
@@ -45,144 +46,125 @@
*/
public class SettingsActivity extends Activity {
- private static final String LOG_TAG = "Emmagee-"
- + SettingsActivity.class.getSimpleName();
+ private static final String LOG_TAG = "Emmagee-" + SettingsActivity.class.getSimpleName();
private CheckBox chkFloat;
- private EditText edtTime;
- private EditText edtRecipients;
- private EditText edtSender;
- private EditText edtPassword;
- private EditText edtSmtp;
- private String time, sender;
- private String prePassword, curPassword;
+ private TextView tvTime;
+ private String time;
private String settingTempFile;
- private String recipients, smtp;
- private String[] receivers;
+ private LinearLayout about;
+ private LinearLayout mailSettings;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "onCreate");
super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
+ Properties properties = new Properties();
final EncryptData des = new EncryptData("emmagee");
Intent intent = this.getIntent();
- settingTempFile = intent.getStringExtra("settingTempFile");
+ settingTempFile = getBaseContext().getFilesDir().getPath() + "\\EmmageeSettings.properties";
chkFloat = (CheckBox) findViewById(R.id.floating);
- edtTime = (EditText) findViewById(R.id.time);
- edtSender = (EditText) findViewById(R.id.sender);
- edtPassword = (EditText) findViewById(R.id.password);
- edtRecipients = (EditText) findViewById(R.id.recipients);
- edtSmtp = (EditText) findViewById(R.id.smtp);
+ tvTime = (TextView) findViewById(R.id.time);
+ about = (LinearLayout) findViewById(R.id.about);
+ mailSettings = (LinearLayout) findViewById(R.id.mail_settings);
+ SeekBar timeBar = (SeekBar) findViewById(R.id.timeline);
+ ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
+ ImageView goBack = (ImageView) findViewById(R.id.go_back);
+ RelativeLayout floatingItem = (RelativeLayout) findViewById(R.id.floating_item);
+ LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
- Button btnSave = (Button) findViewById(R.id.save);
boolean floatingTag = true;
+ btnSave.setVisibility(ImageView.INVISIBLE);
try {
- Properties properties = new Properties();
properties.load(new FileInputStream(settingTempFile));
- String interval = properties.getProperty("interval").trim();
- String isfloat = properties.getProperty("isfloat").trim();
- sender = properties.getProperty("sender").trim();
- prePassword = properties.getProperty("password").trim();
- recipients = properties.getProperty("recipients").trim();
+ String interval = (null == properties.getProperty("interval")) ? "" : properties.getProperty("interval").trim();
+ String isfloat = (null == properties.getProperty("isfloat")) ? "" : properties.getProperty("isfloat").trim();
time = "".equals(interval) ? "5" : interval;
floatingTag = "false".equals(isfloat) ? false : true;
- recipients = properties.getProperty("recipients");
- smtp = properties.getProperty("smtp");
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
e.printStackTrace();
- } catch (IOException e) {
- Log.e(LOG_TAG, "IOException: " + e.getMessage());
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "Exception: " + e.getMessage());
e.printStackTrace();
}
- edtTime.setText(time);
+ tvTime.setText(time);
chkFloat.setChecked(floatingTag);
- edtRecipients.setText(recipients);
- edtSender.setText(sender);
- edtPassword.setText(prePassword);
- edtSmtp.setText(smtp);
+ timeBar.setProgress(Integer.parseInt(time));
+ timeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
+ tvTime.setText(Integer.toString(arg1 + 1));
+ }
- // edtTime.setInputType(InputType.TYPE_CLASS_NUMBER);
- btnSave.setOnClickListener(new OnClickListener() {
@Override
- public void onClick(View v) {
- time = edtTime.getText().toString().trim();
- sender = edtSender.getText().toString().trim();
- if (!"".equals(sender) && !checkMailFormat(sender)) {
- Toast.makeText(SettingsActivity.this, "发件人邮箱格式不正确",
- Toast.LENGTH_LONG).show();
- return;
- }
- recipients = edtRecipients.getText().toString().trim();
- receivers = recipients.split("\\s+");
- for (int i = 0; i < receivers.length; i++) {
- if (!"".equals(receivers[i])
- && !checkMailFormat(receivers[i])) {
- Toast.makeText(SettingsActivity.this,
- "收件人邮箱" + receivers[i] + "格式不正确",
- Toast.LENGTH_LONG).show();
- return;
- }
- }
- curPassword = edtPassword.getText().toString().trim();
- smtp = edtSmtp.getText().toString().trim();
- if (checkMailConfig(sender, recipients, smtp, curPassword) == -1) {
- Toast.makeText(SettingsActivity.this, "邮箱配置不完整,请完善所有信息",
- Toast.LENGTH_LONG).show();
- return;
+ public void onStartTrackingTouch(SeekBar arg0) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar arg0) {
+ // when tracking stoped, update properties file
+ int interval = arg0.getProgress() + 1;
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(settingTempFile));
+ properties.setProperty("interval", Integer.toString(interval));
+ FileOutputStream fos = new FileOutputStream(settingTempFile);
+ properties.store(fos, "Setting Data");
+ fos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- if (!isNumeric(time)) {
- Toast.makeText(SettingsActivity.this, "输入数据无效,请重新输入",
- Toast.LENGTH_LONG).show();
- edtTime.setText("");
- } else if ("".equals(time) || Long.parseLong(time) == 0) {
- Toast.makeText(SettingsActivity.this, "输入数据为空,请重新输入",
- Toast.LENGTH_LONG).show();
- edtTime.setText("");
- } else if (Integer.parseInt(time) > 600) {
- Toast.makeText(SettingsActivity.this, "数据超过最大值600,请重新输入",
- Toast.LENGTH_LONG).show();
- } else {
- try {
- Properties properties = new Properties();
- properties.setProperty("interval", time);
- properties.setProperty("isfloat",
- chkFloat.isChecked() ? "true" : "false");
- properties.setProperty("sender", sender);
- Log.d(LOG_TAG, "sender=" + sender);
- try {
- // FIXME 注释
- properties.setProperty(
- "password",
- curPassword.equals(prePassword) ? curPassword
- : ("".equals(curPassword) ? ""
- : des.encrypt(curPassword)));
- Log.d(LOG_TAG, "curPassword=" + curPassword);
- Log.d(LOG_TAG,
- "encrtpt=" + des.encrypt(curPassword));
- } catch (Exception e) {
- properties.setProperty("password", "");
- }
- properties.setProperty("recipients", recipients);
- properties.setProperty("smtp", smtp);
- FileOutputStream fos = new FileOutputStream(
- settingTempFile);
- properties.store(fos, "Setting Data");
- fos.close();
- Toast.makeText(SettingsActivity.this, "保存成功",
- Toast.LENGTH_LONG).show();
- Intent intent = new Intent();
- setResult(Activity.RESULT_FIRST_USER, intent);
- SettingsActivity.this.finish();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ }
+ });
+
+ layGoBack.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ SettingsActivity.this.finish();
+ Intent intent = new Intent();
+ intent.setClass(SettingsActivity.this, MainPageActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ mailSettings.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ Intent intent = new Intent();
+ intent.setClass(SettingsActivity.this, MailSettingsActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ about.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ Intent intent = new Intent();
+ intent.setClass(SettingsActivity.this, AboutActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ floatingItem.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ try {
+ chkFloat.setChecked(!chkFloat.isChecked());
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(settingTempFile));
+ properties.setProperty("isfloat", chkFloat.isChecked() ? "true" : "false");
+ FileOutputStream fos = new FileOutputStream(settingTempFile);
+ properties.store(fos, "Setting Data");
+ fos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ chkFloat.setChecked(chkFloat.isChecked() ? false : true);
}
}
});
@@ -198,29 +180,6 @@ protected void onDestroy() {
super.onDestroy();
}
- private int checkMailConfig(String sender, String recipients, String smtp,
- String curPassword) {
- if (!"".equals(curPassword) && !"".equals(sender)
- && !"".equals(recipients) && !"".equals(smtp)) {
- return 1;
- } else if ("".equals(curPassword) && "".equals(sender)
- && "".equals(recipients) && "".equals(smtp)) {
- return 0;
- } else
- return -1;
- }
-
- /**
- * 检查邮件格式正确性
- */
- private boolean checkMailFormat(String mail) {
- String strPattern = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*"
- + "[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
- Pattern p = Pattern.compile(strPattern);
- Matcher m = p.matcher(mail);
- return m.matches();
- }
-
/**
* is input a number.
*
diff --git a/src/com/netease/qa/emmagee/service/EmmageeService.java b/src/com/netease/qa/emmagee/service/EmmageeService.java
index d6f45c3..1285c4b 100644
--- a/src/com/netease/qa/emmagee/service/EmmageeService.java
+++ b/src/com/netease/qa/emmagee/service/EmmageeService.java
@@ -123,10 +123,11 @@ public class EmmageeService extends Service {
private int getStartTimeCount = 0;
private boolean isGetStartTime = true;
private String startTime = "";
+ private static final String SERVICE_ACTION = "com.netease.action.emmageeService";
@Override
public void onCreate() {
- Log.i(LOG_TAG, "onCreate");
+ Log.i(LOG_TAG, "service onCreate");
super.onCreate();
isServiceStop = false;
isStop = false;
@@ -155,7 +156,7 @@ public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
- totalBatt = String.valueOf(level * 100 / scale) + "%";
+ totalBatt = String.valueOf(level * 100 / scale);
voltage = String.valueOf(intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1) * 1.0 / 1000);
@@ -168,7 +169,7 @@ public void onReceive(Context context, Intent intent) {
@Override
public void onStart(Intent intent, int startId) {
- Log.i(LOG_TAG, "onStart");
+ Log.i(LOG_TAG, "service onStart");
PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, new Intent(this, MainPageActivity.class), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon).setWhen(System.currentTimeMillis()).setAutoCancel(true)
@@ -194,11 +195,11 @@ public void onStart(Intent intent, int startId) {
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
- btnWifi.setText(R.string.closewifi);
+ btnWifi.setText(R.string.close_wifi);
} else {
- btnWifi.setText(R.string.openwifi);
+ btnWifi.setText(R.string.open_wifi);
}
- txtUnusedMem.setText("计算中,请稍后...");
+ txtUnusedMem.setText(getString(R.string.calculating));
txtUnusedMem.setTextColor(android.graphics.Color.RED);
txtTotalMem.setTextColor(android.graphics.Color.RED);
txtTraffic.setTextColor(android.graphics.Color.RED);
@@ -208,10 +209,8 @@ public void onStart(Intent intent, int startId) {
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("isServiceStop", true);
- intent.setAction("com.netease.action.emmageeService");
+ intent.setAction(SERVICE_ACTION);
sendBroadcast(intent);
- // isServiceStop = true;
- Toast.makeText(EmmageeService.this, "测试结果文件:" + resultFilePath, Toast.LENGTH_LONG).show();
stopSelf();
}
});
@@ -230,13 +229,12 @@ private void readSettingInfo(Intent intent) {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(settingTempFile));
- String interval = properties.getProperty("interval").trim();
- isFloating = "true".equals(properties.getProperty("isfloat").trim()) ? true : false;
- sender = properties.getProperty("sender").trim();
- password = properties.getProperty("password").trim();
- recipients = properties.getProperty("recipients").trim();
+ String interval = (null == properties.getProperty("interval")) ? "" : properties.getProperty("interval").trim();
+ isFloating = "true".equals((null == properties.getProperty("isfloat")) ? "" : properties.getProperty("isfloat").trim()) ? true : false;
+ sender = (null == properties.getProperty("sender")) ? "" : properties.getProperty("sender").trim();
+ password = (null == properties.getProperty("password")) ? "" : properties.getProperty("password").trim();
+ recipients = (null == properties.getProperty("recipients")) ? "" : properties.getProperty("recipients").trim();
time = "".equals(interval) ? "5" : interval;
- recipients = properties.getProperty("recipients");
receivers = recipients.split("\\s+");
smtp = properties.getProperty("smtp");
} catch (IOException e) {
@@ -257,9 +255,12 @@ private void createResultCsv() {
mDateTime = formatter.format(cal.getTime().getTime() + 8 * 60 * 60 * 1000);
else
mDateTime = formatter.format(cal.getTime().getTime());
-
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
- resultFilePath = android.os.Environment.getExternalStorageDirectory() + File.separator + "Emmagee_TestResult_" + mDateTime + ".csv";
+ // 在4.0以下的低版本上/sdcard连接至/mnt/sdcard,而4.0以上版本则连接至/storage/sdcard0,所以有外接sdcard,/sdcard路径一定存在
+ resultFilePath = "/sdcard" + File.separator + "Emmagee_TestResult_" + mDateTime + ".csv";
+ // resultFilePath =
+ // android.os.Environment.getExternalStorageDirectory() +
+ // File.separator + "Emmagee_TestResult_" + mDateTime + ".csv";
} else {
resultFilePath = getBaseContext().getFilesDir().getPath() + File.separator + "Emmagee_TestResult_" + mDateTime + ".csv";
}
@@ -271,11 +272,22 @@ 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:," + uid + "\r\n" + START_TIME);
- bw.write("时间" + "," + "应用占用内存PSS(MB)" + "," + "应用占用内存比(%)" + "," + " 机器剩余内存(MB)" + "," + "应用占用CPU率(%)" + "," + "CPU总使用率(%)" + ","
- + "流量(KB)" + "," + "电量(%)" + "," + "电流(mA)" + "," + "温度(C)" + "," + "电压(V)" + "\r\n");
+ String multiCpuTitle = "";
+ // titles of multiple cpu cores
+ ArrayList cpuList = cpuInfo.getCpuList();
+ for (int i = 0; i < cpuList.size(); i++) {
+ multiCpuTitle += "," + cpuList.get(i) + getString(R.string.total_usage);
+ }
+ bw.write(getString(R.string.process_package) + ": ," + packageName + "\r\n" + getString(R.string.process_name) + ": ," + processName
+ + "\r\n" + getString(R.string.process_pid) + ": ," + pid + "\r\n" + getString(R.string.mem_size) + ": ," + totalMemory + "MB\r\n"
+ + getString(R.string.cpu_type) + ": ," + cpuInfo.getCpuName() + "\r\n" + getString(R.string.android_system_version) + ": ,"
+ + memoryInfo.getSDKVersion() + "\r\n" + getString(R.string.mobile_type) + ": ," + memoryInfo.getPhoneType() + "\r\n" + "UID"
+ + ": ," + uid + "\r\n" + START_TIME);
+ bw.write(getString(R.string.timestamp) + "," + getString(R.string.used_mem_PSS) + "," + getString(R.string.used_mem_ratio) + ","
+ + getString(R.string.mobile_free_mem) + "," + getString(R.string.app_used_cpu_ratio) + ","
+ + getString(R.string.total_used_cpu_ratio) + multiCpuTitle + "," + getString(R.string.traffic) + ","
+ + getString(R.string.battery) + "," + getString(R.string.current) + "," + getString(R.string.temperature) + ","
+ + getString(R.string.voltage) + "\r\n");
} catch (IOException e) {
Log.e(LOG_TAG, e.getMessage());
}
@@ -310,12 +322,10 @@ public boolean onTouch(View v, MotionEvent event) {
startY = y;
mTouchStartX = event.getX();
mTouchStartY = event.getY();
- Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY);
break;
case MotionEvent.ACTION_MOVE:
updateViewPosition();
break;
-
case MotionEvent.ACTION_UP:
updateViewPosition();
// showImg();
@@ -332,34 +342,22 @@ 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.open_wifi);
if (buttonText.equals(wifiText)) {
wifiManager.setWifiEnabled(true);
- btnWifi.setText(R.string.closewifi);
+ btnWifi.setText(R.string.close_wifi);
} else {
wifiManager.setWifiEnabled(false);
- btnWifi.setText(R.string.openwifi);
+ btnWifi.setText(R.string.open_wifi);
}
} catch (Exception e) {
- Toast.makeText(viFloatingWindow.getContext(), "操作wifi失败", Toast.LENGTH_LONG).show();
+ Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast), Toast.LENGTH_LONG).show();
Log.e(LOG_TAG, e.toString());
}
}
});
}
- // /**
- // * show the image.
- // */
- // private void showImg() {
- // if (Math.abs(x - startX) < 1.5 && Math.abs(y - startY) < 1.5 &&
- // !btnStop.isShown()) {
- // btnStop.setVisibility(View.VISIBLE);
- // } else if (btnStop.isShown()) {
- // btnStop.setVisibility(View.GONE);
- // }
- // }
-
private Runnable task = new Runnable() {
public void run() {
@@ -374,7 +372,7 @@ public void run() {
} else {
Intent intent = new Intent();
intent.putExtra("isServiceStop", true);
- intent.setAction("com.netease.action.emmageeService");
+ intent.setAction(SERVICE_ACTION);
sendBroadcast(intent);
stopSelf();
}
@@ -400,21 +398,18 @@ private void getStartTimeFromLogcat() {
strBuilder.append(line);
strBuilder.append("\r\n");
String regex = ".*Displayed.*" + startActivity + ".*\\+(.*)ms.*";
- Log.d("my logs", regex);
if (line.matches(regex)) {
Log.w("my logs", line);
if (line.contains("total")) {
line = line.substring(0, line.indexOf("total"));
}
startTime = line.substring(line.lastIndexOf("+") + 1, line.lastIndexOf("ms") + 2);
- Toast.makeText(EmmageeService.this, "启动时间:" + startTime, Toast.LENGTH_LONG).show();
+ Toast.makeText(EmmageeService.this, getString(R.string.start_time) + startTime, Toast.LENGTH_LONG).show();
isGetStartTime = false;
break;
}
}
getStartTimeCount++;
- // Log.w("my logs", "Start Time Log:" + strBuilder.toString());
- Log.w(LOG_TAG, "getStartCount:" + getStartTimeCount);
} catch (IOException e) {
Log.d(LOG_TAG, e.getMessage());
}
@@ -434,21 +429,17 @@ private void dataRefresh() {
String processMemory = fomart.format((double) pidMemory / 1024);
String currentBatt = String.valueOf(currentInfo.getCurrentValue());
// 异常数据过滤
- Log.d("my logs-before", currentBatt);
try {
if (Math.abs(Double.parseDouble(currentBatt)) >= 500) {
currentBatt = "N/A";
- } else {
- currentBatt = currentBatt + "mA";
}
} catch (Exception e) {
currentBatt = "N/A";
}
- Log.d("my logs-after", currentBatt);
ArrayList processInfo = cpuInfo.getCpuRatioInfo(totalBatt, currentBatt, temperature, voltage);
if (isFloating) {
- String processCpuRatio = "0";
- String totalCpuRatio = "0";
+ String processCpuRatio = "0.00";
+ String totalCpuRatio = "0.00";
String trafficSize = "0";
int tempTraffic = 0;
double trafficMb = 0;
@@ -466,18 +457,18 @@ private void dataRefresh() {
}
// 如果cpu使用率存在且都不小于0,则输出
if (processCpuRatio != null && totalCpuRatio != null) {
- txtUnusedMem.setText("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB");
- txtTotalMem.setText("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%");
- String batt = "电流:" + currentBatt;
+ txtUnusedMem.setText(getString(R.string.process_free_mem) + processMemory + "/" + freeMemoryKb + "MB");
+ txtTotalMem.setText(getString(R.string.process_overall_cpu) + processCpuRatio + "%/" + totalCpuRatio + "%");
+ String batt = getString(R.string.current) + currentBatt;
if ("-1".equals(trafficSize)) {
- txtTraffic.setText(batt + ",流量:N/A");
+ txtTraffic.setText(batt + "," + getString(R.string.traffic) + "N/A");
} else if (isMb)
- txtTraffic.setText(batt + ",流量:" + fomart.format(trafficMb) + "MB");
+ txtTraffic.setText(batt + "," + getString(R.string.traffic) + fomart.format(trafficMb) + "MB");
else
- txtTraffic.setText(batt + ",流量:" + trafficSize + "KB");
+ txtTraffic.setText(batt + "," + getString(R.string.traffic) + trafficSize + "KB");
}
// 当内存为0切cpu使用率为0时则是被测应用退出
- if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
+ if ("0".equals(processMemory)) {
closeOpenedStream();
isServiceStop = true;
return;
@@ -499,12 +490,11 @@ private void updateViewPosition() {
/**
* close all opened stream.
*/
- public static void closeOpenedStream() {
+ public void closeOpenedStream() {
try {
if (bw != null) {
- bw.write("注释:已知部分不支持的机型可在此查阅:https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported \r\n");
- bw.write("电流:小于0是放电大于0是充电\r\n启动时间:为空是应用已启动或者未搜集到启动时间\r\n");
- bw.write("N/A表示不支持或者数据异常\r\n");
+ 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.close();
}
if (osw != null)
@@ -518,14 +508,14 @@ public static void closeOpenedStream() {
@Override
public void onDestroy() {
- Log.i(LOG_TAG, "onDestroy");
+ Log.i(LOG_TAG, "service onDestroy");
if (windowManager != null)
windowManager.removeView(viFloatingWindow);
handler.removeCallbacks(task);
closeOpenedStream();
// replace the start time in file
if (!"".equals(startTime)) {
- replaceFileString(resultFilePath, START_TIME, "启动时间:" + startTime + "\r\n");
+ replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n");
} else {
replaceFileString(resultFilePath, START_TIME, "");
}
@@ -539,9 +529,9 @@ public void onDestroy() {
isSendSuccessfully = false;
}
if (isSendSuccessfully) {
- Toast.makeText(this, "测试结果报表已发送至邮箱:" + recipients, Toast.LENGTH_LONG).show();
+ Toast.makeText(this, getString(R.string.send_success_toast) + recipients, Toast.LENGTH_LONG).show();
} else {
- Toast.makeText(this, "测试结果未成功发送至邮箱,结果保存在:" + EmmageeService.resultFilePath, Toast.LENGTH_LONG).show();
+ Toast.makeText(this, getString(R.string.send_fail_toast) + EmmageeService.resultFilePath, Toast.LENGTH_LONG).show();
}
super.onDestroy();
stopForeground(true);
diff --git a/src/com/netease/qa/emmagee/utils/CpuInfo.java b/src/com/netease/qa/emmagee/utils/CpuInfo.java
index 4537d44..3b30a95 100644
--- a/src/com/netease/qa/emmagee/utils/CpuInfo.java
+++ b/src/com/netease/qa/emmagee/utils/CpuInfo.java
@@ -16,6 +16,8 @@
*/
package com.netease.qa.emmagee.utils;
+import java.io.File;
+import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -23,6 +25,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.regex.Pattern;
import com.netease.qa.emmagee.service.EmmageeService;
@@ -30,6 +33,8 @@
import android.os.Build;
import android.util.Log;
+import com.netease.qa.emmagee.R;
+
/**
* operate CPU information
*
@@ -41,8 +46,8 @@ public class CpuInfo {
private Context context;
private long processCpu;
- private long idleCpu;
- private long totalCpu;
+ private ArrayList idleCpu = new ArrayList();
+ private ArrayList totalCpu = new ArrayList();
private boolean isInitialStatics = true;
private SimpleDateFormat formatterFile;
private MemoryInfo mi;
@@ -51,14 +56,20 @@ public class CpuInfo {
private long lastestTraffic;
private long traffic;
private TrafficInfo trafficInfo;
- private ArrayList cpuUsedRatio;
- private long totalCpu2;
+ private ArrayList cpuUsedRatio = new ArrayList();
+ private ArrayList totalCpu2 = new ArrayList();
private long processCpu2;
- private long idleCpu2;
+ private ArrayList idleCpu2 = new ArrayList();
private String processCpuRatio = "";
- private String totalCpuRatio = "";
+ private ArrayList totalCpuRatio = new ArrayList();
private int pid;
+ private static final String INTEL_CPU_NAME = "model name";
+ private static final String CPU_DIR_PATH = "/sys/devices/system/cpu/";
+ private static final String CPU_X86 = "x86";
+ private static final String CPU_INFO_PATH = "/proc/cpuinfo";
+ private static final String CPU_STAT = "/proc/stat";
+
public CpuInfo(Context context, int pid, String uid) {
this.pid = pid;
this.context = context;
@@ -95,14 +106,23 @@ public void readCpuStat() {
} catch (IOException e) {
e.printStackTrace();
}
+ readTotalCpuStat();
+ }
+ /**
+ * read stat of each CPU cores
+ */
+ private void readTotalCpuStat() {
try {
// monitor total and idle cpu stat of certain process
- RandomAccessFile cpuInfo = new RandomAccessFile("/proc/stat", "r");
- String[] toks = cpuInfo.readLine().split("\\s+");
- idleCpu = Long.parseLong(toks[4]);
- totalCpu = Long.parseLong(toks[1]) + Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
- + Long.parseLong(toks[6]) + Long.parseLong(toks[5]) + Long.parseLong(toks[7]);
+ RandomAccessFile cpuInfo = new RandomAccessFile(CPU_STAT, "r");
+ String line = "";
+ while ((null != (line = cpuInfo.readLine())) && line.startsWith("cpu")) {
+ String[] toks = line.split("\\s+");
+ idleCpu.add(Long.parseLong(toks[4]));
+ totalCpu.add(Long.parseLong(toks[1]) + Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
+ + Long.parseLong(toks[6]) + Long.parseLong(toks[5]) + Long.parseLong(toks[7]));
+ }
cpuInfo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
@@ -118,16 +138,85 @@ public void readCpuStat() {
*/
public String getCpuName() {
try {
- RandomAccessFile cpuStat = new RandomAccessFile("/proc/cpuinfo", "r");
- String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
- cpuStat.close();
- return cpu[1];
+ RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r");
+ // 需要判断是intel or arm
+ if (Build.CPU_ABI.equalsIgnoreCase(CPU_X86)) {
+ String line;
+ while (null != (line = cpuStat.readLine())) {
+ String[] values = line.split(":");
+ if (values[0].contains(INTEL_CPU_NAME)) {
+ cpuStat.close();
+ return values[1];
+ }
+ }
+ } else {
+ String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
+ cpuStat.close();
+ return cpu[1];
+ }
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
}
return "";
}
+ /**
+ * display directories naming with "cpu*"
+ *
+ * @author andrewleo
+ */
+ class CpuFilter implements FileFilter {
+ @Override
+ public boolean accept(File pathname) {
+ // Check if filename matchs "cpu[0-9]"
+ if (Pattern.matches("cpu[0-9]", pathname.getName())) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * get CPU core numbers
+ *
+ * @return cpu core numbers
+ */
+ public int getCpuNum() {
+ try {
+ // Get directory containing CPU info
+ File dir = new File(CPU_DIR_PATH);
+ // Filter to only list the devices we care about
+ File[] files = dir.listFiles(new CpuFilter());
+ return files.length;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return 1;
+ }
+ }
+
+ /**
+ * get CPU core list
+ *
+ * @return cpu core list
+ */
+ public ArrayList getCpuList() {
+ ArrayList cpuList = new ArrayList();
+ try {
+ // Get directory containing CPU info
+ File dir = new File(CPU_DIR_PATH);
+ // Filter to only list the devices we care about
+ File[] files = dir.listFiles(new CpuFilter());
+ for (int i = 0; i < files.length; i++) {
+ cpuList.add(files[i].getName());
+ }
+ return cpuList;
+ } catch (Exception e) {
+ e.printStackTrace();
+ cpuList.add("cpu0");
+ return cpuList;
+ }
+ }
+
/**
* reserve used ratio of process CPU and total CPU, meanwhile collect
* network traffic.
@@ -138,12 +227,15 @@ public String getCpuName() {
public ArrayList getCpuRatioInfo(String totalBatt, String currentBatt, String temperature, String voltage) {
DecimalFormat fomart = new DecimalFormat();
- // fomart.setGroupingUsed(false);
+ fomart.setGroupingUsed(false);
fomart.setMaximumFractionDigits(2);
fomart.setMinimumFractionDigits(2);
- readCpuStat();
cpuUsedRatio.clear();
+ idleCpu.clear();
+ totalCpu.clear();
+ totalCpuRatio.clear();
+ readCpuStat();
try {
String mDateTime2;
@@ -156,7 +248,6 @@ public ArrayList getCpuRatioInfo(String totalBatt, String currentBatt, S
voltage = "N/A";
} else
mDateTime2 = formatterFile.format(cal.getTime().getTime());
-
if (isInitialStatics) {
initialTraffic = trafficInfo.getTrafficInfo();
isInitialStatics = false;
@@ -166,31 +257,56 @@ public ArrayList getCpuRatioInfo(String totalBatt, String currentBatt, S
traffic = -1;
else
traffic = (lastestTraffic - initialTraffic + 1023) / 1024;
- processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu - totalCpu2))));
- totalCpuRatio = fomart.format(100 * ((double) ((totalCpu - idleCpu) - (totalCpu2 - idleCpu2)) / (double) (totalCpu - totalCpu2)));
+ StringBuffer totalCpuBuffer = new StringBuffer();
+ if (null != totalCpu2 && totalCpu2.size() > 0) {
+ processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0)))));
+ for (int i = 0; i < (totalCpu.size() > totalCpu2.size() ? totalCpu2.size() : totalCpu.size()); i++) {
+ String cpuRatio = "0.00";
+ if (totalCpu.get(i) - totalCpu2.get(i) > 0) {
+ cpuRatio = fomart
+ .format(100 * ((double) ((totalCpu.get(i) - idleCpu.get(i)) - (totalCpu2.get(i) - idleCpu2.get(i))) / (double) (totalCpu
+ .get(i) - totalCpu2.get(i))));
+ }
+ totalCpuRatio.add(cpuRatio);
+ totalCpuBuffer.append(cpuRatio + ",");
+ }
+ } else {
+ processCpuRatio = "0";
+ totalCpuRatio.add("0");
+ totalCpuBuffer.append("0,");
+ totalCpu2 = (ArrayList) totalCpu.clone();
+ processCpu2 = processCpu;
+ idleCpu2 = (ArrayList) idleCpu.clone();
+ }
+ // 多核cpu的值写入csv文件中
+ for (int i = 0; i < getCpuNum() - totalCpuRatio.size() + 1; i++) {
+ totalCpuBuffer.append("0.00,");
+ }
long pidMemory = mi.getPidMemorySize(pid, context);
String pMemory = fomart.format((double) pidMemory / 1024);
long freeMemory = mi.getFreeMemorySize(context);
String fMemory = fomart.format((double) freeMemory / 1024);
- String percent = "统计出错";
+ String percent = context.getString(R.string.stat_error);
if (totalMemorySize != 0) {
percent = fomart.format(((double) pidMemory / (double) totalMemorySize) * 100);
}
- if (isPositive(processCpuRatio) && isPositive(totalCpuRatio)) {
+ if (isPositive(processCpuRatio) && isPositive(totalCpuRatio.get(0))) {
// whether certain device supports traffic statics or not
if (traffic == -1) {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
- + totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
+ + totalCpuBuffer.toString() + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
+ + "\r\n");
} else {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
- + totalCpuRatio + "," + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
+ + totalCpuBuffer.toString() + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
+ + "\r\n");
}
- totalCpu2 = totalCpu;
+ totalCpu2 = (ArrayList) totalCpu.clone();
processCpu2 = processCpu;
- idleCpu2 = idleCpu;
+ idleCpu2 = (ArrayList) idleCpu.clone();
cpuUsedRatio.add(processCpuRatio);
- cpuUsedRatio.add(totalCpuRatio);
+ cpuUsedRatio.add(totalCpuRatio.get(0));
cpuUsedRatio.add(String.valueOf(traffic));
}
}