From 2ad075f9b759c9d97dc5d3fd1490ae406978bf6a Mon Sep 17 00:00:00 2001 From: andrewleo Date: Thu, 9 Mar 2017 17:47:55 +0800 Subject: [PATCH] Added: write N/A in TopActivity column when sdk is higher than 21; android 7.0 toast --- README.md | 159 +++++++++--------- res/layout/navigation_bar.xml | 1 + res/values-zh-rCN/strings.xml | 1 + res/values/strings.xml | 1 + .../qa/emmagee/activity/AboutActivity.java | 6 +- .../activity/MailSettingsActivity.java | 10 +- .../qa/emmagee/activity/MainPageActivity.java | 77 +++++---- .../qa/emmagee/activity/SettingsActivity.java | 8 +- .../qa/emmagee/service/EmmageeService.java | 28 +-- src/com/netease/qa/emmagee/utils/CpuInfo.java | 3 +- .../utils/CustomizedAuthenticator.java | 3 +- .../netease/qa/emmagee/utils/EncryptData.java | 2 +- .../netease/qa/emmagee/utils/MemoryInfo.java | 1 - .../netease/qa/emmagee/utils/ProcessInfo.java | 3 + .../netease/qa/emmagee/utils/TrafficInfo.java | 4 - 15 files changed, 159 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index a88a782..6b1c200 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,82 @@ -##Emmagee - a practical, handy performance test tool for specified Android App - -Emmagee is a practical, handy performance test tool for specified Android App, which can monitor CPU, memory, -network traffic, battery current and status([Some devices are not supported](https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported)), new features such as top activity and heap size if rooted([Root Toast may continously show](https://github.com/NetEase/Emmagee/wiki/FAQ)), are also supported in the [latest version](https://github.com/NetEase/Emmagee/releases). 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. - - * Homepage: https://github.com/NetEase/Emmagee - * Wiki: https://github.com/NetEase/Emmagee/wiki - * Issues: https://github.com/NetEase/Emmagee/issues - * FAQ: https://github.com/NetEase/Emmagee/wiki/FAQ - * Tags: Android, Java - - -  - -  - - -## Why should I use Emmagee? - -Unlike most other performance test tools that only do system-level monitoring, Emmagee provides the ability to monitor any single App. Other advantages that -you should not miss: -* Open source -* Easy to use -* Process-specific monitoring, including CPU, memory, network traffic, battery current, launching time and status -* Floating window that renders real-time process status -* CSV format report that can be converted into any other format you want -* User-defined collecting interval -* Fully support Android 2.2 and above - -## How to use Emmagee? - -First of all ,you should have Emmagee.apk,download [here](https://github.com/NetEase/Emmagee/releases) or -build the apk file youself [here](https://github.com/NetEase/Emmagee/wiki/How-to-build-emmage.apk%3F),then : - -1. Start Emmagee App -2. Configure interval -3. Select a target process -4. Click Start button - -And Enjoy! - -If you want to stop the test, just go back to Emmagee and click Stop button. - -## Coming Soon -* We want you to decide! - -## How to Contribute? - -You are welcome to contribute to Emmagee, meanwhile you'd better follow the rules below - -* It's *NOT* recommended to submit a pull request directly to Emmagee's `master` branch. `develop` branch is more appropriate -* Follow common Java coding conventions -* Put all Java class files under *com.netease* package -* Add the following [license](#license) in each Java class file - -## Contributors -* NetEase, Inc. -* [yrom](https://github.com/yrom) -* [LukeOwncloud](https://github.com/LukeOwncloud) - -## License -(The Apache License) - -Copyright (c) 2012-2015 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. +## Emmagee - a practical, handy performance test tool for specified Android App + +Emmagee is a practical, handy performance test tool for specified Android App, which can monitor CPU, memory, +network traffic, battery current and status([Some devices are not supported](https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported)), new features such as top activity and heap size if rooted([Root Toast may continously show](https://github.com/NetEase/Emmagee/wiki/FAQ)), are also supported in the [latest version](https://github.com/NetEase/Emmagee/releases). 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. + + * Homepage: https://github.com/NetEase/Emmagee + * Wiki: https://github.com/NetEase/Emmagee/wiki + * Issues: https://github.com/NetEase/Emmagee/issues + * FAQ: https://github.com/NetEase/Emmagee/wiki/FAQ + * Tags: Android, Java + + +  + +  + + +## Why should I use Emmagee? + +Unlike most other performance test tools that only do system-level monitoring, Emmagee provides the ability to monitor any single App. Other advantages that +you should not miss: +* Open source +* Easy to use +* Process-specific monitoring, including CPU, memory, network traffic, battery current, launching time and status +* Floating window that renders real-time process status +* CSV format report that can be converted into any other format you want +* User-defined collecting interval +* Fully support Android 2.2 and above + +## How to use Emmagee? + +First of all ,you should have Emmagee.apk,download [here](https://github.com/NetEase/Emmagee/releases) or +build the apk file youself [here](https://github.com/NetEase/Emmagee/wiki/How-to-build-emmage.apk%3F),then : + +1. Start Emmagee App +2. Configure interval +3. Select a target process +4. Click Start button + +And Enjoy! + +If you want to stop the test, just go back to Emmagee and click Stop button. + +## Android 5.0 and above + +* `Android 5.0 and above`: getRunningTasks() and getRunningAppProcesses() are deprecated and only return your application process, so it is unable to get TopActivity from Android 5.0. +* `Android 7.0`: Google has restricted access to /proc, and also can not get pid of target application from TOP command in Android 7.0, I am so sorry to tell that 7.0 can not be supported. + +## Coming Soon +* We want you to decide! + +## How to Contribute? + +You are welcome to contribute to Emmagee, meanwhile you'd better follow the rules below + +* It's *NOT* recommended to submit a pull request directly to Emmagee's `master` branch. `develop` branch is more appropriate +* Follow common Java coding conventions +* Put all Java class files under *com.netease* package +* Add the following [license](#license) in each Java class file + +## Contributors +* NetEase, Inc. +* [yrom](https://github.com/yrom) +* [LukeOwncloud](https://github.com/LukeOwncloud) + +## License +(The Apache License) + +Copyright (c) 2012-2015 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. diff --git a/res/layout/navigation_bar.xml b/res/layout/navigation_bar.xml index 81c5c50..5762d94 100644 --- a/res/layout/navigation_bar.xml +++ b/res/layout/navigation_bar.xml @@ -30,6 +30,7 @@ android:singleLine="true" android:text="@string/setting" android:textColor="@color/white" + android:textStyle="bold" android:textSize="@dimen/text_size_big" /> 应用退出后停止监听 列表更新成功 + 由于Google的限制,Emmagee无法支持7.0及以上版本 diff --git a/res/values/strings.xml b/res/values/strings.xml index 463ac1b..183414f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -87,4 +87,5 @@ Stop monitoring when app exited Update List Successfully + Don\'t support 7.0 and above while Google has restricted access to shell commands and file system diff --git a/src/com/netease/qa/emmagee/activity/AboutActivity.java b/src/com/netease/qa/emmagee/activity/AboutActivity.java index 14b34ec..552ec8f 100644 --- a/src/com/netease/qa/emmagee/activity/AboutActivity.java +++ b/src/com/netease/qa/emmagee/activity/AboutActivity.java @@ -16,20 +16,20 @@ */ package com.netease.qa.emmagee.activity; +import com.netease.qa.emmagee.R; + import android.app.Activity; 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.view.Window; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.netease.qa.emmagee.R; - /** * About Page of Emmagee * diff --git a/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java index 245bd15..ddd2a8e 100644 --- a/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java +++ b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java @@ -19,6 +19,10 @@ package com.netease.qa.emmagee.activity; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.netease.qa.emmagee.R; +import com.netease.qa.emmagee.utils.EncryptData; +import com.netease.qa.emmagee.utils.Settings; + import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -27,17 +31,13 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; import android.view.View; -import android.view.Window; import android.view.View.OnClickListener; +import android.view.Window; import android.widget.EditText; 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; -import com.netease.qa.emmagee.utils.Settings; - /** * Mail Setting Page of Emmagee * diff --git a/src/com/netease/qa/emmagee/activity/MainPageActivity.java b/src/com/netease/qa/emmagee/activity/MainPageActivity.java index a64f948..fdf8a9d 100644 --- a/src/com/netease/qa/emmagee/activity/MainPageActivity.java +++ b/src/com/netease/qa/emmagee/activity/MainPageActivity.java @@ -29,6 +29,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; @@ -86,46 +87,50 @@ public class MainPageActivity extends Activity { btnTest.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - monitorService = new Intent(); - monitorService.setClass(MainPageActivity.this, EmmageeService.class); - if (getString(R.string.start_test).equals(btnTest.getText().toString())) { - ListAdapter adapter = (ListAdapter) lstViProgramme.getAdapter(); - if (adapter.checkedProg != null) { - String packageName = adapter.checkedProg.getPackageName(); - String processName = adapter.checkedProg.getProcessName(); - 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()); + if (Build.VERSION.SDK_INT < 24) { + monitorService = new Intent(); + monitorService.setClass(MainPageActivity.this, EmmageeService.class); + if (getString(R.string.start_test).equals(btnTest.getText().toString())) { + ListAdapter adapter = (ListAdapter) lstViProgramme.getAdapter(); + if (adapter.checkedProg != null) { + String packageName = adapter.checkedProg.getPackageName(); + String processName = adapter.checkedProg.getProcessName(); + 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()); + } + try { + startActivity = intent.resolveActivity(getPackageManager()).getShortClassName(); + startActivity(intent); + } catch (Exception e) { + Toast.makeText(MainPageActivity.this, getString(R.string.can_not_start_app_toast), Toast.LENGTH_LONG).show(); + return; + } + waitForAppStart(packageName); + monitorService.putExtra("processName", processName); + monitorService.putExtra("pid", pid); + monitorService.putExtra("uid", uid); + monitorService.putExtra("packageName", packageName); + monitorService.putExtra("startActivity", startActivity); + startService(monitorService); + isServiceStop = false; + btnTest.setText(getString(R.string.stop_test)); + } else { + Toast.makeText(MainPageActivity.this, getString(R.string.choose_app_toast), Toast.LENGTH_LONG).show(); } - try { - startActivity = intent.resolveActivity(getPackageManager()).getShortClassName(); - startActivity(intent); - } catch (Exception e) { - Toast.makeText(MainPageActivity.this, getString(R.string.can_not_start_app_toast), Toast.LENGTH_LONG).show(); - return; - } - waitForAppStart(packageName); - monitorService.putExtra("processName", processName); - monitorService.putExtra("pid", pid); - monitorService.putExtra("uid", uid); - monitorService.putExtra("packageName", packageName); - monitorService.putExtra("startActivity", startActivity); - startService(monitorService); - isServiceStop = false; - btnTest.setText(getString(R.string.stop_test)); } else { - Toast.makeText(MainPageActivity.this, getString(R.string.choose_app_toast), 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); } } else { - 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); + Toast.makeText(MainPageActivity.this, getString(R.string.nougat_warning),Toast.LENGTH_LONG).show(); } } }); diff --git a/src/com/netease/qa/emmagee/activity/SettingsActivity.java b/src/com/netease/qa/emmagee/activity/SettingsActivity.java index f51535a..59163ed 100644 --- a/src/com/netease/qa/emmagee/activity/SettingsActivity.java +++ b/src/com/netease/qa/emmagee/activity/SettingsActivity.java @@ -18,14 +18,17 @@ package com.netease.qa.emmagee.activity; import java.io.DataOutputStream; +import com.netease.qa.emmagee.R; +import com.netease.qa.emmagee.utils.Settings; + import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.View; -import android.view.Window; import android.view.View.OnClickListener; +import android.view.Window; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; @@ -35,9 +38,6 @@ import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import android.widget.Toast; -import com.netease.qa.emmagee.R; -import com.netease.qa.emmagee.utils.Settings; - /** * Setting Page of Emmagee * diff --git a/src/com/netease/qa/emmagee/service/EmmageeService.java b/src/com/netease/qa/emmagee/service/EmmageeService.java index 0204cc4..9c19b54 100644 --- a/src/com/netease/qa/emmagee/service/EmmageeService.java +++ b/src/com/netease/qa/emmagee/service/EmmageeService.java @@ -32,6 +32,20 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Locale; +import com.netease.qa.emmagee.R; +import com.netease.qa.emmagee.activity.MainPageActivity; +import com.netease.qa.emmagee.utils.Constants; +import com.netease.qa.emmagee.utils.CpuInfo; +import com.netease.qa.emmagee.utils.CurrentInfo; +import com.netease.qa.emmagee.utils.EncryptData; +import com.netease.qa.emmagee.utils.FpsInfo; +import com.netease.qa.emmagee.utils.MailSender; +import com.netease.qa.emmagee.utils.MemoryInfo; +import com.netease.qa.emmagee.utils.MyApplication; +import com.netease.qa.emmagee.utils.ProcessInfo; +import com.netease.qa.emmagee.utils.Programe; +import com.netease.qa.emmagee.utils.Settings; + import android.app.Activity; import android.app.PendingIntent; import android.app.Service; @@ -60,20 +74,6 @@ import android.widget.Button; import android.widget.TextView; import android.widget.Toast; -import com.netease.qa.emmagee.R; -import com.netease.qa.emmagee.activity.MainPageActivity; -import com.netease.qa.emmagee.utils.Constants; -import com.netease.qa.emmagee.utils.CpuInfo; -import com.netease.qa.emmagee.utils.CurrentInfo; -import com.netease.qa.emmagee.utils.EncryptData; -import com.netease.qa.emmagee.utils.FpsInfo; -import com.netease.qa.emmagee.utils.MailSender; -import com.netease.qa.emmagee.utils.MemoryInfo; -import com.netease.qa.emmagee.utils.MyApplication; -import com.netease.qa.emmagee.utils.ProcessInfo; -import com.netease.qa.emmagee.utils.Programe; -import com.netease.qa.emmagee.utils.Settings; - /** * Service running in background * diff --git a/src/com/netease/qa/emmagee/utils/CpuInfo.java b/src/com/netease/qa/emmagee/utils/CpuInfo.java index c7f7f21..cd28587 100644 --- a/src/com/netease/qa/emmagee/utils/CpuInfo.java +++ b/src/com/netease/qa/emmagee/utils/CpuInfo.java @@ -29,14 +29,13 @@ import java.util.Calendar; import java.util.Locale; import java.util.regex.Pattern; +import com.netease.qa.emmagee.R; import com.netease.qa.emmagee.service.EmmageeService; import android.content.Context; import android.os.Build; import android.util.Log; -import com.netease.qa.emmagee.R; - /** * operate CPU information * diff --git a/src/com/netease/qa/emmagee/utils/CustomizedAuthenticator.java b/src/com/netease/qa/emmagee/utils/CustomizedAuthenticator.java index 2b6fe43..e2be858 100644 --- a/src/com/netease/qa/emmagee/utils/CustomizedAuthenticator.java +++ b/src/com/netease/qa/emmagee/utils/CustomizedAuthenticator.java @@ -1,6 +1,7 @@ package com.netease.qa.emmagee.utils; -import javax.mail.*; +import javax.mail.Authenticator; +import javax.mail.PasswordAuthentication; /** * Customized Authenticator diff --git a/src/com/netease/qa/emmagee/utils/EncryptData.java b/src/com/netease/qa/emmagee/utils/EncryptData.java index e305fdf..c595d18 100644 --- a/src/com/netease/qa/emmagee/utils/EncryptData.java +++ b/src/com/netease/qa/emmagee/utils/EncryptData.java @@ -1,6 +1,6 @@ package com.netease.qa.emmagee.utils; -import java.security.*; +import java.security.Key; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; diff --git a/src/com/netease/qa/emmagee/utils/MemoryInfo.java b/src/com/netease/qa/emmagee/utils/MemoryInfo.java index 24a1517..84be2a4 100644 --- a/src/com/netease/qa/emmagee/utils/MemoryInfo.java +++ b/src/com/netease/qa/emmagee/utils/MemoryInfo.java @@ -21,7 +21,6 @@ import java.io.DataOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; -import java.text.DecimalFormat; import android.app.ActivityManager; import android.content.Context; diff --git a/src/com/netease/qa/emmagee/utils/ProcessInfo.java b/src/com/netease/qa/emmagee/utils/ProcessInfo.java index 16f5a08..c6a26bc 100644 --- a/src/com/netease/qa/emmagee/utils/ProcessInfo.java +++ b/src/com/netease/qa/emmagee/utils/ProcessInfo.java @@ -210,6 +210,9 @@ public class ProcessInfo { ActivityManager manager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); // Note: getRunningTasks is deprecated in API 21(Official) +// if (Build.VERSION.SDK_INT >= 21) { +// return Constants.NA; +// } List runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return (runningTaskInfos.get(0).topActivity).toString(); diff --git a/src/com/netease/qa/emmagee/utils/TrafficInfo.java b/src/com/netease/qa/emmagee/utils/TrafficInfo.java index 4d597af..5e6a04f 100644 --- a/src/com/netease/qa/emmagee/utils/TrafficInfo.java +++ b/src/com/netease/qa/emmagee/utils/TrafficInfo.java @@ -16,10 +16,6 @@ */ package com.netease.qa.emmagee.utils; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; - import android.net.TrafficStats; import android.util.Log; -- GitLab