From 8e6089f1d9e443625d1871fc4eab2b9b7ee39cfb Mon Sep 17 00:00:00 2001 From: andrewleo Date: Thu, 16 Oct 2014 11:23:13 +0800 Subject: [PATCH] Misc: code review --- .../qa/emmagee/activity/AboutActivity.java | 3 - .../activity/MailSettingsActivity.java | 64 ++++++------- .../qa/emmagee/activity/MainPageActivity.java | 93 +++++++++---------- .../qa/emmagee/activity/SettingsActivity.java | 3 - .../qa/emmagee/service/EmmageeService.java | 68 +++++++------- src/com/netease/qa/emmagee/utils/CpuInfo.java | 26 +++--- .../netease/qa/emmagee/utils/CurrentInfo.java | 15 ++- .../netease/qa/emmagee/utils/MailSender.java | 33 +++---- .../netease/qa/emmagee/utils/MemoryInfo.java | 4 - .../netease/qa/emmagee/utils/ProcessInfo.java | 11 --- .../netease/qa/emmagee/utils/Settings.java | 29 +++--- 11 files changed, 165 insertions(+), 184 deletions(-) diff --git a/src/com/netease/qa/emmagee/activity/AboutActivity.java b/src/com/netease/qa/emmagee/activity/AboutActivity.java index 129f6b4..14b34ec 100644 --- a/src/com/netease/qa/emmagee/activity/AboutActivity.java +++ b/src/com/netease/qa/emmagee/activity/AboutActivity.java @@ -17,7 +17,6 @@ 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; @@ -42,7 +41,6 @@ public class AboutActivity extends Activity { + AboutActivity.class.getSimpleName(); private TextView appVersion; - private ImageView goBack; @Override public void onCreate(Bundle savedInstanceState) { @@ -60,7 +58,6 @@ public class AboutActivity extends Activity { 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() { diff --git a/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java index 284cab0..245bd15 100644 --- a/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java +++ b/src/com/netease/qa/emmagee/activity/MailSettingsActivity.java @@ -30,7 +30,6 @@ 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; @@ -46,8 +45,8 @@ import com.netease.qa.emmagee.utils.Settings; */ public class MailSettingsActivity extends Activity { - private static final String LOG_TAG = "Emmagee-" - + MailSettingsActivity.class.getSimpleName(); + private static final String LOG_TAG = "Emmagee-" + MailSettingsActivity.class.getSimpleName(); + private static final String BLANK_STRING = ""; private EditText edtRecipients; private EditText edtSender; @@ -72,17 +71,17 @@ public class MailSettingsActivity extends Activity { 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); + title = (TextView) findViewById(R.id.nb_title); LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back); LinearLayout layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set); - + title.setText(R.string.mail_settings); - + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - sender = preferences.getString(Settings.KEY_SENDER, ""); - prePassword = preferences.getString(Settings.KEY_PASSWORD, ""); - recipients = preferences.getString(Settings.KEY_RECIPIENTS, ""); - smtp = preferences.getString(Settings.KEY_SMTP, ""); + sender = preferences.getString(Settings.KEY_SENDER, BLANK_STRING); + prePassword = preferences.getString(Settings.KEY_PASSWORD, BLANK_STRING); + recipients = preferences.getString(Settings.KEY_RECIPIENTS, BLANK_STRING); + smtp = preferences.getString(Settings.KEY_SMTP, BLANK_STRING); edtRecipients.setText(recipients); edtSender.setText(sender); @@ -97,9 +96,9 @@ public class MailSettingsActivity extends Activity { }); layBtnSet.setOnClickListener(new OnClickListener() { @Override - public void onClick(View v) { + public void onClick(View v) { sender = edtSender.getText().toString().trim(); - if (!"".equals(sender) && !checkMailFormat(sender)) { + if (!BLANK_STRING.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; @@ -107,8 +106,7 @@ public class MailSettingsActivity extends Activity { recipients = edtRecipients.getText().toString().trim(); receivers = recipients.split("\\s+"); for (int i = 0; i < receivers.length; i++) { - if (!"".equals(receivers[i]) - && !checkMailFormat(receivers[i])) { + if (!BLANK_STRING.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(); @@ -118,24 +116,22 @@ public class MailSettingsActivity extends Activity { 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(); + Toast.makeText(MailSettingsActivity.this, getString(R.string.info_incomplete_toast), Toast.LENGTH_LONG).show(); return; } SharedPreferences preferences = Settings.getDefaultSharedPreferences(getApplicationContext()); Editor editor = preferences.edit(); editor.putString(Settings.KEY_SENDER, sender); - + try { - editor.putString(Settings.KEY_PASSWORD, curPassword.equals(prePassword) ? curPassword : des.encrypt(curPassword)); - } catch (Exception e) { - editor.putString(Settings.KEY_PASSWORD, curPassword); - } + editor.putString(Settings.KEY_PASSWORD, curPassword.equals(prePassword) ? curPassword : des.encrypt(curPassword)); + } catch (Exception e) { + editor.putString(Settings.KEY_PASSWORD, curPassword); + } editor.putString(Settings.KEY_RECIPIENTS, recipients); editor.putString(Settings.KEY_SMTP, smtp); editor.commit(); - Toast.makeText(MailSettingsActivity.this, getString(R.string.save_success_toast), - Toast.LENGTH_LONG).show(); + 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(); @@ -153,13 +149,20 @@ public class MailSettingsActivity extends Activity { super.onDestroy(); } - private int checkMailConfig(String sender, String recipients, String smtp, - String curPassword) { - if (!"".equals(curPassword) && !"".equals(sender) - && !"".equals(recipients) && !"".equals(smtp)) { + /** + * check if mail configurations are available + * + * @param sender + * @param recipients + * @param smtp + * @param curPassword + * @return true: valid configurations + * + */ + private int checkMailConfig(String sender, String recipients, String smtp, String curPassword) { + if (!BLANK_STRING.equals(curPassword) && !BLANK_STRING.equals(sender) && !BLANK_STRING.equals(recipients) && !BLANK_STRING.equals(smtp)) { return 1; - } else if ("".equals(curPassword) && "".equals(sender) - && "".equals(recipients) && "".equals(smtp)) { + } else if (BLANK_STRING.equals(curPassword) && BLANK_STRING.equals(sender) && BLANK_STRING.equals(recipients) && BLANK_STRING.equals(smtp)) { return 0; } else return -1; @@ -171,8 +174,7 @@ public class MailSettingsActivity extends Activity { * @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]$"; + 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 d0f836a..518818a 100644 --- a/src/com/netease/qa/emmagee/activity/MainPageActivity.java +++ b/src/com/netease/qa/emmagee/activity/MainPageActivity.java @@ -16,11 +16,8 @@ */ package com.netease.qa.emmagee.activity; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.List; -import java.util.Properties; import android.app.Activity; import android.content.BroadcastReceiver; @@ -82,10 +79,10 @@ public class MainPageActivity extends Activity { monitorService = new Intent(); monitorService.setClass(MainPageActivity.this, EmmageeService.class); if (getString(R.string.start_test).equals(btnTest.getText().toString())) { - ListAdapter adapter = (ListAdapter) lstViProgramme.getAdapter(); + ListAdapter adapter = (ListAdapter) lstViProgramme.getAdapter(); if (adapter.checkedProg != null) { - String packageName = adapter.checkedProg.getPackageName(); - String processName = adapter.checkedProg.getProcessName(); + String packageName = adapter.checkedProg.getPackageName(); + String processName = adapter.checkedProg.getProcessName(); Intent intent = getPackageManager().getLaunchIntentForPackage(packageName); String startActivity = ""; Log.d(LOG_TAG, packageName); @@ -141,9 +138,9 @@ public class MainPageActivity extends Activity { } }); receiver = new UpdateReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction("com.netease.action.emmageeService"); - registerReceiver(receiver, filter); + IntentFilter filter = new IntentFilter(); + filter.addAction(EmmageeService.SERVICE_ACTION); + registerReceiver(receiver, filter); } private void initTitleLayout() { @@ -186,7 +183,6 @@ public class MainPageActivity extends Activity { } } - /** * wait for test application started. * @@ -279,56 +275,53 @@ public class MainPageActivity extends Activity { @Override public View getView(int position, View convertView, ViewGroup parent) { Programe pr = (Programe) programes.get(position); - if(convertView == null) - convertView = getLayoutInflater().inflate(R.layout.list_item, parent, false); + if (convertView == null) + convertView = getLayoutInflater().inflate(R.layout.list_item, parent, false); Viewholder holder = (Viewholder) convertView.getTag(); - if(holder == null){ - holder = new Viewholder(); - convertView.setTag(holder); - holder.imgViAppIcon = (ImageView) convertView.findViewById(R.id.image); - holder.txtAppName = (TextView) convertView.findViewById(R.id.text); - holder.rdoBtnApp = (RadioButton) convertView.findViewById(R.id.rb); - holder.rdoBtnApp.setFocusable(false); - holder.rdoBtnApp.setOnCheckedChangeListener(checkedChangeListener); + if (holder == null) { + holder = new Viewholder(); + convertView.setTag(holder); + holder.imgViAppIcon = (ImageView) convertView.findViewById(R.id.image); + holder.txtAppName = (TextView) convertView.findViewById(R.id.text); + holder.rdoBtnApp = (RadioButton) convertView.findViewById(R.id.rb); + holder.rdoBtnApp.setFocusable(false); + holder.rdoBtnApp.setOnCheckedChangeListener(checkedChangeListener); } - holder.imgViAppIcon.setImageDrawable(pr.getIcon()); - holder.txtAppName.setText(pr.getProcessName()); - holder.rdoBtnApp.setId(position); - holder.rdoBtnApp.setChecked(checkedProg != null && getItem(position) == checkedProg); + holder.rdoBtnApp.setChecked(checkedProg != null && getItem(position) == checkedProg); return convertView; } - - + OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - final int checkedPosition = buttonView.getId(); - if (lastCheckedPosition != -1) { - RadioButton tempButton = (RadioButton) findViewById(lastCheckedPosition); - if ((tempButton != null) && (lastCheckedPosition != checkedPosition)) { - tempButton.setChecked(false); - } - } - checkedProg = programes.get(checkedPosition); - lastCheckedPosition = checkedPosition; - } - } - }; + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + final int checkedPosition = buttonView.getId(); + if (lastCheckedPosition != -1) { + RadioButton tempButton = (RadioButton) findViewById(lastCheckedPosition); + if ((tempButton != null) && (lastCheckedPosition != checkedPosition)) { + tempButton.setChecked(false); + } + } + checkedProg = programes.get(checkedPosition); + lastCheckedPosition = checkedPosition; + } + } + }; } + /** - * save status of all installed processes - * - * @author andrewleo - */ - static class Viewholder { - TextView txtAppName; - ImageView imgViAppIcon; - RadioButton rdoBtnApp; - } + * save status of all installed processes + * + * @author andrewleo + */ + static class Viewholder { + TextView txtAppName; + ImageView imgViAppIcon; + RadioButton rdoBtnApp; + } @Override protected void onDestroy() { diff --git a/src/com/netease/qa/emmagee/activity/SettingsActivity.java b/src/com/netease/qa/emmagee/activity/SettingsActivity.java index c5ddfd4..4d7bcb9 100644 --- a/src/com/netease/qa/emmagee/activity/SettingsActivity.java +++ b/src/com/netease/qa/emmagee/activity/SettingsActivity.java @@ -64,17 +64,14 @@ public class SettingsActivity extends Activity { 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); - btnSave.setVisibility(ImageView.INVISIBLE); preferences = Settings.getDefaultSharedPreferences(getApplicationContext()); int interval = preferences.getInt(Settings.KEY_INTERVAL, 5); boolean isfloat = preferences.getBoolean(Settings.KEY_ISFLOAT, true); - tvTime.setText(String.valueOf(interval)); chkFloat.setChecked(isfloat); timeBar.setProgress(interval); diff --git a/src/com/netease/qa/emmagee/service/EmmageeService.java b/src/com/netease/qa/emmagee/service/EmmageeService.java index 48d396c..745434f 100644 --- a/src/com/netease/qa/emmagee/service/EmmageeService.java +++ b/src/com/netease/qa/emmagee/service/EmmageeService.java @@ -76,13 +76,13 @@ public class EmmageeService extends Service { private final static String LOG_TAG = "Emmagee-" + EmmageeService.class.getSimpleName(); + private static final String BLANK_STRING = ""; + private WindowManager windowManager = null; private WindowManager.LayoutParams wmParams = null; private View viFloatingWindow; private float mTouchStartX; private float mTouchStartY; - private float startX; - private float startY; private float x; private float y; private TextView txtTotalMem; @@ -122,7 +122,7 @@ 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"; + public static final String SERVICE_ACTION = "com.netease.action.emmageeService"; @Override public void onCreate() { @@ -153,12 +153,9 @@ public class EmmageeService extends Service { if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); - int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); totalBatt = String.valueOf(level * 100 / scale); - voltage = String.valueOf(intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1) * 1.0 / 1000); - temperature = String.valueOf(intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1) * 1.0 / 10); } @@ -224,15 +221,15 @@ public class EmmageeService extends Service { * @throws IOException */ private void readSettingInfo() { - SharedPreferences preferences = Settings.getDefaultSharedPreferences(getApplicationContext()); - int interval = preferences.getInt(Settings.KEY_INTERVAL, 5); - delaytime = interval * 1000; - isFloating = preferences.getBoolean(Settings.KEY_ISFLOAT, true); - sender = preferences.getString(Settings.KEY_SENDER, ""); - password = preferences.getString(Settings.KEY_PASSWORD, ""); - recipients = preferences.getString(Settings.KEY_RECIPIENTS, ""); - receivers = recipients.split("\\s+"); - smtp = preferences.getString(Settings.KEY_SMTP, ""); + SharedPreferences preferences = Settings.getDefaultSharedPreferences(getApplicationContext()); + int interval = preferences.getInt(Settings.KEY_INTERVAL, 5); + delaytime = interval * 1000; + isFloating = preferences.getBoolean(Settings.KEY_ISFLOAT, true); + sender = preferences.getString(Settings.KEY_SENDER, BLANK_STRING); + password = preferences.getString(Settings.KEY_PASSWORD, BLANK_STRING); + recipients = preferences.getString(Settings.KEY_RECIPIENTS, BLANK_STRING); + receivers = recipients.split("\\s+"); + smtp = preferences.getString(Settings.KEY_SMTP, BLANK_STRING); } /** @@ -263,7 +260,7 @@ public class EmmageeService extends Service { bw = new BufferedWriter(osw); long totalMemorySize = memoryInfo.getTotalMemory(); String totalMemory = fomart.format((double) totalMemorySize / 1024); - String multiCpuTitle = ""; + String multiCpuTitle = BLANK_STRING; // titles of multiple cpu cores ArrayList cpuList = cpuInfo.getCpuList(); for (int i = 0; i < cpuList.size(); i++) { @@ -274,9 +271,9 @@ public class EmmageeService extends Service { + 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"); - - if(isGrantedReadLogsPermission()){ - bw.write(START_TIME); + + if (isGrantedReadLogsPermission()) { + bw.write(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) + "," @@ -313,8 +310,6 @@ public class EmmageeService extends Service { y = event.getRawY() - 25; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - startX = x; - startY = y; mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; @@ -387,7 +382,7 @@ public class EmmageeService extends Service { Process process = Runtime.getRuntime().exec(logcatCommand); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuilder strBuilder = new StringBuilder(); - String line = ""; + String line = BLANK_STRING; while ((line = bufferedReader.readLine()) != null) { strBuilder.append(line); @@ -409,14 +404,16 @@ public class EmmageeService extends Service { Log.d(LOG_TAG, e.getMessage()); } } + /** * Above JellyBean, we cannot grant READ_LOGS permission... + * * @return */ - private boolean isGrantedReadLogsPermission() { - int permissionState = getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, getPackageName()); - return permissionState == PackageManager.PERMISSION_GRANTED; - } + private boolean isGrantedReadLogsPermission() { + int permissionState = getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, getPackageName()); + return permissionState == PackageManager.PERMISSION_GRANTED; + } /** * refresh the performance data showing in floating window. @@ -451,7 +448,7 @@ public class EmmageeService extends Service { processCpuRatio = processInfo.get(0); totalCpuRatio = processInfo.get(1); trafficSize = processInfo.get(2); - if (!("".equals(trafficSize)) && !("-1".equals(trafficSize))) { + if (!(BLANK_STRING.equals(trafficSize)) && !("-1".equals(trafficSize))) { tempTraffic = Integer.parseInt(trafficSize); if (tempTraffic > 1024) { isMb = true; @@ -517,13 +514,13 @@ public class EmmageeService extends Service { handler.removeCallbacks(task); closeOpenedStream(); // replace the start time in file - if(isGrantedReadLogsPermission()){ - if (!"".equals(startTime)) { - replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n"); - } else { - replaceFileString(resultFilePath, START_TIME, ""); - } - } + if (isGrantedReadLogsPermission()) { + if (!BLANK_STRING.equals(startTime)) { + replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n"); + } else { + replaceFileString(resultFilePath, START_TIME, BLANK_STRING); + } + } isStop = true; unregisterReceiver(batteryBroadcast); boolean isSendSuccessfully = false; @@ -554,7 +551,8 @@ public class EmmageeService extends Service { try { File file = new File(filePath); BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = "", oldtext = ""; + String line = BLANK_STRING; + String oldtext = BLANK_STRING; while ((line = reader.readLine()) != null) { oldtext += line + "\r\n"; } diff --git a/src/com/netease/qa/emmagee/utils/CpuInfo.java b/src/com/netease/qa/emmagee/utils/CpuInfo.java index 3b30a95..8a1e89b 100644 --- a/src/com/netease/qa/emmagee/utils/CpuInfo.java +++ b/src/com/netease/qa/emmagee/utils/CpuInfo.java @@ -69,6 +69,8 @@ public class CpuInfo { private static final String CPU_X86 = "x86"; private static final String CPU_INFO_PATH = "/proc/cpuinfo"; private static final String CPU_STAT = "/proc/stat"; + private static final String NA = "N/A"; + private static final String COMMA = ","; public CpuInfo(Context context, int pid, String uid) { this.pid = pid; @@ -139,7 +141,7 @@ public class CpuInfo { public String getCpuName() { try { RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r"); - // 需要判断是intel or arm + // check cpu type if (Build.CPU_ABI.equalsIgnoreCase(CPU_X86)) { String line; while (null != (line = cpuStat.readLine())) { @@ -242,10 +244,10 @@ public class CpuInfo { Calendar cal = Calendar.getInstance(); if ((Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"))) { mDateTime2 = formatterFile.format(cal.getTime().getTime() + 8 * 60 * 60 * 1000); - totalBatt = "N/A"; - currentBatt = "N/A"; - temperature = "N/A"; - voltage = "N/A"; + totalBatt = NA; + currentBatt = NA; + temperature = NA; + voltage = NA; } else mDateTime2 = formatterFile.format(cal.getTime().getTime()); if (isInitialStatics) { @@ -268,7 +270,7 @@ public class CpuInfo { .get(i) - totalCpu2.get(i)))); } totalCpuRatio.add(cpuRatio); - totalCpuBuffer.append(cpuRatio + ","); + totalCpuBuffer.append(cpuRatio + COMMA); } } else { processCpuRatio = "0"; @@ -292,16 +294,16 @@ public class CpuInfo { } if (isPositive(processCpuRatio) && isPositive(totalCpuRatio.get(0))) { + String trafValue; // whether certain device supports traffic statics or not if (traffic == -1) { - EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + "," - + totalCpuBuffer.toString() + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage - + "\r\n"); + trafValue = NA; } else { - EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + "," - + totalCpuBuffer.toString() + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage - + "\r\n"); + trafValue = String.valueOf(traffic); } + EmmageeService.bw.write(mDateTime2 + COMMA + pMemory + COMMA + percent + COMMA + fMemory + COMMA + processCpuRatio + COMMA + + totalCpuBuffer.toString() + trafValue + COMMA + totalBatt + COMMA + currentBatt + COMMA + temperature + COMMA + voltage + + "\r\n"); totalCpu2 = (ArrayList) totalCpu.clone(); processCpu2 = processCpu; idleCpu2 = (ArrayList) idleCpu.clone(); diff --git a/src/com/netease/qa/emmagee/utils/CurrentInfo.java b/src/com/netease/qa/emmagee/utils/CurrentInfo.java index 51b9fff..712c979 100644 --- a/src/com/netease/qa/emmagee/utils/CurrentInfo.java +++ b/src/com/netease/qa/emmagee/utils/CurrentInfo.java @@ -26,6 +26,11 @@ public class CurrentInfo { private static final String BATT_CURRENT_ADC = "/sys/class/power_supply/battery/batt_current_adc"; private static final String CURRENT_AVG = "/sys/class/power_supply/battery/current_avg"; + /** + * read system file to get current value + * + * @return current value + */ public Long getCurrentValue() { File f = null; Log.d(LOG_TAG, BUILD_MODEL); @@ -88,9 +93,9 @@ public class CurrentInfo { } /** - * 从smem_text文件中读取电流数据 + * get current value from smem_text * - * @return + * @return current value */ public Long getSMemValue() { boolean success = false; @@ -125,11 +130,11 @@ public class CurrentInfo { } /** - * 获取当前的电流值 + * read system file to get current value * * @param file - * @param convertToMillis - * @return + * @param convertToMillis + * @return current value */ public Long getCurrentValue(File file, boolean convertToMillis) { Log.d(LOG_TAG, "*** getCurrentValue ***"); diff --git a/src/com/netease/qa/emmagee/utils/MailSender.java b/src/com/netease/qa/emmagee/utils/MailSender.java index ee27d08..04504db 100644 --- a/src/com/netease/qa/emmagee/utils/MailSender.java +++ b/src/com/netease/qa/emmagee/utils/MailSender.java @@ -34,13 +34,11 @@ public class MailSender { /** * 以文本格式发送邮件 * - * 待发送的邮件的信息 + * 待发送的邮件的信息 */ - public static boolean sendTextMail(String sender, String encryptPassword, - String smtp, String subject, String content, String file, + public static boolean sendTextMail(String sender, String encryptPassword, String smtp, String subject, String content, String file, String[] maillists) { - if (maillists == null || maillists.length == 0 - || ("".equals(maillists[0].trim()))) { + if (maillists == null || maillists.length == 0 || ("".equals(maillists[0].trim()))) { return false; } else { // Get system properties @@ -56,12 +54,10 @@ public class MailSender { CustomizedAuthenticator authenticator = null; if (true) { // 如果需要身份认证,则创建一个密码验证器 - authenticator = new CustomizedAuthenticator(sender, - encryptPassword); + authenticator = new CustomizedAuthenticator(sender, encryptPassword); } // 根据邮件会话属性和密码验证器构造一个发送邮件的session - Session sendMailSession = Session.getInstance(props, - authenticator); + Session sendMailSession = Session.getInstance(props, authenticator); try { // 根据session创建一个邮件消息 Message mailMessage = new MimeMessage(sendMailSession); @@ -71,7 +67,7 @@ public class MailSender { mailMessage.setFrom(from); // 创建邮件的接收者地址,并设置到邮件消息中 for (int i = 0; i < maillists.length; i++) { - // Message.RecipientType.TO属性表示接收者的类型为TO + // Message.RecipientType.TO属性表示接收者的类型为TO mailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(maillists[i])); } @@ -86,17 +82,16 @@ public class MailSender { multipart.addBodyPart(bodyPart); File attach = new File(file); - if(attach.exists()){ - MimeBodyPart attachPart = new MimeBodyPart(); - DataSource source = new FileDataSource(attach); - attachPart.setDataHandler(new DataHandler(source)); - attachPart.setFileName(attach.getName()); - - multipart.addBodyPart(attachPart); + if (attach.exists()) { + MimeBodyPart attachPart = new MimeBodyPart(); + DataSource source = new FileDataSource(attach); + attachPart.setDataHandler(new DataHandler(source)); + attachPart.setFileName(attach.getName()); + + multipart.addBodyPart(attachPart); } mailMessage.setContent(multipart); - MailcapCommandMap mc = (MailcapCommandMap) CommandMap - .getDefaultCommandMap(); + MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); diff --git a/src/com/netease/qa/emmagee/utils/MemoryInfo.java b/src/com/netease/qa/emmagee/utils/MemoryInfo.java index cb5d9e3..c285fee 100644 --- a/src/com/netease/qa/emmagee/utils/MemoryInfo.java +++ b/src/com/netease/qa/emmagee/utils/MemoryInfo.java @@ -95,11 +95,7 @@ public class MemoryInfo { int[] myMempid = new int[] { pid }; Debug.MemoryInfo[] memoryInfo = am.getProcessMemoryInfo(myMempid); memoryInfo[0].getTotalSharedDirty(); - - // int memSize = memoryInfo[0].dalvikPrivateDirty; - // TODO PSS int memSize = memoryInfo[0].getTotalPss(); - // int memSize = memoryInfo[0].getTotalPrivateDirty(); return memSize; } diff --git a/src/com/netease/qa/emmagee/utils/ProcessInfo.java b/src/com/netease/qa/emmagee/utils/ProcessInfo.java index de3e862..c4c5584 100644 --- a/src/com/netease/qa/emmagee/utils/ProcessInfo.java +++ b/src/com/netease/qa/emmagee/utils/ProcessInfo.java @@ -23,10 +23,8 @@ import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; -import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.util.Log; /** @@ -68,15 +66,6 @@ public class ProcessInfo { break; } } -// Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); -// mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); -// List appList = pm.queryIntentActivities(mainIntent, PackageManager.MATCH_DEFAULT_ONLY); -// for (ResolveInfo temp : appList) { -// Log.d("my logs", temp.activityInfo.packageName); -// if (temp.activityInfo.packageName.toLowerCase().contains("uc")) { -// Log.v("my logs", "package and activity name = " + temp.activityInfo.packageName + " " + temp.activityInfo.name); -// } -// } programe.setPackageName(appinfo.processName); programe.setProcessName(appinfo.loadLabel(pm).toString()); programe.setIcon(appinfo.loadIcon(pm)); diff --git a/src/com/netease/qa/emmagee/utils/Settings.java b/src/com/netease/qa/emmagee/utils/Settings.java index d93df32..b71de11 100644 --- a/src/com/netease/qa/emmagee/utils/Settings.java +++ b/src/com/netease/qa/emmagee/utils/Settings.java @@ -4,16 +4,23 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +/** + * Parameters in Setting Activity + * + * @author yrom + * + */ public final class Settings { - - public static final String KEY_SENDER = "sender"; - public static final String KEY_PASSWORD = "password"; - public static final String KEY_RECIPIENTS = "recipients"; - public static final String KEY_SMTP = "smtp"; - public static final String KEY_ISFLOAT = "isfloat"; - public static final String KEY_INTERVAL = "interval"; - public static SharedPreferences getDefaultSharedPreferences(Context context){ - return PreferenceManager.getDefaultSharedPreferences(context); - } - + + public static final String KEY_SENDER = "sender"; + public static final String KEY_PASSWORD = "password"; + public static final String KEY_RECIPIENTS = "recipients"; + public static final String KEY_SMTP = "smtp"; + public static final String KEY_ISFLOAT = "isfloat"; + public static final String KEY_INTERVAL = "interval"; + + public static SharedPreferences getDefaultSharedPreferences(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context); + } + } -- GitLab