提交 1350be70 编写于 作者: Y yrom

remove `libs` from build path; add .gitignore; ...

refactor ListAdapter;
Change settings to SharedPreferences from Properties;
set File name to mail attachment;
check read_logs permission
上级 c8533ed9
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="libs"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/activation.jar"/>
<classpathentry kind="lib" path="libs/mail.jar"/>
<classpathentry kind="lib" path="libs/additionnal.jar"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
lint.xml
.DS_Store
\ No newline at end of file
......@@ -16,17 +16,15 @@
*/
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.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
......@@ -39,6 +37,7 @@ 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
......@@ -56,7 +55,6 @@ public class MailSettingsActivity extends Activity {
private EditText edtSmtp;
private String sender;
private String prePassword, curPassword;
private String settingTempFile;
private String recipients, smtp;
private String[] receivers;
private TextView title;
......@@ -69,42 +67,22 @@ public class MailSettingsActivity extends Activity {
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();
}
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, "");
edtRecipients.setText(recipients);
edtSender.setText(sender);
......@@ -144,35 +122,23 @@ public class MailSettingsActivity extends Activity {
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 {
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();
}
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();
Intent intent = new Intent();
setResult(Activity.RESULT_FIRST_USER, intent);
MailSettingsActivity.this.finish();
}
});
}
......
......@@ -36,12 +36,6 @@ import android.view.ViewGroup;
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;
import android.widget.Toast;
import com.netease.qa.emmagee.service.EmmageeService;
import com.netease.qa.emmagee.utils.ProcessInfo;
......@@ -64,9 +58,7 @@ public class MainPageActivity extends Activity {
private Intent monitorService;
private ListView lstViProgramme;
private Button btnTest;
private boolean isRadioChecked = false;
private int pid, uid;
private String processName, packageName, settingTempFile;
private boolean isServiceStop = false;
private UpdateReceiver receiver;
......@@ -83,8 +75,6 @@ public class MainPageActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainpage);
initTitleLayout();
createNewFile();
processInfo = new ProcessInfo();
btnTest.setOnClickListener(new OnClickListener() {
@Override
......@@ -92,7 +82,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())) {
if (isRadioChecked) {
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);
......@@ -114,9 +107,9 @@ public class MainPageActivity extends Activity {
monitorService.putExtra("pid", pid);
monitorService.putExtra("uid", uid);
monitorService.putExtra("packageName", packageName);
monitorService.putExtra("settingTempFile", settingTempFile);
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();
......@@ -147,6 +140,10 @@ public class MainPageActivity extends Activity {
goToSettingsActivity();
}
});
receiver = new UpdateReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.netease.action.emmageeService");
registerReceiver(receiver, filter);
}
private void initTitleLayout() {
......@@ -177,10 +174,6 @@ public class MainPageActivity extends Activity {
@Override
protected void onStart() {
Log.d(LOG_TAG, "onStart");
receiver = new UpdateReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.netease.action.emmageeService");
this.registerReceiver(receiver, filter);
super.onStart();
}
......@@ -188,37 +181,11 @@ public class MainPageActivity extends Activity {
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "onResume");
if (EmmageeService.isStop) {
if (isServiceStop) {
btnTest.setText(getString(R.string.start_test));
}
}
/**
* create new file to reserve setting data.
*/
private void createNewFile() {
Log.i(LOG_TAG, "create new file to save setting data");
settingTempFile = getBaseContext().getFilesDir().getPath() + "\\EmmageeSettings.properties";
Log.i(LOG_TAG, "settingFile = " + settingTempFile);
File settingFile = new File(settingTempFile);
if (!settingFile.exists()) {
try {
settingFile.createNewFile();
Properties properties = new Properties();
properties.setProperty("interval", "5");
properties.setProperty("isfloat", "true");
properties.setProperty("sender", "");
properties.setProperty("password", "");
properties.setProperty("recipients", "");
properties.setProperty("smtp", "");
FileOutputStream fos = new FileOutputStream(settingTempFile);
properties.store(fos, "Setting Data");
fos.close();
} catch (IOException e) {
Log.d(LOG_TAG, "create new file exception :" + e.getMessage());
}
}
}
/**
* wait for test application started.
......@@ -277,7 +244,6 @@ public class MainPageActivity extends Activity {
private void goToSettingsActivity() {
Intent intent = new Intent();
intent.setClass(MainPageActivity.this, SettingsActivity.class);
intent.putExtra("settingTempFile", settingTempFile);
startActivityForResult(intent, Activity.RESULT_FIRST_USER);
}
......@@ -287,32 +253,22 @@ public class MainPageActivity extends Activity {
* @author andrewleo
*/
private class ListAdapter extends BaseAdapter {
List<Programe> programe;
int tempPosition = -1;
/**
* save status of all installed processes
*
* @author andrewleo
*/
class Viewholder {
TextView txtAppName;
ImageView imgViAppIcon;
RadioButton rdoBtnApp;
}
List<Programe> programes;
Programe checkedProg;
int lastCheckedPosition = -1;
public ListAdapter() {
programe = processInfo.getRunningProcess(getBaseContext());
programes = processInfo.getRunningProcess(getBaseContext());
}
@Override
public int getCount() {
return programe.size();
return programes.size();
}
@Override
public Object getItem(int position) {
return programe.get(position);
return programes.get(position);
}
@Override
......@@ -322,60 +278,61 @@ public class MainPageActivity extends Activity {
@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);
Programe pr = (Programe) programes.get(position);
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);
}
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
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
isRadioChecked = true;
// Radio function
if (tempPosition != -1) {
RadioButton tempButton = (RadioButton) findViewById(tempPosition);
if ((tempButton != null) && (tempPosition != i)) {
tempButton.setChecked(false);
}
}
tempPosition = buttonView.getId();
packageName = programe.get(tempPosition).getPackageName();
processName = programe.get(tempPosition).getProcessName();
}
}
});
if (tempPosition == position) {
if (!holder.rdoBtnApp.isChecked())
holder.rdoBtnApp.setChecked(true);
}
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 finish() {
super.finish();
}
protected void onStop() {
unregisterReceiver(receiver);
super.onStop();
}
/**
* save status of all installed processes
*
* @author andrewleo
*/
static class Viewholder {
TextView txtAppName;
ImageView imgViAppIcon;
RadioButton rdoBtnApp;
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
}
}
......@@ -16,13 +16,9 @@
*/
package com.netease.qa.emmagee.activity;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Properties;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
......@@ -37,7 +33,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.utils.EncryptData;
import com.netease.qa.emmagee.utils.Settings;
/**
* Setting Page of Emmagee
......@@ -46,15 +42,15 @@ import com.netease.qa.emmagee.utils.EncryptData;
*/
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 TextView tvTime;
private String time;
private String settingTempFile;
private LinearLayout about;
private LinearLayout mailSettings;
private SharedPreferences preferences;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "onCreate");
......@@ -62,11 +58,6 @@ public class SettingsActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
Properties properties = new Properties();
final EncryptData des = new EncryptData("emmagee");
Intent intent = this.getIntent();
settingTempFile = getBaseContext().getFilesDir().getPath() + "\\EmmageeSettings.properties";
chkFloat = (CheckBox) findViewById(R.id.floating);
tvTime = (TextView) findViewById(R.id.time);
about = (LinearLayout) findViewById(R.id.about);
......@@ -77,25 +68,16 @@ public class SettingsActivity extends Activity {
RelativeLayout floatingItem = (RelativeLayout) findViewById(R.id.floating_item);
LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
boolean floatingTag = true;
btnSave.setVisibility(ImageView.INVISIBLE);
try {
properties.load(new FileInputStream(settingTempFile));
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;
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
Log.e(LOG_TAG, "Exception: " + e.getMessage());
e.printStackTrace();
}
tvTime.setText(time);
chkFloat.setChecked(floatingTag);
timeBar.setProgress(Integer.parseInt(time));
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);
timeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
......@@ -108,18 +90,9 @@ public class SettingsActivity extends Activity {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// when tracking stoped, update properties file
// when tracking stoped, update preferences
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();
}
preferences.edit().putInt(Settings.KEY_INTERVAL, interval).commit();
}
});
......@@ -154,18 +127,8 @@ public class SettingsActivity extends Activity {
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);
}
chkFloat.setChecked(!chkFloat.isChecked());
preferences.edit().putBoolean(Settings.KEY_ISFLOAT, chkFloat.isChecked()).commit();
}
});
}
......@@ -180,20 +143,4 @@ public class SettingsActivity extends Activity {
super.onDestroy();
}
/**
* is input a number.
*
* @param inputStr
* input string
* @return true is numeric
*/
private boolean isNumeric(String inputStr) {
for (int i = inputStr.length(); --i >= 0;) {
if (!Character.isDigit(inputStr.charAt(i))) {
return false;
}
}
return true;
}
}
......@@ -19,7 +19,6 @@ package com.netease.qa.emmagee.service;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
......@@ -30,7 +29,6 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Properties;
import android.app.Activity;
import android.app.PendingIntent;
......@@ -40,6 +38,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
......@@ -66,6 +65,7 @@ import com.netease.qa.emmagee.utils.EncryptData;
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.Settings;
/**
* Service running in background
......@@ -96,9 +96,8 @@ public class EmmageeService extends Service {
private WifiManager wifiManager;
private Handler handler = new Handler();
private CpuInfo cpuInfo;
private String time;
private boolean isFloating;
private String processName, packageName, settingTempFile, startActivity;
private String processName, packageName, startActivity;
private int pid, uid;
private boolean isServiceStop = false;
private String sender, password, recipients, smtp;
......@@ -168,7 +167,7 @@ public class EmmageeService extends Service {
}
@Override
public void onStart(Intent intent, int startId) {
public int onStartCommand(Intent intent, int flags, int startId) {
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);
......@@ -180,12 +179,10 @@ public class EmmageeService extends Service {
uid = intent.getExtras().getInt("uid");
processName = intent.getExtras().getString("processName");
packageName = intent.getExtras().getString("packageName");
settingTempFile = intent.getExtras().getString("settingTempFile");
startActivity = intent.getExtras().getString("startActivity");
cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid));
readSettingInfo(intent);
delaytime = Integer.parseInt(time) * 1000;
readSettingInfo();
if (isFloating) {
viFloatingWindow = LayoutInflater.from(this).inflate(R.layout.floating, null);
txtUnusedMem = (TextView) viFloatingWindow.findViewById(R.id.memunused);
......@@ -218,6 +215,7 @@ public class EmmageeService extends Service {
}
createResultCsv();
handler.postDelayed(task, 1000);
return START_NOT_STICKY;
}
/**
......@@ -225,23 +223,16 @@ public class EmmageeService extends Service {
*
* @throws IOException
*/
private void readSettingInfo(Intent intent) {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(settingTempFile));
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;
receivers = recipients.split("\\s+");
smtp = properties.getProperty("smtp");
} catch (IOException e) {
time = "5";
isFloating = true;
Log.e(LOG_TAG, e.getMessage());
}
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, "");
}
/**
......@@ -282,7 +273,11 @@ public class EmmageeService extends Service {
+ "\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);
+ ": ," + uid + "\r\n");
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) + ","
+ getString(R.string.total_used_cpu_ratio) + multiCpuTitle + "," + getString(R.string.traffic) + ","
......@@ -414,6 +409,14 @@ 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;
}
/**
* refresh the performance data showing in floating window.
......@@ -514,11 +517,13 @@ public class EmmageeService extends Service {
handler.removeCallbacks(task);
closeOpenedStream();
// replace the start time in file
if (!"".equals(startTime)) {
replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n");
} else {
replaceFileString(resultFilePath, START_TIME, "");
}
if(isGrantedReadLogsPermission()){
if (!"".equals(startTime)) {
replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n");
} else {
replaceFileString(resultFilePath, START_TIME, "");
}
}
isStop = true;
unregisterReceiver(batteryBroadcast);
boolean isSendSuccessfully = false;
......
package com.netease.qa.emmagee.utils;
import java.io.File;
import java.util.Date;
import java.util.Properties;
......@@ -69,32 +70,30 @@ public class MailSender {
// 设置邮件消息的发送者
mailMessage.setFrom(from);
// 创建邮件的接收者地址,并设置到邮件消息中
Address[] tos = null;
tos = new InternetAddress[maillists.length];
for (int i = 0; i < maillists.length; i++) {
tos[i] = new InternetAddress(maillists[i]);
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(maillists[i]));
}
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipients(Message.RecipientType.TO, tos);
// 设置邮件消息的主题
mailMessage.setSubject(subject);
// 设置邮件消息发送的时间
mailMessage.setSentDate(new Date());
Multipart multipart = new MimeMultipart();
BodyPart bodyPart = new MimeBodyPart();
bodyPart.setText(content);
MimeBodyPart attachPart = new MimeBodyPart();
DataSource source = new FileDataSource(file);
attachPart.setDataHandler(new DataHandler(source));
attachPart.setFileName(file);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(bodyPart);
multipart.addBodyPart(attachPart);
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);
}
mailMessage.setContent(multipart);
MailcapCommandMap mc = (MailcapCommandMap) CommandMap
.getDefaultCommandMap();
......
package com.netease.qa.emmagee.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册