配置文件新增app设置参数,添加异常捕获日志
This commit is contained in:
1 parent
4d55b95a8d
commit
a7ca196258
36 files changed
+734
-482
No files matched your search
@@ -44,6 +44,24 @@ import com.arialyy.aria.core.upload.UploadReceiver;
|
|||||||
* .start();
|
* .start();
|
||||||
* </code>
|
* </code>
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
|
* 如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||||
|
* 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
|
||||||
|
* 然后才能使用{@link #download(Object)}、{@link #upload(Object)}
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <code>
|
||||||
|
* Aria.init(getContext());
|
||||||
|
*
|
||||||
|
* Aria.download(this)
|
||||||
|
* .load(URL) //下载地址,必填
|
||||||
|
* //文件保存路径,必填
|
||||||
|
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||||
|
* .start();
|
||||||
|
*
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
|
||||||
|
|
||||||
@@ -69,21 +87,21 @@ import com.arialyy.aria.core.upload.UploadReceiver;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在任意对象中初始化下载
|
* 在任意对象中初始化下载,前提是你需要在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
|
||||||
*
|
*
|
||||||
* @param obj 任意对象
|
* @param obj 任意对象
|
||||||
*/
|
*/
|
||||||
public static DownloadReceiver download(Context context, Object obj) {
|
public static DownloadReceiver download(Object obj) {
|
||||||
return get(context).download(obj);
|
return AriaManager.getInstance().download(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在任意对象中初始化上传
|
* 在任意对象中初始化上传,前提是你需要在Application或Activity初始化的时候调用{@link #init(Context)}对Aria进行初始化
|
||||||
*
|
*
|
||||||
* @param obj 任意对象
|
* @param obj 任意对象
|
||||||
*/
|
*/
|
||||||
public static UploadReceiver upload(Context context, Object obj) {
|
public static UploadReceiver upload(Object obj) {
|
||||||
return get(context).upload(obj);
|
return AriaManager.getInstance().upload(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,31 +109,15 @@ import com.arialyy.aria.core.upload.UploadReceiver;
|
|||||||
*/
|
*/
|
||||||
public static AriaManager get(Context context) {
|
public static AriaManager get(Context context) {
|
||||||
return AriaManager.getInstance(context);
|
return AriaManager.getInstance(context);
|
||||||
//if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
|
}
|
||||||
// return AriaManager.getInstance((Context) obj);
|
|
||||||
//} else if (obj instanceof DialogFragment) {
|
/**
|
||||||
// DialogFragment dialog = (DialogFragment) obj;
|
* 初始化Aria,如果你需要在【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
|
||||||
// return AriaManager.getInstance(
|
* 之外的java中使用Aria,那么你应该在Application或Activity初始化的时候调用本方法对Aria进行初始化
|
||||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
|
* 只需要初始化一次就可以
|
||||||
// : dialog.getActivity());
|
* {@link #download(Object)}、{@link #upload(Object)}
|
||||||
//} else if (obj instanceof android.support.v4.app.Fragment) {
|
*/
|
||||||
// android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
|
public static AriaManager init(Context context) {
|
||||||
// return AriaManager.getInstance(
|
return AriaManager.getInstance(context);
|
||||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
|
||||||
// : fragment.getActivity());
|
|
||||||
//} else if (obj instanceof Fragment) {
|
|
||||||
// Fragment fragment = (Fragment) obj;
|
|
||||||
// return AriaManager.getInstance(
|
|
||||||
// Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
|
|
||||||
// : fragment.getActivity());
|
|
||||||
//} else if (obj instanceof PopupWindow) {
|
|
||||||
// PopupWindow popupWindow = (PopupWindow) obj;
|
|
||||||
// return AriaManager.getInstance(popupWindow.getContentView().getContext());
|
|
||||||
//} else if (obj instanceof Dialog) {
|
|
||||||
// Dialog dialog = (Dialog) obj;
|
|
||||||
// return AriaManager.getInstance(dialog.getContext());
|
|
||||||
//} else {
|
|
||||||
// throw new IllegalArgumentException("不支持的类型");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
|
|||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.orm.DelegateWrapper;
|
import com.arialyy.aria.orm.DelegateWrapper;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
|
import com.arialyy.aria.util.AriaCrashHandler;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -73,12 +74,14 @@ import org.xml.sax.SAXException;
|
|||||||
private List<ICmd> mCommands = new ArrayList<>();
|
private List<ICmd> mCommands = new ArrayList<>();
|
||||||
private Configuration.DownloadConfig mDConfig;
|
private Configuration.DownloadConfig mDConfig;
|
||||||
private Configuration.UploadConfig mUConfig;
|
private Configuration.UploadConfig mUConfig;
|
||||||
|
private Configuration.AppConfig mAConfig;
|
||||||
|
|
||||||
private AriaManager(Context context) {
|
private AriaManager(Context context) {
|
||||||
DelegateWrapper.init(context.getApplicationContext());
|
DelegateWrapper.init(context.getApplicationContext());
|
||||||
APP = context.getApplicationContext();
|
APP = context.getApplicationContext();
|
||||||
regAppLifeCallback(context);
|
regAppLifeCallback(context);
|
||||||
initConfig();
|
initConfig();
|
||||||
|
initAria();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AriaManager getInstance(Context context) {
|
public static AriaManager getInstance(Context context) {
|
||||||
@@ -90,17 +93,22 @@ import org.xml.sax.SAXException;
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, AbsReceiver> getReceiver() {
|
static AriaManager getInstance() {
|
||||||
return mReceivers;
|
if (INSTANCE == null) {
|
||||||
|
throw new NullPointerException("请在Application或Activity初始化时调用一次Aria.init(context)方法进行初始化操作");
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void initAria() {
|
||||||
* 设置Aria的日志级别
|
if (mAConfig.getUseAriaCrashHandler()) {
|
||||||
*
|
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler());
|
||||||
* @param level {@link ALog#LOG_LEVEL_VERBOSE}
|
}
|
||||||
*/
|
mAConfig.setLogLevel(mAConfig.getLogLevel());
|
||||||
public void setLogLevel(int level) {
|
}
|
||||||
ALog.LOG_LEVEL = level;
|
|
||||||
|
public Map<String, AbsReceiver> getReceiver() {
|
||||||
|
return mReceivers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,6 +171,13 @@ import org.xml.sax.SAXException;
|
|||||||
return mUConfig;
|
return mUConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取APP配置
|
||||||
|
*/
|
||||||
|
public Configuration.AppConfig getAppConfig() {
|
||||||
|
return mAConfig;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置命令
|
* 设置命令
|
||||||
*/
|
*/
|
||||||
@@ -213,22 +228,6 @@ import org.xml.sax.SAXException;
|
|||||||
return (receiver instanceof UploadReceiver) ? (UploadReceiver) receiver : null;
|
return (receiver instanceof UploadReceiver) ? (UploadReceiver) receiver : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Aria下载错误日志
|
|
||||||
*
|
|
||||||
* @return 如果错误日志不存在则返回空,否则返回错误日志列表
|
|
||||||
*/
|
|
||||||
public List<ErrorEntity> getErrorLog() {
|
|
||||||
return DbEntity.findAllData(ErrorEntity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清楚错误日志
|
|
||||||
*/
|
|
||||||
public void cleanLog() {
|
|
||||||
DbEntity.clean(ErrorEntity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除任务记录
|
* 删除任务记录
|
||||||
*
|
*
|
||||||
@@ -379,6 +378,7 @@ import org.xml.sax.SAXException;
|
|||||||
}
|
}
|
||||||
mDConfig = Configuration.DownloadConfig.getInstance();
|
mDConfig = Configuration.DownloadConfig.getInstance();
|
||||||
mUConfig = Configuration.UploadConfig.getInstance();
|
mUConfig = Configuration.UploadConfig.getInstance();
|
||||||
|
mAConfig = Configuration.AppConfig.getInstance();
|
||||||
if (tempDir.exists()) {
|
if (tempDir.exists()) {
|
||||||
File newDir = new File(APP.getFilesDir().getPath() + DOWNLOAD_TEMP_DIR);
|
File newDir = new File(APP.getFilesDir().getPath() + DOWNLOAD_TEMP_DIR);
|
||||||
newDir.mkdirs();
|
newDir.mkdirs();
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ import org.xml.sax.helpers.DefaultHandler;
|
|||||||
class ConfigHelper extends DefaultHandler {
|
class ConfigHelper extends DefaultHandler {
|
||||||
private final String TAG = "ConfigHelper";
|
private final String TAG = "ConfigHelper";
|
||||||
|
|
||||||
private boolean isDownloadConfig = false, isUploadConfig;
|
private boolean isDownloadConfig = false, isUploadConfig = false, isAppConfig = false;
|
||||||
private Configuration.DownloadConfig mDownloadConfig = Configuration.DownloadConfig.getInstance();
|
private Configuration.DownloadConfig mDownloadConfig = Configuration.DownloadConfig.getInstance();
|
||||||
private Configuration.UploadConfig mUploadConfig = Configuration.UploadConfig.getInstance();
|
private Configuration.UploadConfig mUploadConfig = Configuration.UploadConfig.getInstance();
|
||||||
|
private Configuration.AppConfig mAppConfig = Configuration.AppConfig.getInstance();
|
||||||
|
|
||||||
@Override public void startDocument() throws SAXException {
|
@Override public void startDocument() throws SAXException {
|
||||||
super.startDocument();
|
super.startDocument();
|
||||||
@@ -43,10 +44,17 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
if (qName.equals("download")) {
|
if (qName.equals("download")) {
|
||||||
isDownloadConfig = true;
|
isDownloadConfig = true;
|
||||||
isUploadConfig = false;
|
isUploadConfig = false;
|
||||||
|
isAppConfig = false;
|
||||||
} else if (qName.equals("upload")) {
|
} else if (qName.equals("upload")) {
|
||||||
isUploadConfig = true;
|
isUploadConfig = true;
|
||||||
isDownloadConfig = false;
|
isDownloadConfig = false;
|
||||||
|
isAppConfig = false;
|
||||||
|
} else if (qName.equals("app")) {
|
||||||
|
isUploadConfig = false;
|
||||||
|
isDownloadConfig = false;
|
||||||
|
isAppConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDownloadConfig || isUploadConfig) {
|
if (isDownloadConfig || isUploadConfig) {
|
||||||
|
|
||||||
String value = attributes.getValue("value");
|
String value = attributes.getValue("value");
|
||||||
@@ -90,17 +98,46 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
loadUpdateInterval(value);
|
loadUpdateInterval(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (isAppConfig) {
|
||||||
|
String value = attributes.getValue("value");
|
||||||
|
switch (value) {
|
||||||
|
case "useAriaCrashHandler":
|
||||||
|
loadUseAriaCrashHandler(value);
|
||||||
|
break;
|
||||||
|
case "logLevel":
|
||||||
|
loadLogLevel(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLogLevel(String value) {
|
||||||
|
int level;
|
||||||
|
try {
|
||||||
|
level = Integer.parseInt(value);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
level = ALog.LOG_LEVEL_VERBOSE;
|
||||||
|
}
|
||||||
|
if (level < ALog.LOG_LEVEL_VERBOSE || level > ALog.LOG_CLOSE) {
|
||||||
|
ALog.w(TAG, "level【" + level + "】错误");
|
||||||
|
mAppConfig.logLevel = ALog.LOG_LEVEL_VERBOSE;
|
||||||
|
} else {
|
||||||
|
mAppConfig.logLevel = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadUseAriaCrashHandler(String value) {
|
||||||
|
if (checkBoolean(value)) {
|
||||||
|
ALog.w(TAG, "useAriaCrashHandler【" + value + "】错误");
|
||||||
|
mAppConfig.useAriaCrashHandler = Boolean.parseBoolean(value);
|
||||||
|
} else {
|
||||||
|
mAppConfig.useAriaCrashHandler = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUpdateInterval(String value) {
|
private void loadUpdateInterval(String value) {
|
||||||
long temp = 1000;
|
long temp = checkLong(value) ? Long.parseLong(value) : 1000;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
temp = Long.parseLong(value);
|
|
||||||
if (temp <= 0) {
|
|
||||||
temp = 1000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.updateInterval = temp;
|
mDownloadConfig.updateInterval = temp;
|
||||||
}
|
}
|
||||||
@@ -124,17 +161,18 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadMaxSpeed(String value) {
|
private void loadMaxSpeed(String value) {
|
||||||
double maxSpeed = 0.0;
|
int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
maxSpeed = Double.parseDouble(value);
|
|
||||||
}
|
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.msxSpeed = maxSpeed;
|
mDownloadConfig.msxSpeed = maxSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConvertSpeed(String value) {
|
private void loadConvertSpeed(String value) {
|
||||||
boolean open = Boolean.parseBoolean(value);
|
boolean open = true;
|
||||||
|
if (checkBoolean(value)) {
|
||||||
|
open = Boolean.parseBoolean(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.isConvertSpeed = open;
|
mDownloadConfig.isConvertSpeed = open;
|
||||||
}
|
}
|
||||||
@@ -144,10 +182,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadReTryInterval(String value) {
|
private void loadReTryInterval(String value) {
|
||||||
int time = 2 * 1000;
|
int time = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
time = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time < 2 * 1000) {
|
if (time < 2 * 1000) {
|
||||||
time = 2 * 1000;
|
time = 2 * 1000;
|
||||||
@@ -166,10 +201,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadBuffSize(String value) {
|
private void loadBuffSize(String value) {
|
||||||
int buffSize = 8192;
|
int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
buffSize = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffSize < 2048) {
|
if (buffSize < 2048) {
|
||||||
buffSize = 2048;
|
buffSize = 2048;
|
||||||
@@ -181,10 +213,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadIOTimeout(String value) {
|
private void loadIOTimeout(String value) {
|
||||||
int time = 10 * 1000;
|
int time = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
time = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time < 10 * 1000) {
|
if (time < 10 * 1000) {
|
||||||
time = 10 * 1000;
|
time = 10 * 1000;
|
||||||
@@ -196,10 +225,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadConnectTime(String value) {
|
private void loadConnectTime(String value) {
|
||||||
int time = 5 * 1000;
|
int time = checkInt(value) ? Integer.parseInt(value) : 5 * 1000;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
time = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.connectTimeOut = time;
|
mDownloadConfig.connectTimeOut = time;
|
||||||
@@ -210,10 +236,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadReTry(String value) {
|
private void loadReTry(String value) {
|
||||||
int num = 0;
|
int num = checkInt(value) ? Integer.parseInt(value) : 0;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
num = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.reTryNum = num;
|
mDownloadConfig.reTryNum = num;
|
||||||
@@ -224,10 +247,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadMaxQueue(String value) {
|
private void loadMaxQueue(String value) {
|
||||||
int num = 2;
|
int num = checkInt(value) ? Integer.parseInt(value) : 2;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
num = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
if (num < 1) {
|
if (num < 1) {
|
||||||
ALog.w(TAG, "任务队列数不能小于 1");
|
ALog.w(TAG, "任务队列数不能小于 1");
|
||||||
num = 2;
|
num = 2;
|
||||||
@@ -241,10 +261,7 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadThreadNum(String value) {
|
private void loadThreadNum(String value) {
|
||||||
int num = 3;
|
int num = checkInt(value) ? Integer.parseInt(value) : 3;
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
num = Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
if (num < 1) {
|
if (num < 1) {
|
||||||
ALog.e(TAG, "下载线程数不能小于 1");
|
ALog.e(TAG, "下载线程数不能小于 1");
|
||||||
num = 1;
|
num = 1;
|
||||||
@@ -254,6 +271,52 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否int值是否合法
|
||||||
|
*
|
||||||
|
* @return {@code true} 合法
|
||||||
|
*/
|
||||||
|
private boolean checkInt(String value) {
|
||||||
|
if (TextUtils.isEmpty(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Integer l = Integer.parseInt(value);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否long值是否合法
|
||||||
|
*
|
||||||
|
* @return {@code true} 合法
|
||||||
|
*/
|
||||||
|
private boolean checkLong(String value) {
|
||||||
|
if (TextUtils.isEmpty(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Long l = Long.parseLong(value);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查boolean值是否合法
|
||||||
|
*
|
||||||
|
* @return {@code true} 合法
|
||||||
|
*/
|
||||||
|
private boolean checkBoolean(String value) {
|
||||||
|
return !TextUtils.isEmpty(value) && (value.equalsIgnoreCase("true") || value.equalsIgnoreCase(
|
||||||
|
"false"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void characters(char[] ch, int start, int length) throws SAXException {
|
@Override public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
super.characters(ch, start, length);
|
super.characters(ch, start, length);
|
||||||
}
|
}
|
||||||
@@ -266,5 +329,6 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
super.endDocument();
|
super.endDocument();
|
||||||
mDownloadConfig.saveAll();
|
mDownloadConfig.saveAll();
|
||||||
mUploadConfig.saveAll();
|
mUploadConfig.saveAll();
|
||||||
|
mAppConfig.saveAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
*
|
|
||||||
* 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.arialyy.aria.core;
|
|
||||||
|
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Aria.Lao on 2017/8/29.
|
|
||||||
* 错误实体
|
|
||||||
*/
|
|
||||||
public class ErrorEntity extends DbEntity {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入时间
|
|
||||||
*/
|
|
||||||
public long insertTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 错误信息
|
|
||||||
*/
|
|
||||||
public String err;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务名
|
|
||||||
*/
|
|
||||||
public String taskName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*任务类型
|
|
||||||
*/
|
|
||||||
public String taskType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提示
|
|
||||||
*/
|
|
||||||
public String msg;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务key
|
|
||||||
*/
|
|
||||||
public String key;
|
|
||||||
|
|
||||||
@Override public String toString() {
|
|
||||||
return "ErrorEntity{"
|
|
||||||
+ "insertTime="
|
|
||||||
+ insertTime
|
|
||||||
+ ", err='"
|
|
||||||
+ err
|
|
||||||
+ '\''
|
|
||||||
+ ", taskName='"
|
|
||||||
+ taskName
|
|
||||||
+ '\''
|
|
||||||
+ ", taskType='"
|
|
||||||
+ taskType
|
|
||||||
+ '\''
|
|
||||||
+ ", msg='"
|
|
||||||
+ msg
|
|
||||||
+ '\''
|
|
||||||
+ ", key='"
|
|
||||||
+ key
|
|
||||||
+ '\''
|
|
||||||
+ '}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,15 @@ package com.arialyy.aria.core.command.normal;
|
|||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
|
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
|
||||||
|
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
|
||||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
|
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
@@ -53,29 +56,32 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
* @param type {@code 1}单任务下载任务;{@code 2}任务组下载任务;{@code 3} 单任务上传任务
|
* @param type {@code 1}单任务下载任务;{@code 2}任务组下载任务;{@code 3} 单任务上传任务
|
||||||
*/
|
*/
|
||||||
private List<AbsTaskEntity> findTaskData(int type) {
|
private List<AbsTaskEntity> findTaskData(int type) {
|
||||||
|
// TODO: 2018/4/20 需要测试
|
||||||
List<AbsTaskEntity> tempList = new ArrayList<>();
|
List<AbsTaskEntity> tempList = new ArrayList<>();
|
||||||
switch (type) {
|
if (type == 1) {
|
||||||
case 1:
|
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
|
||||||
List<DownloadTaskEntity> dTaskEntity =
|
"DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state!=?", "1");
|
||||||
DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false");
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
if (dTaskEntity != null && !dTaskEntity.isEmpty()) {
|
for (DTEWrapper w : wrappers) {
|
||||||
tempList.addAll(dTaskEntity);
|
tempList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 2:
|
} else if (type == 2) {
|
||||||
List<DownloadGroupTaskEntity> groupTask =
|
List<DGTEWrapper> wrappers =
|
||||||
DbEntity.findAllData(DownloadGroupTaskEntity.class);
|
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.state!=?", "1");
|
||||||
if (groupTask != null && !groupTask.isEmpty()) {
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
tempList.addAll(groupTask);
|
for (DGTEWrapper w : wrappers) {
|
||||||
|
tempList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 3:
|
} else if (type == 3) {
|
||||||
List<UploadTaskEntity> uTaskEntity =
|
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class,
|
||||||
DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false");
|
"UploadTaskEntity.state!=?", "1");
|
||||||
if (uTaskEntity != null && !uTaskEntity.isEmpty()) {
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
tempList.addAll(uTaskEntity);
|
for (UTEWrapper w : wrappers) {
|
||||||
|
tempList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
return tempList;
|
return tempList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import com.arialyy.aria.core.AriaManager;
|
|||||||
import com.arialyy.aria.core.common.QueueMod;
|
import com.arialyy.aria.core.common.QueueMod;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
|
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
|
||||||
|
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
|
||||||
import com.arialyy.aria.core.inf.AbsTask;
|
import com.arialyy.aria.core.inf.AbsTask;
|
||||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
@@ -28,6 +30,7 @@ import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
|||||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
|
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
@@ -112,29 +115,32 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<AbsTaskEntity> findWaitData(int type) {
|
private List<AbsTaskEntity> findWaitData(int type) {
|
||||||
|
// TODO: 2018/4/20 需要测试
|
||||||
List<AbsTaskEntity> waitList = new ArrayList<>();
|
List<AbsTaskEntity> waitList = new ArrayList<>();
|
||||||
switch (type) {
|
if (type == 1) {
|
||||||
case 1:
|
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
|
||||||
List<DownloadTaskEntity> dEntity =
|
"DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state=?", "3");
|
||||||
DbEntity.findDatas(DownloadTaskEntity.class, "groupName=? and state=?", "", "3");
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
if (dEntity != null && !dEntity.isEmpty()) {
|
for (DTEWrapper w : wrappers) {
|
||||||
waitList.addAll(dEntity);
|
waitList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 2:
|
} else if (type == 2) {
|
||||||
List<DownloadGroupTaskEntity> dgEntity =
|
List<DGTEWrapper> wrappers =
|
||||||
DbEntity.findDatas(DownloadGroupTaskEntity.class, "state=?", "3");
|
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.state=?", "3");
|
||||||
if (dgEntity != null && !dgEntity.isEmpty()) {
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
waitList.addAll(dgEntity);
|
for (DGTEWrapper w : wrappers) {
|
||||||
|
waitList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 3:
|
} else if (type == 3) {
|
||||||
List<UploadTaskEntity> uEntity =
|
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class,
|
||||||
DbEntity.findDatas(UploadTaskEntity.class, "state=?", "3");
|
"UploadTaskEntity.state=?", "3");
|
||||||
if (uEntity != null && !uEntity.isEmpty()) {
|
if (wrappers != null && !wrappers.isEmpty()) {
|
||||||
waitList.addAll(uEntity);
|
for (UTEWrapper w : wrappers) {
|
||||||
|
waitList.add(w.taskEntity);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
return waitList;
|
return waitList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
try {
|
try {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
ALog.e(TAG, msg + "\n" + CommonUtil.getPrintException(ex));
|
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
|
||||||
} else {
|
} else {
|
||||||
ALog.e(TAG, msg);
|
ALog.e(TAG, msg);
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
} else {
|
} else {
|
||||||
ALog.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
ALog.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
ErrorHelp.saveError(mTaskType, mEntity, "", CommonUtil.getPrintException(ex));
|
ErrorHelp.saveError(TAG, "", ALog.getExceptionString(ex));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import com.arialyy.aria.core.command.ICmd;
|
|||||||
import com.arialyy.aria.core.command.normal.CancelAllCmd;
|
import com.arialyy.aria.core.command.normal.CancelAllCmd;
|
||||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||||
import com.arialyy.aria.core.common.ProxyHelper;
|
import com.arialyy.aria.core.common.ProxyHelper;
|
||||||
import com.arialyy.aria.core.download.wrapper.DGroupEntityWrapper;
|
import com.arialyy.aria.core.download.wrapper.DGEWrapper;
|
||||||
import com.arialyy.aria.core.inf.AbsEntity;
|
import com.arialyy.aria.core.inf.AbsEntity;
|
||||||
import com.arialyy.aria.core.inf.AbsReceiver;
|
import com.arialyy.aria.core.inf.AbsReceiver;
|
||||||
import com.arialyy.aria.core.inf.AbsTarget;
|
import com.arialyy.aria.core.inf.AbsTarget;
|
||||||
@@ -50,7 +50,7 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
*
|
*
|
||||||
* @param maxSpeed 为0表示不限速
|
* @param maxSpeed 为0表示不限速
|
||||||
*/
|
*/
|
||||||
@Deprecated public void setMaxSpeed(double maxSpeed) {
|
@Deprecated public void setMaxSpeed(int maxSpeed) {
|
||||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMsxSpeed(maxSpeed);
|
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMsxSpeed(maxSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,12 +350,12 @@ public class DownloadReceiver extends AbsReceiver {
|
|||||||
* @return 如果没有任务组列表,则返回null
|
* @return 如果没有任务组列表,则返回null
|
||||||
*/
|
*/
|
||||||
public List<DownloadGroupEntity> getGroupTaskList() {
|
public List<DownloadGroupEntity> getGroupTaskList() {
|
||||||
List<DGroupEntityWrapper> wrappers = DbEntity.findRelationData(DGroupEntityWrapper.class);
|
List<DGEWrapper> wrappers = DbEntity.findRelationData(DGEWrapper.class);
|
||||||
if (wrappers == null || wrappers.isEmpty()) {
|
if (wrappers == null || wrappers.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<DownloadGroupEntity> entities = new ArrayList<>();
|
List<DownloadGroupEntity> entities = new ArrayList<>();
|
||||||
for (DGroupEntityWrapper wrapper : wrappers) {
|
for (DGEWrapper wrapper : wrappers) {
|
||||||
entities.add(wrapper.groupEntity);
|
entities.add(wrapper.groupEntity);
|
||||||
}
|
}
|
||||||
return entities;
|
return entities;
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class DownloadTask extends AbsNormalTask<DownloadTaskEntity> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否真正下载
|
* 是否真正下载
|
||||||
|
*
|
||||||
* @return {@code true} 真正下载
|
* @return {@code true} 真正下载
|
||||||
*/
|
*/
|
||||||
@Override public boolean isRunning() {
|
@Override public boolean isRunning() {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
+ "】\n【filePath:"
|
+ "】\n【filePath:"
|
||||||
+ mEntity.getDownloadPath()
|
+ mEntity.getDownloadPath()
|
||||||
+ "】\n"
|
+ "】\n"
|
||||||
+ CommonUtil.getPrintException(e));
|
+ ALog.getExceptionString(e));
|
||||||
} finally {
|
} finally {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
@@ -116,6 +116,6 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
ALog.e(TAG, errorMsg);
|
ALog.e(TAG, errorMsg);
|
||||||
mConstance.isRunning = false;
|
mConstance.isRunning = false;
|
||||||
mListener.onFail(false);
|
mListener.onFail(false);
|
||||||
ErrorHelp.saveError("", mEntity, "", errorMsg);
|
ErrorHelp.saveError(TAG, "", errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-1
@@ -27,6 +27,8 @@ import java.util.Set;
|
|||||||
* ftp文件夹下载工具
|
* ftp文件夹下载工具
|
||||||
*/
|
*/
|
||||||
public class FtpDirDownloadUtil extends AbsGroupUtil {
|
public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||||
|
private String TAG = "FtpDirDownloadUtil";
|
||||||
|
|
||||||
public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
|
public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
|
||||||
super(listener, taskEntity);
|
super(listener, taskEntity);
|
||||||
}
|
}
|
||||||
@@ -56,7 +58,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
|||||||
mExeMap.remove(url);
|
mExeMap.remove(url);
|
||||||
}
|
}
|
||||||
mListener.onFail(needRetry);
|
mListener.onFail(needRetry);
|
||||||
ErrorHelp.saveError("D_FTP_DIR", mGTEntity.getEntity(), "", errorMsg);
|
ErrorHelp.saveError(TAG, "", errorMsg);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ class HttpFileInfoThread implements Runnable {
|
|||||||
+ "】\n【filePath:"
|
+ "】\n【filePath:"
|
||||||
+ mEntity.getDownloadPath()
|
+ mEntity.getDownloadPath()
|
||||||
+ "】\n"
|
+ "】\n"
|
||||||
+ CommonUtil.getPrintException(e), true);
|
+ ALog.getExceptionString(e), true);
|
||||||
} finally {
|
} finally {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
|||||||
@@ -116,11 +116,12 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取chunk模式的文件流
|
* 读取chunk模式的文件流
|
||||||
|
*
|
||||||
* @deprecated 暂时先这样处理,无chun
|
* @deprecated 暂时先这样处理,无chun
|
||||||
*/
|
*/
|
||||||
private void readChunk(InputStream is, RandomAccessFile file)
|
private void readChunk(InputStream is, RandomAccessFile file)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
readNormal(is, file);
|
readNormal(is, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -29,7 +29,7 @@ import com.arialyy.aria.util.ErrorHelp;
|
|||||||
* D_HTTP\FTP单任务下载工具
|
* D_HTTP\FTP单任务下载工具
|
||||||
*/
|
*/
|
||||||
public class SimpleDownloadUtil implements IUtil, Runnable {
|
public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||||
private static final String TAG = "SimpleDownloadUtil";
|
private String TAG = "SimpleDownloadUtil";
|
||||||
private IDownloadListener mListener;
|
private IDownloadListener mListener;
|
||||||
private Downloader mDownloader;
|
private Downloader mDownloader;
|
||||||
private DownloadTaskEntity mTaskEntity;
|
private DownloadTaskEntity mTaskEntity;
|
||||||
@@ -86,7 +86,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
|||||||
|
|
||||||
private void failDownload(String msg, boolean needRetry) {
|
private void failDownload(String msg, boolean needRetry) {
|
||||||
mListener.onFail(needRetry);
|
mListener.onFail(needRetry);
|
||||||
ErrorHelp.saveError("HTTP_DOWNLOAD", mTaskEntity.getEntity(), msg, "");
|
ErrorHelp.saveError(TAG, msg, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.List;
|
|||||||
* 任务组实体和子任务实体的关系
|
* 任务组实体和子任务实体的关系
|
||||||
*/
|
*/
|
||||||
@Wrapper
|
@Wrapper
|
||||||
public class DGroupEntityWrapper extends AbsWrapper {
|
public class DGEWrapper extends AbsWrapper {
|
||||||
|
|
||||||
@One
|
@One
|
||||||
public DownloadGroupEntity groupEntity;
|
public DownloadGroupEntity groupEntity;
|
||||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.List;
|
|||||||
* 任务组任务实体和任务组任务实体的子任务实体对应关系
|
* 任务组任务实体和任务组任务实体的子任务实体对应关系
|
||||||
*/
|
*/
|
||||||
@Wrapper
|
@Wrapper
|
||||||
public class DGroupSubTaskEntityWrapper extends AbsWrapper {
|
public class DGSTEWrapper extends AbsWrapper {
|
||||||
|
|
||||||
@One
|
@One
|
||||||
public DownloadGroupTaskEntity dgTaskEntity;
|
public DownloadGroupTaskEntity dgTaskEntity;
|
||||||
+4
-4
@@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
* 任务组实体和任务组任务实体的关系
|
* 任务组实体和任务组任务实体的关系
|
||||||
*/
|
*/
|
||||||
@Wrapper
|
@Wrapper
|
||||||
public class DGroupTaskEntityWrapper extends AbsWrapper {
|
public class DGTEWrapper extends AbsWrapper {
|
||||||
|
|
||||||
@One
|
@One
|
||||||
public DownloadGroupEntity entity;
|
public DownloadGroupEntity entity;
|
||||||
@@ -47,12 +47,12 @@ public class DGroupTaskEntityWrapper extends AbsWrapper {
|
|||||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
|
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
|
||||||
if (taskEntity != null) {
|
if (taskEntity != null) {
|
||||||
taskEntity.setEntity(entity);
|
taskEntity.setEntity(entity);
|
||||||
List<DownloadTaskWrapper> subWrappers =
|
List<DTEWrapper> subWrappers =
|
||||||
DbEntity.findRelationData(DownloadTaskWrapper.class, "DownloadTaskEntity.groupName=?",
|
DbEntity.findRelationData(DTEWrapper.class, "DownloadTaskEntity.groupName=?",
|
||||||
taskEntity.getKey());
|
taskEntity.getKey());
|
||||||
if (subWrappers != null && !subWrappers.isEmpty()) {
|
if (subWrappers != null && !subWrappers.isEmpty()) {
|
||||||
List<DownloadTaskEntity> temp = new ArrayList<>();
|
List<DownloadTaskEntity> temp = new ArrayList<>();
|
||||||
for (DownloadTaskWrapper dw : subWrappers) {
|
for (DTEWrapper dw : subWrappers) {
|
||||||
if (dw.taskEntity.requestType == AbsTaskEntity.D_FTP) {
|
if (dw.taskEntity.requestType == AbsTaskEntity.D_FTP) {
|
||||||
dw.taskEntity.urlEntity = CommonUtil.getFtpUrlInfo(dw.taskEntity.url);
|
dw.taskEntity.urlEntity = CommonUtil.getFtpUrlInfo(dw.taskEntity.url);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@ import java.util.List;
|
|||||||
* Created by laoyuyu on 2018/3/30.
|
* Created by laoyuyu on 2018/3/30.
|
||||||
*/
|
*/
|
||||||
@Wrapper
|
@Wrapper
|
||||||
public class DownloadTaskWrapper extends AbsWrapper {
|
public class DTEWrapper extends AbsWrapper {
|
||||||
|
|
||||||
@One
|
@One
|
||||||
public DownloadEntity entity;
|
public DownloadEntity entity;
|
||||||
@@ -19,8 +19,8 @@ import com.arialyy.aria.core.download.DownloadEntity;
|
|||||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
import com.arialyy.aria.core.download.wrapper.DGroupEntityWrapper;
|
import com.arialyy.aria.core.download.wrapper.DGEWrapper;
|
||||||
import com.arialyy.aria.core.download.wrapper.DGroupTaskEntityWrapper;
|
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -48,8 +48,8 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
|||||||
|
|
||||||
@Override public DownloadGroupTaskEntity getGTE(String groupName, List<String> urls) {
|
@Override public DownloadGroupTaskEntity getGTE(String groupName, List<String> urls) {
|
||||||
DownloadGroupEntity entity = createDGroupEntity(groupName, urls);
|
DownloadGroupEntity entity = createDGroupEntity(groupName, urls);
|
||||||
List<DGroupTaskEntityWrapper> wrapper =
|
List<DGTEWrapper> wrapper =
|
||||||
DbEntity.findRelationData(DGroupTaskEntityWrapper.class, "DownloadGroupTaskEntity.key=?",
|
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?",
|
||||||
entity.getGroupName());
|
entity.getGroupName());
|
||||||
DownloadGroupTaskEntity gte;
|
DownloadGroupTaskEntity gte;
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public DownloadGroupTaskEntity getFTE(String ftpUrl) {
|
@Override public DownloadGroupTaskEntity getFTE(String ftpUrl) {
|
||||||
List<DGroupTaskEntityWrapper> wrapper =
|
List<DGTEWrapper> wrapper =
|
||||||
DbEntity.findRelationData(DGroupTaskEntityWrapper.class, "DownloadGroupTaskEntity.key=?",
|
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?",
|
||||||
ftpUrl);
|
ftpUrl);
|
||||||
DownloadGroupTaskEntity fte;
|
DownloadGroupTaskEntity fte;
|
||||||
|
|
||||||
@@ -130,8 +130,8 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
|||||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
|
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
|
||||||
*/
|
*/
|
||||||
private DownloadGroupEntity createDGroupEntity(String groupName, List<String> urls) {
|
private DownloadGroupEntity createDGroupEntity(String groupName, List<String> urls) {
|
||||||
List<DGroupEntityWrapper> wrapper =
|
List<DGEWrapper> wrapper =
|
||||||
DbEntity.findRelationData(DGroupEntityWrapper.class, "DownloadGroupEntity.groupName=?",
|
DbEntity.findRelationData(DGEWrapper.class, "DownloadGroupEntity.groupName=?",
|
||||||
groupName);
|
groupName);
|
||||||
|
|
||||||
DownloadGroupEntity groupEntity;
|
DownloadGroupEntity groupEntity;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.manager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
import com.arialyy.aria.core.download.wrapper.DownloadTaskWrapper;
|
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -49,7 +49,7 @@ class DTEFactory implements INormalTEFactory<DownloadEntity, DownloadTaskEntity>
|
|||||||
* 通过下载实体创建任务实体
|
* 通过下载实体创建任务实体
|
||||||
*/
|
*/
|
||||||
private DownloadTaskEntity create(DownloadEntity entity) {
|
private DownloadTaskEntity create(DownloadEntity entity) {
|
||||||
List<DownloadTaskWrapper> wrapper = DbEntity.findRelationData(DownloadTaskWrapper.class,
|
List<DTEWrapper> wrapper = DbEntity.findRelationData(DTEWrapper.class,
|
||||||
"DownloadTaskEntity.key=? and DownloadTaskEntity.isGroupTask='false' and DownloadTaskEntity.url=?",
|
"DownloadTaskEntity.key=? and DownloadTaskEntity.isGroupTask='false' and DownloadTaskEntity.url=?",
|
||||||
entity.getDownloadPath(), entity.getUrl());
|
entity.getDownloadPath(), entity.getUrl());
|
||||||
DownloadTaskEntity taskEntity;
|
DownloadTaskEntity taskEntity;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.manager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.arialyy.aria.core.upload.UploadEntity;
|
import com.arialyy.aria.core.upload.UploadEntity;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskWrapper;
|
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.Regular;
|
import com.arialyy.aria.util.Regular;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,8 +45,8 @@ class UTEFactory implements INormalTEFactory<UploadEntity, UploadTaskEntity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UploadTaskEntity create(UploadEntity entity) {
|
private UploadTaskEntity create(UploadEntity entity) {
|
||||||
List<UploadTaskWrapper> wrapper =
|
List<UTEWrapper> wrapper =
|
||||||
DbEntity.findRelationData(UploadTaskWrapper.class, "UploadTaskEntity.key=?",
|
DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.key=?",
|
||||||
entity.getFilePath());
|
entity.getFilePath());
|
||||||
|
|
||||||
if (wrapper != null && !wrapper.isEmpty()) {
|
if (wrapper != null && !wrapper.isEmpty()) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.upload.uploader;
|
package com.arialyy.aria.core.upload.uploader;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||||
import com.arialyy.aria.core.common.StateConstance;
|
import com.arialyy.aria.core.common.StateConstance;
|
||||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||||
|
|||||||
+4
-2
@@ -13,8 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.upload;
|
package com.arialyy.aria.core.upload.wrapper;
|
||||||
|
|
||||||
|
import com.arialyy.aria.core.upload.UploadEntity;
|
||||||
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.orm.AbsWrapper;
|
import com.arialyy.aria.orm.AbsWrapper;
|
||||||
import com.arialyy.aria.orm.annotation.Many;
|
import com.arialyy.aria.orm.annotation.Many;
|
||||||
import com.arialyy.aria.orm.annotation.One;
|
import com.arialyy.aria.orm.annotation.One;
|
||||||
@@ -25,7 +27,7 @@ import java.util.List;
|
|||||||
* Created by laoyuyu on 2018/3/30.
|
* Created by laoyuyu on 2018/3/30.
|
||||||
*/
|
*/
|
||||||
@Wrapper
|
@Wrapper
|
||||||
public class UploadTaskWrapper extends AbsWrapper {
|
public class UTEWrapper extends AbsWrapper {
|
||||||
|
|
||||||
@One
|
@One
|
||||||
public UploadEntity entity;
|
public UploadEntity entity;
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
package com.arialyy.aria.orm;
|
package com.arialyy.aria.orm;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.arialyy.aria.core.ErrorEntity;
|
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
@@ -52,6 +51,5 @@ class DBConfig {
|
|||||||
mapping.put("UploadTaskEntity", UploadTaskEntity.class);
|
mapping.put("UploadTaskEntity", UploadTaskEntity.class);
|
||||||
mapping.put("DownloadEntity", DownloadEntity.class);
|
mapping.put("DownloadEntity", DownloadEntity.class);
|
||||||
mapping.put("UploadEntity", UploadEntity.class);
|
mapping.put("UploadEntity", UploadEntity.class);
|
||||||
mapping.put("ErrorEntity", ErrorEntity.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ import android.content.Context;
|
|||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.database.DatabaseErrorHandler;
|
import android.database.DatabaseErrorHandler;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Environment;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -36,52 +36,35 @@ class DatabaseContext extends ContextWrapper {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public File getDatabasePath(String name) {
|
public File getDatabasePath(String name) {
|
||||||
//判断是否存在sd卡
|
String dbDir = CommonUtil.getAppPath(getBaseContext());
|
||||||
boolean sdExist = android.os.Environment.MEDIA_MOUNTED.equals(
|
|
||||||
android.os.Environment.getExternalStorageState());
|
dbDir += "DB";//数据库所在目录
|
||||||
if (!sdExist) {
|
String dbPath = dbDir + "/" + name;//数据库路径
|
||||||
return null;
|
//判断目录是否存在,不存在则创建该目录
|
||||||
|
File dirFile = new File(dbDir);
|
||||||
|
if (!dirFile.exists()) {
|
||||||
|
dirFile.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据库文件是否创建成功
|
||||||
|
boolean isFileCreateSuccess = false;
|
||||||
|
//判断文件是否存在,不存在则创建该文件
|
||||||
|
File dbFile = new File(dbPath);
|
||||||
|
if (!dbFile.exists()) {
|
||||||
|
try {
|
||||||
|
isFileCreateSuccess = dbFile.createNewFile();//创建文件
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//获取sd卡路径
|
isFileCreateSuccess = true;
|
||||||
File file = getBaseContext().getExternalFilesDir(null);
|
}
|
||||||
String dbDir;
|
|
||||||
if (file != null) {
|
|
||||||
dbDir = file.getPath() + "/";
|
|
||||||
} else {
|
|
||||||
dbDir = Environment.getExternalStorageDirectory().getPath()
|
|
||||||
+ "/Android/data/"
|
|
||||||
+ getBaseContext().getPackageName()
|
|
||||||
+ "/files/";
|
|
||||||
}
|
|
||||||
|
|
||||||
dbDir += "DB";//数据库所在目录
|
//返回数据库文件对象
|
||||||
String dbPath = dbDir + "/" + name;//数据库路径
|
if (isFileCreateSuccess) {
|
||||||
//判断目录是否存在,不存在则创建该目录
|
return dbFile;
|
||||||
File dirFile = new File(dbDir);
|
} else {
|
||||||
if (!dirFile.exists()) {
|
return null;
|
||||||
dirFile.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
//数据库文件是否创建成功
|
|
||||||
boolean isFileCreateSuccess = false;
|
|
||||||
//判断文件是否存在,不存在则创建该文件
|
|
||||||
File dbFile = new File(dbPath);
|
|
||||||
if (!dbFile.exists()) {
|
|
||||||
try {
|
|
||||||
isFileCreateSuccess = dbFile.createNewFile();//创建文件
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
isFileCreateSuccess = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//返回数据库文件对象
|
|
||||||
if (isFileCreateSuccess) {
|
|
||||||
return dbFile;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -193,7 +192,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
update.insertData(db, entity);
|
update.insertData(db, entity);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ALog.e(TAG, CommonUtil.getPrintException(e));
|
ALog.e(TAG, ALog.getExceptionString(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.arialyy.aria.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Aria.Lao on 2017/10/25.
|
||||||
|
* 程序异常日志捕获器
|
||||||
|
*/
|
||||||
|
public class AriaCrashHandler implements Thread.UncaughtExceptionHandler {
|
||||||
|
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||||
|
private ExecutorService mExecutorService;
|
||||||
|
|
||||||
|
public AriaCrashHandler() {
|
||||||
|
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||||
|
mExecutorService = Executors.newSingleThreadExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread thread, Throwable ex) {
|
||||||
|
ALog.d(thread.getName(), ex.getLocalizedMessage());
|
||||||
|
handleException(thread.getName(), ex);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
mDefaultHandler.uncaughtException(thread, ex);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理异常
|
||||||
|
*/
|
||||||
|
private void handleException(final String name, final Throwable ex) {
|
||||||
|
if (ex == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mExecutorService.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ErrorHelp.saveError(name, "", ALog.getExceptionString(ex));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出当前应用
|
||||||
|
*/
|
||||||
|
private void exit() {
|
||||||
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
@@ -68,6 +69,33 @@ import java.util.regex.Pattern;
|
|||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
private static final String TAG = "CommonUtil";
|
private static final String TAG = "CommonUtil";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取sdcard app的缓存目录
|
||||||
|
*
|
||||||
|
* @return "/mnt/sdcard/Android/data/{package_name}/files/"
|
||||||
|
*/
|
||||||
|
public static String getAppPath(Context context) {
|
||||||
|
//判断是否存在sd卡
|
||||||
|
boolean sdExist = android.os.Environment.MEDIA_MOUNTED.equals(
|
||||||
|
android.os.Environment.getExternalStorageState());
|
||||||
|
if (!sdExist) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
//获取sd卡路径
|
||||||
|
File file = context.getExternalFilesDir(null);
|
||||||
|
String dir;
|
||||||
|
if (file != null) {
|
||||||
|
dir = file.getPath() + "/";
|
||||||
|
} else {
|
||||||
|
dir = Environment.getExternalStorageDirectory().getPath()
|
||||||
|
+ "/Android/data/"
|
||||||
|
+ context.getPackageName()
|
||||||
|
+ "/files/";
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取map泛型类型
|
* 获取map泛型类型
|
||||||
*
|
*
|
||||||
@@ -105,6 +133,7 @@ public class CommonUtil {
|
|||||||
* @param list list类型字段
|
* @param list list类型字段
|
||||||
* @return 泛型类型
|
* @return 泛型类型
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static Class getListParamType(Field list) {
|
public static Class getListParamType(Field list) {
|
||||||
Class type = list.getType();
|
Class type = list.getType();
|
||||||
if (!type.isAssignableFrom(List.class)) {
|
if (!type.isAssignableFrom(List.class)) {
|
||||||
@@ -788,34 +817,6 @@ public class CommonUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置打印的异常格式
|
|
||||||
*/
|
|
||||||
public static String getPrintException(Throwable ex) {
|
|
||||||
if (ex == null) return "";
|
|
||||||
StringBuilder err = new StringBuilder();
|
|
||||||
err.append("ExceptionDetailed:\n");
|
|
||||||
err.append("====================Exception Info====================\n");
|
|
||||||
err.append(ex.toString());
|
|
||||||
err.append("\n");
|
|
||||||
StackTraceElement[] stack = ex.getStackTrace();
|
|
||||||
for (StackTraceElement stackTraceElement : stack) {
|
|
||||||
err.append(stackTraceElement.toString()).append("\n");
|
|
||||||
}
|
|
||||||
Throwable cause = ex.getCause();
|
|
||||||
if (cause != null) {
|
|
||||||
err.append("【Caused by】: ");
|
|
||||||
err.append(cause.toString());
|
|
||||||
err.append("\n");
|
|
||||||
StackTraceElement[] stackTrace = cause.getStackTrace();
|
|
||||||
for (StackTraceElement stackTraceElement : stackTrace) {
|
|
||||||
err.append(stackTraceElement.toString()).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err.append("===================================================");
|
|
||||||
return err.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过文件名获取下载配置文件路径
|
* 通过文件名获取下载配置文件路径
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,11 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.util;
|
package com.arialyy.aria.util;
|
||||||
|
|
||||||
import com.arialyy.aria.core.ErrorEntity;
|
import android.annotation.SuppressLint;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
import java.io.File;
|
||||||
import com.arialyy.aria.core.inf.AbsEntity;
|
import java.io.FileWriter;
|
||||||
import com.arialyy.aria.core.upload.UploadEntity;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Aria.Lao on 2017/8/29.
|
* Created by Aria.Lao on 2017/8/29.
|
||||||
@@ -30,31 +33,71 @@ public class ErrorHelp {
|
|||||||
/**
|
/**
|
||||||
* 保存错误信息
|
* 保存错误信息
|
||||||
*
|
*
|
||||||
* @param taskType 任务类型
|
|
||||||
* @param entity 任务实体
|
|
||||||
* @param msg 错误提示
|
* @param msg 错误提示
|
||||||
* @param ex 异常
|
* @param ex 异常
|
||||||
*/
|
*/
|
||||||
// TODO: 2018/4/4 错误应该写在文件中
|
public static void saveError(String tag, String msg, String ex) {
|
||||||
@Deprecated
|
String message = "msg【" + msg + "】\nException:" + ex;
|
||||||
public static void saveError(String taskType, AbsEntity entity, String msg, String ex) {
|
writeLogToFile(tag, message);
|
||||||
ErrorEntity errorEntity = new ErrorEntity();
|
}
|
||||||
errorEntity.insertTime = System.currentTimeMillis();
|
|
||||||
errorEntity.err = ex;
|
|
||||||
errorEntity.msg = msg;
|
|
||||||
errorEntity.taskType = taskType;
|
|
||||||
String name = "";
|
|
||||||
String key = entity.getKey();
|
|
||||||
if (entity instanceof DownloadEntity) {
|
|
||||||
name = ((DownloadEntity) entity).getFileName();
|
|
||||||
} else if (entity instanceof DownloadGroupEntity) {
|
|
||||||
name = ((DownloadGroupEntity) entity).getGroupName();
|
|
||||||
} else if (entity instanceof UploadEntity) {
|
|
||||||
name = ((UploadEntity) entity).getFileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorEntity.taskName = name;
|
/**
|
||||||
errorEntity.key = key;
|
* 返回日志路径
|
||||||
errorEntity.insert();
|
*
|
||||||
|
* @return "/mnt/sdcard/Android/data/{package_name}/files/log/*"
|
||||||
|
*/
|
||||||
|
private static String getLogPath() {
|
||||||
|
String path = android.os.Environment.getExternalStorageDirectory().getPath()
|
||||||
|
+ "/"
|
||||||
|
+ CommonUtil.getAppPath(AriaManager.APP)
|
||||||
|
+ "/log/AriaCrash_"
|
||||||
|
+ getData("yyyy-MM-dd")
|
||||||
|
+ ".log";
|
||||||
|
|
||||||
|
File log = new File(path);
|
||||||
|
if (!log.getParentFile().exists()) {
|
||||||
|
log.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
if (!log.exists()) {
|
||||||
|
try {
|
||||||
|
log.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把日志记录到文件
|
||||||
|
*/
|
||||||
|
private static int writeLogToFile(String tag, String message) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append(getData("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
stringBuffer.append(" ");
|
||||||
|
stringBuffer.append(tag);
|
||||||
|
stringBuffer.append(" ");
|
||||||
|
stringBuffer.append(message);
|
||||||
|
stringBuffer.append("\n\n");
|
||||||
|
PrintWriter writer = null;
|
||||||
|
try {
|
||||||
|
writer = new PrintWriter(new FileWriter(getLogPath(), true));
|
||||||
|
writer.append(stringBuffer);
|
||||||
|
writer.flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
private static String getData(String format) {
|
||||||
|
Date date = new Date(System.currentTimeMillis());
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||||
|
return sdf.format(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,10 +15,10 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<!--android:name=".MainActivity"-->
|
<!--android:name=".MainActivity"-->
|
||||||
<!--android:name=".test.AnyRunActivity"-->
|
|
||||||
<!--android:name=".test.TestGroupActivity"-->
|
<!--android:name=".test.TestGroupActivity"-->
|
||||||
|
<!--android:name=".test.TestActivity"-->
|
||||||
<activity
|
<activity
|
||||||
android:name=".test.TestActivity"
|
android:name=".test.AnyRunActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<aria>
|
<aria>
|
||||||
|
|
||||||
|
<app>
|
||||||
|
<!--是否使用AriaCrashHandler来捕获异常,异常日志保存在:/mnt/sdcard/Android/data/{package_name}/files/log/-->
|
||||||
|
<useAriaCrashHandler value="true"/>
|
||||||
|
<!--设置Aria的日志级别,{@link ALog#LOG_LEVEL_VERBOSE}-->
|
||||||
|
<logLevel value="2"/>
|
||||||
|
</app>
|
||||||
|
|
||||||
|
|
||||||
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
||||||
<download>
|
<download>
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onMenuItemClick(MenuItem item) {
|
@Override public boolean onMenuItemClick(MenuItem item) {
|
||||||
double speed = -1;
|
int speed = -1;
|
||||||
String msg = "";
|
String msg = "";
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.help:
|
case R.id.help:
|
||||||
@@ -83,19 +83,19 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
showMsgDialog("tip", msg);
|
showMsgDialog("tip", msg);
|
||||||
break;
|
break;
|
||||||
case R.id.speed_0:
|
case R.id.speed_0:
|
||||||
speed = 0.0;
|
speed = 0;
|
||||||
break;
|
break;
|
||||||
case R.id.speed_128:
|
case R.id.speed_128:
|
||||||
speed = 128.0;
|
speed = 128;
|
||||||
break;
|
break;
|
||||||
case R.id.speed_256:
|
case R.id.speed_256:
|
||||||
speed = 256.0;
|
speed = 256;
|
||||||
break;
|
break;
|
||||||
case R.id.speed_512:
|
case R.id.speed_512:
|
||||||
speed = 512.0;
|
speed = 512;
|
||||||
break;
|
break;
|
||||||
case R.id.speed_1m:
|
case R.id.speed_1m:
|
||||||
speed = 1024.0;
|
speed = 1024;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (speed > -1) {
|
if (speed > -1) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.arialyy.simple.test;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivityTestBinding;
|
import com.arialyy.simple.databinding.ActivityTestBinding;
|
||||||
@@ -12,6 +13,8 @@ import com.arialyy.simple.databinding.ActivityTestBinding;
|
|||||||
|
|
||||||
public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||||
AnyRunnModule module;
|
AnyRunnModule module;
|
||||||
|
String[] urls;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
@Override protected int setLayoutId() {
|
||||||
return R.layout.activity_test;
|
return R.layout.activity_test;
|
||||||
@@ -19,14 +22,20 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
|||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
|
Aria.init(this);
|
||||||
mBar.setVisibility(View.GONE);
|
mBar.setVisibility(View.GONE);
|
||||||
module = new AnyRunnModule(this);
|
module = new AnyRunnModule(this);
|
||||||
|
urls = getResources().getStringArray(R.array.group_urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.start:
|
case R.id.start:
|
||||||
module.start();
|
//module.start();
|
||||||
|
if (index < urls.length) {
|
||||||
|
module.start(urls[index]);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.stop:
|
case R.id.stop:
|
||||||
module.stop();
|
module.stop();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class AnyRunnModule {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
public AnyRunnModule(Context context) {
|
public AnyRunnModule(Context context) {
|
||||||
Aria.download(context, this).register();
|
Aria.download(this).register();
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class AnyRunnModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
Aria.download(mContext, this)
|
Aria.download(this)
|
||||||
.load(URL)
|
.load(URL)
|
||||||
.addHeader("Accept-Encoding", "gzip, deflate")
|
.addHeader("Accept-Encoding", "gzip, deflate")
|
||||||
.setRequestMode(RequestEnum.GET)
|
.setRequestMode(RequestEnum.GET)
|
||||||
@@ -72,15 +72,25 @@ public class AnyRunnModule {
|
|||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start(String url) {
|
||||||
|
Aria.download(this)
|
||||||
|
.load(url)
|
||||||
|
.addHeader("Accept-Encoding", "gzip, deflate")
|
||||||
|
.setRequestMode(RequestEnum.GET)
|
||||||
|
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||||
|
.resetState()
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
Aria.download(mContext, this).load(URL).stop();
|
Aria.download(this).load(URL).stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancel() {
|
void cancel() {
|
||||||
Aria.download(mContext, this).load(URL).cancel();
|
Aria.download(this).load(URL).cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unRegist() {
|
void unRegist() {
|
||||||
Aria.download(mContext, this).unRegister();
|
Aria.download(this).unRegister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import com.arialyy.annotations.Upload;
|
import com.arialyy.annotations.Upload;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
|
import com.arialyy.aria.core.common.RequestEnum;
|
||||||
import com.arialyy.aria.core.upload.UploadTask;
|
import com.arialyy.aria.core.upload.UploadTask;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
@@ -20,7 +21,7 @@ public class TestActivity extends BaseActivity<ActivityTestBinding> {
|
|||||||
String TAG = "TestActivity";
|
String TAG = "TestActivity";
|
||||||
//String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
//String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||||
//private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
|
//private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
|
||||||
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar";
|
private final String FILE_PATH = "/mnt/sdcard/SDK_Demo-release.apk";
|
||||||
//private final String URL = "ftp://192.168.29.140:21/aa//你好";
|
//private final String URL = "ftp://192.168.29.140:21/aa//你好";
|
||||||
private final String URL = "http://192.168.29.140:5000/upload/";
|
private final String URL = "http://192.168.29.140:5000/upload/";
|
||||||
|
|
||||||
@@ -73,7 +74,13 @@ public class TestActivity extends BaseActivity<ActivityTestBinding> {
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.start:
|
case R.id.start:
|
||||||
Aria.upload(this).load(FILE_PATH).setUploadUrl(URL).setExtendField("韩寒哈大双").setAttachment("file").start();
|
Aria.upload(this)
|
||||||
|
.load(FILE_PATH)
|
||||||
|
.setUploadUrl(URL)
|
||||||
|
.setRequestMode(RequestEnum.POST)
|
||||||
|
.setExtendField("韩寒哈大双")
|
||||||
|
.setAttachment("file")
|
||||||
|
.start();
|
||||||
break;
|
break;
|
||||||
case R.id.stop:
|
case R.id.stop:
|
||||||
Aria.upload(this).load(FILE_PATH).stop();
|
Aria.upload(this).load(FILE_PATH).stop();
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ import com.arialyy.aria.core.common.QueueMod;
|
|||||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
|
import com.arialyy.aria.util.AriaCrashHandler;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import com.arialyy.aria.util.ErrorHelp;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -32,14 +34,147 @@ import java.util.Properties;
|
|||||||
* 信息配置
|
* 信息配置
|
||||||
*/
|
*/
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
static final String TAG = "Configuration";
|
||||||
static final String DOWNLOAD_CONFIG_FILE = "/Aria/DownloadConfig.properties";
|
static final String DOWNLOAD_CONFIG_FILE = "/Aria/DownloadConfig.properties";
|
||||||
static final String UPLOAD_CONFIG_FILE = "/Aria/UploadConfig.properties";
|
static final String UPLOAD_CONFIG_FILE = "/Aria/UploadConfig.properties";
|
||||||
|
static final String APP_CONFIG_FILE = "/Aria/AppConfig.properties";
|
||||||
static final String XML_FILE = "/Aria/aria_config.xml";
|
static final String XML_FILE = "/Aria/aria_config.xml";
|
||||||
|
static final int TYPE_DOWNLOAD = 1;
|
||||||
|
static final int TYPE_UPLOAD = 2;
|
||||||
|
static final int TYPE_APP = 3;
|
||||||
|
|
||||||
|
abstract static class BaseConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*
|
||||||
|
* @return {@link #TYPE_DOWNLOAD}、{@link #TYPE_UPLOAD}、{@link #TYPE_APP}
|
||||||
|
*/
|
||||||
|
abstract int getType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载配置
|
||||||
|
*/
|
||||||
|
void loadConfig() {
|
||||||
|
String path = null;
|
||||||
|
Class clazz = null;
|
||||||
|
switch (getType()) {
|
||||||
|
case TYPE_DOWNLOAD:
|
||||||
|
path = DOWNLOAD_CONFIG_FILE;
|
||||||
|
clazz = DownloadConfig.class;
|
||||||
|
break;
|
||||||
|
case TYPE_UPLOAD:
|
||||||
|
path = UPLOAD_CONFIG_FILE;
|
||||||
|
clazz = UploadConfig.class;
|
||||||
|
break;
|
||||||
|
case TYPE_APP:
|
||||||
|
path = APP_CONFIG_FILE;
|
||||||
|
clazz = AppConfig.class;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(path)) {
|
||||||
|
ALog.e(TAG, "读取配置失败:未知文件类型");
|
||||||
|
ErrorHelp.saveError(TAG, "读取配置失败:未知文件类型", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(AriaManager.APP.getFilesDir().getPath() + path);
|
||||||
|
if (file.exists()) {
|
||||||
|
Properties properties = CommonUtil.loadConfig(file);
|
||||||
|
List<Field> fields = CommonUtil.getAllFields(clazz);
|
||||||
|
try {
|
||||||
|
for (Field field : fields) {
|
||||||
|
int m = field.getModifiers();
|
||||||
|
String fileName = field.getName();
|
||||||
|
if (fileName.equals("oldMaxTaskNum")
|
||||||
|
|| field.isSynthetic()
|
||||||
|
|| Modifier.isFinal(m)
|
||||||
|
|| Modifier.isStatic(m)
|
||||||
|
|| fileName.equals("shadow$_klass_")
|
||||||
|
|| fileName.equals("shadow$_monitor_")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
String value = properties.getProperty(field.getName());
|
||||||
|
if (TextUtils.isEmpty(value) || value.equalsIgnoreCase("null")) continue;
|
||||||
|
Class<?> type = field.getType();
|
||||||
|
if (type == String.class) {
|
||||||
|
field.set(this, value);
|
||||||
|
} else if (type == int.class || type == Integer.class) {
|
||||||
|
if (fileName.equalsIgnoreCase("maxSpeed")) { //兼容以前版本,以前maxSpeed是double类型的
|
||||||
|
Double d = Double.parseDouble(value);
|
||||||
|
field.setInt(this, (int) d.doubleValue());
|
||||||
|
} else {
|
||||||
|
field.setInt(this, Integer.parseInt(value));
|
||||||
|
}
|
||||||
|
} else if (type == float.class || type == Float.class) {
|
||||||
|
field.setFloat(this, Float.parseFloat(value));
|
||||||
|
} else if (type == double.class || type == Double.class) {
|
||||||
|
if (TextUtils.isEmpty(value)) {
|
||||||
|
value = "0.0";
|
||||||
|
}
|
||||||
|
field.setDouble(this, Double.parseDouble(value));
|
||||||
|
} else if (type == long.class || type == Long.class) {
|
||||||
|
field.setLong(this, Long.parseLong(value));
|
||||||
|
} else if (type == boolean.class || type == Boolean.class) {
|
||||||
|
field.setBoolean(this, Boolean.parseBoolean(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存key
|
||||||
|
*/
|
||||||
|
void saveKey(String key, String value) {
|
||||||
|
boolean isDownload = this instanceof DownloadConfig;
|
||||||
|
File file = new File(
|
||||||
|
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
||||||
|
: UPLOAD_CONFIG_FILE));
|
||||||
|
if (file.exists()) {
|
||||||
|
Properties properties = CommonUtil.loadConfig(file);
|
||||||
|
properties.setProperty(key, value);
|
||||||
|
CommonUtil.saveConfig(file, properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存配置
|
||||||
|
*/
|
||||||
|
void saveAll() {
|
||||||
|
List<Field> fields = CommonUtil.getAllFields(getClass());
|
||||||
|
boolean isDownload = this instanceof DownloadConfig;
|
||||||
|
try {
|
||||||
|
File file = new File(
|
||||||
|
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
||||||
|
: UPLOAD_CONFIG_FILE));
|
||||||
|
Properties properties = CommonUtil.loadConfig(file);
|
||||||
|
for (Field field : fields) {
|
||||||
|
int m = field.getModifiers();
|
||||||
|
if (field.isSynthetic()
|
||||||
|
|| Modifier.isFinal(m)
|
||||||
|
|| Modifier.isStatic(m)
|
||||||
|
|| field.getName().equals("shadow$_klass_")
|
||||||
|
|| field.getName().equals("shadow$_monitor_")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
field.setAccessible(true);
|
||||||
|
properties.setProperty(field.getName(), field.get(this) + "");
|
||||||
|
}
|
||||||
|
CommonUtil.saveConfig(file, properties);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用配置
|
* 通用任务配置
|
||||||
*/
|
*/
|
||||||
public static class BaseConfig {
|
abstract static class BaseTaskConfig extends BaseConfig {
|
||||||
/**
|
/**
|
||||||
* 进度刷新间隔,默认1秒
|
* 进度刷新间隔,默认1秒
|
||||||
*/
|
*/
|
||||||
@@ -88,7 +223,7 @@ class Configuration {
|
|||||||
*
|
*
|
||||||
* @param updateInterval 不能小于0
|
* @param updateInterval 不能小于0
|
||||||
*/
|
*/
|
||||||
public BaseConfig setUpdateInterval(long updateInterval) {
|
public BaseTaskConfig setUpdateInterval(long updateInterval) {
|
||||||
if (updateInterval <= 0) {
|
if (updateInterval <= 0) {
|
||||||
ALog.w("Configuration", "进度更新间隔不能小于0");
|
ALog.w("Configuration", "进度更新间隔不能小于0");
|
||||||
return this;
|
return this;
|
||||||
@@ -102,7 +237,7 @@ class Configuration {
|
|||||||
return queueMod;
|
return queueMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseConfig setQueueMod(String queueMod) {
|
public BaseTaskConfig setQueueMod(String queueMod) {
|
||||||
this.queueMod = queueMod;
|
this.queueMod = queueMod;
|
||||||
saveKey("queueMod", queueMod);
|
saveKey("queueMod", queueMod);
|
||||||
return this;
|
return this;
|
||||||
@@ -116,9 +251,9 @@ class Configuration {
|
|||||||
return reTryNum;
|
return reTryNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseConfig setReTryNum(int reTryNum) {
|
public BaseTaskConfig setReTryNum(int reTryNum) {
|
||||||
this.reTryNum = reTryNum;
|
this.reTryNum = reTryNum;
|
||||||
saveKey("reTryNum", reTryNum + "");
|
saveKey("reTryNum", String.valueOf(reTryNum));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +261,9 @@ class Configuration {
|
|||||||
return reTryInterval;
|
return reTryInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseConfig setReTryInterval(int reTryInterval) {
|
public BaseTaskConfig setReTryInterval(int reTryInterval) {
|
||||||
this.reTryInterval = reTryInterval;
|
this.reTryInterval = reTryInterval;
|
||||||
saveKey("reTryInterval", reTryInterval + "");
|
saveKey("reTryInterval", String.valueOf(reTryInterval));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,9 +271,9 @@ class Configuration {
|
|||||||
return isConvertSpeed;
|
return isConvertSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseConfig setConvertSpeed(boolean convertSpeed) {
|
public BaseTaskConfig setConvertSpeed(boolean convertSpeed) {
|
||||||
isConvertSpeed = convertSpeed;
|
isConvertSpeed = convertSpeed;
|
||||||
saveKey("isConvertSpeed", isConvertSpeed + "");
|
saveKey("isConvertSpeed", String.valueOf(isConvertSpeed));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,108 +281,17 @@ class Configuration {
|
|||||||
return connectTimeOut;
|
return connectTimeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseConfig setConnectTimeOut(int connectTimeOut) {
|
public BaseTaskConfig setConnectTimeOut(int connectTimeOut) {
|
||||||
this.connectTimeOut = connectTimeOut;
|
this.connectTimeOut = connectTimeOut;
|
||||||
saveKey("connectTimeOut", connectTimeOut + "");
|
saveKey("connectTimeOut", String.valueOf(connectTimeOut));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存key
|
|
||||||
*/
|
|
||||||
void saveKey(String key, String value) {
|
|
||||||
boolean isDownload = this instanceof DownloadConfig;
|
|
||||||
File file = new File(
|
|
||||||
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
|
||||||
: UPLOAD_CONFIG_FILE));
|
|
||||||
if (file.exists()) {
|
|
||||||
Properties properties = CommonUtil.loadConfig(file);
|
|
||||||
properties.setProperty(key, value);
|
|
||||||
CommonUtil.saveConfig(file, properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载配置
|
|
||||||
*/
|
|
||||||
void loadConfig() {
|
|
||||||
boolean isDownload = this instanceof DownloadConfig;
|
|
||||||
File file = new File(
|
|
||||||
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
|
||||||
: UPLOAD_CONFIG_FILE));
|
|
||||||
if (file.exists()) {
|
|
||||||
Properties properties = CommonUtil.loadConfig(file);
|
|
||||||
List<Field> fields =
|
|
||||||
CommonUtil.getAllFields(isDownload ? DownloadConfig.class : UploadConfig.class);
|
|
||||||
try {
|
|
||||||
for (Field field : fields) {
|
|
||||||
int m = field.getModifiers();
|
|
||||||
String fileName = field.getName();
|
|
||||||
if (fileName.equals("oldMaxTaskNum")
|
|
||||||
|| field.isSynthetic()
|
|
||||||
|| Modifier.isFinal(m)
|
|
||||||
|| Modifier.isStatic(m)
|
|
||||||
|| fileName.equals("shadow$_klass_")
|
|
||||||
|| fileName.equals("shadow$_monitor_")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
field.setAccessible(true);
|
|
||||||
String value = properties.getProperty(field.getName());
|
|
||||||
if (TextUtils.isEmpty(value) || value.equalsIgnoreCase("null")) continue;
|
|
||||||
Class<?> type = field.getType();
|
|
||||||
if (type == String.class) {
|
|
||||||
field.set(this, value);
|
|
||||||
} else if (type == int.class || type == Integer.class) {
|
|
||||||
field.setInt(this, Integer.parseInt(value));
|
|
||||||
} else if (type == float.class || type == Float.class) {
|
|
||||||
field.setFloat(this, Float.parseFloat(value));
|
|
||||||
} else if (type == double.class || type == Double.class) {
|
|
||||||
if (TextUtils.isEmpty(value)) {
|
|
||||||
value = "0.0";
|
|
||||||
}
|
|
||||||
field.setDouble(this, Double.parseDouble(value));
|
|
||||||
} else if (type == long.class || type == Long.class) {
|
|
||||||
field.setLong(this, Long.parseLong(value));
|
|
||||||
} else if (type == boolean.class || type == Boolean.class) {
|
|
||||||
field.setBoolean(this, Boolean.parseBoolean(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存配置
|
|
||||||
*/
|
|
||||||
void saveAll() {
|
|
||||||
List<Field> fields = CommonUtil.getAllFields(getClass());
|
|
||||||
boolean isDownload = this instanceof DownloadConfig;
|
|
||||||
try {
|
|
||||||
File file = new File(
|
|
||||||
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
|
||||||
: UPLOAD_CONFIG_FILE));
|
|
||||||
Properties properties = CommonUtil.loadConfig(file);
|
|
||||||
for (Field field : fields) {
|
|
||||||
int m = field.getModifiers();
|
|
||||||
if (Modifier.isFinal(m) || Modifier.isStatic(m)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
field.setAccessible(true);
|
|
||||||
properties.setProperty(field.getName(), field.get(this) + "");
|
|
||||||
}
|
|
||||||
CommonUtil.saveConfig(file, properties);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载配置
|
* 下载配置
|
||||||
*/
|
*/
|
||||||
public static class DownloadConfig extends BaseConfig {
|
public static class DownloadConfig extends BaseTaskConfig {
|
||||||
/**
|
/**
|
||||||
* 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
|
* 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
|
||||||
*/
|
*/
|
||||||
@@ -272,12 +316,12 @@ class Configuration {
|
|||||||
/**
|
/**
|
||||||
* 设置最大下载速度,单位:kb, 为0表示不限速
|
* 设置最大下载速度,单位:kb, 为0表示不限速
|
||||||
*/
|
*/
|
||||||
double msxSpeed = 0.0;
|
int msxSpeed = 0;
|
||||||
|
|
||||||
public DownloadConfig setMaxTaskNum(int maxTaskNum) {
|
public DownloadConfig setMaxTaskNum(int maxTaskNum) {
|
||||||
oldMaxTaskNum = this.maxTaskNum;
|
oldMaxTaskNum = this.maxTaskNum;
|
||||||
this.maxTaskNum = maxTaskNum;
|
this.maxTaskNum = maxTaskNum;
|
||||||
saveKey("maxTaskNum", maxTaskNum + "");
|
saveKey("maxTaskNum", String.valueOf(maxTaskNum));
|
||||||
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
|
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -286,11 +330,11 @@ class Configuration {
|
|||||||
return iOTimeOut;
|
return iOTimeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMsxSpeed() {
|
public int getMsxSpeed() {
|
||||||
return msxSpeed;
|
return msxSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadConfig setMsxSpeed(double msxSpeed) {
|
public DownloadConfig setMsxSpeed(int msxSpeed) {
|
||||||
this.msxSpeed = msxSpeed;
|
this.msxSpeed = msxSpeed;
|
||||||
saveKey("msxSpeed", String.valueOf(msxSpeed));
|
saveKey("msxSpeed", String.valueOf(msxSpeed));
|
||||||
DownloadTaskQueue.getInstance().setMaxSpeed(msxSpeed);
|
DownloadTaskQueue.getInstance().setMaxSpeed(msxSpeed);
|
||||||
@@ -304,7 +348,7 @@ class Configuration {
|
|||||||
|
|
||||||
public DownloadConfig setIOTimeOut(int iOTimeOut) {
|
public DownloadConfig setIOTimeOut(int iOTimeOut) {
|
||||||
this.iOTimeOut = iOTimeOut;
|
this.iOTimeOut = iOTimeOut;
|
||||||
saveKey("iOTimeOut", iOTimeOut + "");
|
saveKey("iOTimeOut", String.valueOf(iOTimeOut));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +358,7 @@ class Configuration {
|
|||||||
|
|
||||||
public DownloadConfig setBuffSize(int buffSize) {
|
public DownloadConfig setBuffSize(int buffSize) {
|
||||||
this.buffSize = buffSize;
|
this.buffSize = buffSize;
|
||||||
saveKey("buffSize", buffSize + "");
|
saveKey("buffSize", String.valueOf(buffSize));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,23 +400,26 @@ class Configuration {
|
|||||||
}
|
}
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override int getType() {
|
||||||
|
return TYPE_DOWNLOAD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传配置
|
* 上传配置
|
||||||
*/
|
*/
|
||||||
public static class UploadConfig extends BaseConfig {
|
public static class UploadConfig extends BaseTaskConfig {
|
||||||
|
private static UploadConfig INSTANCE = null;
|
||||||
|
|
||||||
private UploadConfig() {
|
private UploadConfig() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UploadConfig INSTANCE = null;
|
|
||||||
|
|
||||||
public UploadConfig setMaxTaskNum(int maxTaskNum) {
|
public UploadConfig setMaxTaskNum(int maxTaskNum) {
|
||||||
oldMaxTaskNum = this.maxTaskNum;
|
oldMaxTaskNum = this.maxTaskNum;
|
||||||
this.maxTaskNum = maxTaskNum;
|
this.maxTaskNum = maxTaskNum;
|
||||||
saveKey("maxTaskNum", maxTaskNum + "");
|
saveKey("maxTaskNum", String.valueOf(maxTaskNum));
|
||||||
UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
|
UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -385,5 +432,71 @@ class Configuration {
|
|||||||
}
|
}
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override int getType() {
|
||||||
|
return TYPE_UPLOAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用配置
|
||||||
|
*/
|
||||||
|
public static class AppConfig extends BaseConfig {
|
||||||
|
private static AppConfig INSTANCE = null;
|
||||||
|
/**
|
||||||
|
* 是否使用{@link AriaCrashHandler}来捕获异常
|
||||||
|
* {@code true} 使用;{@code false} 不使用
|
||||||
|
*/
|
||||||
|
Boolean useAriaCrashHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置Aria的日志级别
|
||||||
|
*
|
||||||
|
* {@link ALog#LOG_LEVEL_VERBOSE}
|
||||||
|
*/
|
||||||
|
int logLevel;
|
||||||
|
|
||||||
|
AppConfig() {
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
static AppConfig getInstance() {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
synchronized (AppConfig.class) {
|
||||||
|
INSTANCE = new AppConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppConfig setLogLevel(int level) {
|
||||||
|
this.logLevel = level;
|
||||||
|
ALog.LOG_LEVEL = level;
|
||||||
|
saveKey("logLevel", String.valueOf(logLevel));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLogLevel() {
|
||||||
|
return logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUseAriaCrashHandler() {
|
||||||
|
return useAriaCrashHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppConfig setUseAriaCrashHandler(Boolean useAriaCrashHandler) {
|
||||||
|
this.useAriaCrashHandler = useAriaCrashHandler;
|
||||||
|
saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler));
|
||||||
|
if (useAriaCrashHandler) {
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler());
|
||||||
|
} else {
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(null);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override int getType() {
|
||||||
|
return TYPE_APP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user