From 56af75c35c70f9a97cc4d931cd1b23dfafa35d1e Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 21 Jan 2019 20:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=81=E5=A2=9E=E5=8A=A0=E7=BB=84=E5=90=88=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E9=98=9F=E5=88=97=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/jcenter.gradle | 2 +- .../com/arialyy/aria/core/AriaManager.java | 23 +- .../com/arialyy/aria/core/ConfigHelper.java | 365 +++++---------- .../arialyy/aria/core/ConfigHelper.java.back | 441 ++++++++++++++++++ .../com/arialyy/aria/core/ConfigType.java | 4 +- .../com/arialyy/aria/core/command/AbsCmd.java | 4 +- .../core/command/normal/AbsNormalCmd.java | 3 +- .../core/command/normal/ResumeAllCmd.java | 55 +-- .../aria/core/command/normal/StartCmd.java | 3 - .../arialyy/aria/core/common/AbsFileer.java | 87 ++-- .../arialyy/aria/core/common/TaskRecord.java | 6 +- .../aria/core/download/BaseGroupTarget.java | 5 +- .../aria/core/download/BaseNormalTarget.java | 2 - .../aria/core/download/DGEntityWrapper.java | 2 +- .../aria/core/download/DGTaskWrapper.java | 11 +- .../aria/core/download/DTaskWrapper.java | 37 +- .../aria/core/download/DownloadEntity.java | 20 +- .../core/download/DownloadGroupEntity.java | 4 +- .../core/download/DownloadGroupTarget.java | 12 +- .../aria/core/download/DownloadGroupTask.java | 2 +- .../aria/core/download/DownloadReceiver.java | 6 +- .../core/download/FtpDirDownloadTarget.java | 4 +- .../download/downloader/AbsGroupUtil.java | 20 +- .../downloader/DownloadGroupUtil.java | 4 +- .../core/download/downloader/Downloader.java | 10 +- .../download/downloader/FtpDirInfoThread.java | 16 +- .../download/downloader/FtpThreadTask.java | 2 +- .../downloader/HttpFileInfoThread.java | 1 - .../download/downloader/HttpThreadTask.java | 2 +- .../com/arialyy/aria/core/inf/AbsEntity.java | 4 + .../arialyy/aria/core/inf/AbsGroupEntity.java | 12 +- .../arialyy/aria/core/inf/AbsTaskWrapper.java | 3 +- .../core/manager/DGTaskWrapperFactory.java | 14 +- .../core/manager/DTaskWrapperFactory.java | 7 +- .../aria/core/manager/IGTEFactory.java | 4 +- .../aria/core/manager/TaskWrapperManager.java | 8 +- .../core/manager/UTaskWrapperFactory.java | 4 +- .../arialyy/aria/core/queue/AbsTaskQueue.java | 45 +- .../core/queue/DownloadGroupTaskQueue.java | 11 +- .../aria/core/queue/DownloadTaskQueue.java | 8 +- .../arialyy/aria/core/queue/ITaskQueue.java | 30 +- .../aria/core/queue/UploadTaskQueue.java | 11 +- .../aria/core/queue/pool/BaseCachePool.java | 11 +- .../aria/core/queue/pool/BaseExecutePool.java | 7 +- .../arialyy/aria/core/queue/pool/IPool.java | 20 +- .../aria/core/scheduler/AbsSchedulers.java | 24 +- .../aria/core/upload/BaseNormalTarget.java | 1 - .../aria/core/upload/UTaskWrapper.java | 21 +- .../core/upload/uploader/FtpThreadTask.java | 2 +- .../core/upload/uploader/HttpThreadTask.java | 2 +- .../aria/core/upload/uploader/Uploader.java | 6 +- .../java/com/arialyy/aria/orm/DBConfig.java | 5 +- .../com/arialyy/aria/orm/DelegateFind.java | 2 +- .../com/arialyy/aria/util/CommonUtil.java | 2 +- .../com/arialyy/aria/util/DbDataHelper.java | 24 +- .../arialyy/annotations/DownloadGroup.java | 8 +- DEV_LOG.md | 5 +- app/src/main/assets/aria_config.xml | 71 ++- .../com/arialyy/simple/DbTestActivity.java | 2 - .../simple/download/KotlinDownloadActivity.kt | 2 +- .../download/group/ChildHandleDialog.java | 7 +- .../multi_download/DownloadAdapter.java | 2 +- .../com/arialyy/aria/core/Configuration.java | 220 ++++++--- 63 files changed, 1104 insertions(+), 654 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back diff --git a/Aria/jcenter.gradle b/Aria/jcenter.gradle index 8ce3129a..5d0a7f24 100644 --- a/Aria/jcenter.gradle +++ b/Aria/jcenter.gradle @@ -76,7 +76,7 @@ artifacts { //################################# jcenter 上传配置 start ######################################### bintray { // user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER") -// groupName = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY") +// groupHash = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY") user = BINTRAY_USER key = BINTRAY_KEY configurations = ['archives'] diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index f151c382..6c1eca6f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -30,15 +30,12 @@ import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; -import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DownloadReceiver; -import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.ReceiverType; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadReceiver; -import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DelegateWrapper; import com.arialyy.aria.util.ALog; @@ -78,6 +75,7 @@ import org.xml.sax.SAXException; private Configuration.DownloadConfig mDConfig; private Configuration.UploadConfig mUConfig; private Configuration.AppConfig mAConfig; + private Configuration.DGroupConfig mDGConfig; private AriaManager(Context context) { APP = context.getApplicationContext(); @@ -127,8 +125,7 @@ import org.xml.sax.SAXException; */ private void amendTaskState() { Class[] clazzs = new Class[] { - DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class, - DTaskWrapper.class, UTaskWrapper.class, DGTaskWrapper.class + DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class }; String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)"; for (Class clazz : clazzs) { @@ -206,6 +203,19 @@ import org.xml.sax.SAXException; return mAConfig; } + /** + * 如果需要在代码中修改下载类型的组合任务的配置,请使用以下方法 + *
+ *
+ * //修改最大任务队列数
+ * Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
+ *
+ *
+ */
+ public Configuration.DGroupConfig getDGroupConfig(){
+ return mDGConfig;
+ }
+
/**
* 设置命令
*/
@@ -268,7 +278,7 @@ import org.xml.sax.SAXException;
DbEntity.deleteData(DownloadEntity.class, "url=? and isGroupChild='false'", key);
break;
case 2:
- DbEntity.deleteData(DownloadGroupEntity.class, "groupName=?", key);
+ DbEntity.deleteData(DownloadGroupEntity.class, "groupHash=?", key);
break;
case 3:
DbEntity.deleteData(UploadEntity.class, "filePath=?", key);
@@ -379,6 +389,7 @@ import org.xml.sax.SAXException;
mDConfig = Configuration.getInstance().downloadCfg;
mUConfig = Configuration.getInstance().uploadCfg;
mAConfig = Configuration.getInstance().appCfg;
+ mDGConfig = Configuration.getInstance().dGroupCfg;
File xmlFile = new File(APP.getFilesDir().getPath() + Configuration.XML_FILE);
File tempDir = new File(APP.getFilesDir().getPath() + "/temp");
diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
index e5feef66..ff5d851c 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
@@ -17,6 +17,9 @@ package com.arialyy.aria.core;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
+import com.arialyy.aria.util.CommonUtil;
+import java.lang.reflect.Field;
+import javax.xml.validation.Validator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -30,6 +33,7 @@ class ConfigHelper extends DefaultHandler {
private Configuration.DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg;
private Configuration.UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg;
private Configuration.AppConfig mAppConfig = Configuration.getInstance().appCfg;
+ private Configuration.DGroupConfig mDGroupConfig = Configuration.getInstance().dGroupCfg;
private @ConfigType int mType;
@Override public void startDocument() throws SAXException {
@@ -50,281 +54,165 @@ class ConfigHelper extends DefaultHandler {
case "app":
mType = ConfigType.APP;
break;
+ case "dGroup":
+ mType = ConfigType.D_GROUP;
+ break;
}
- if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD) {
+ if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD || mType == ConfigType.D_GROUP) {
String value = attributes.getValue("value");
switch (qName) {
- case "threadNum":
- loadThreadNum(value);
- break;
- case "maxTaskNum":
- loadMaxQueue(value);
+ case "threadNum": // 线程数
+ int threadNum = checkInt(value) ? Integer.parseInt(value) : 3;
+ if (threadNum < 1) {
+ ALog.w(TAG, "下载线程数不能小于 1");
+ threadNum = 1;
+ }
+ setField("threadNum", threadNum, ConfigType.DOWNLOAD);
break;
- case "reTryNum":
- loadReTry(value);
+ case "maxTaskNum": //最大任务书
+ int maxTaskNum = checkInt(value) ? Integer.parseInt(value) : 2;
+ if (maxTaskNum < 1) {
+ ALog.w(TAG, "任务队列数不能小于 1");
+ maxTaskNum = 2;
+ }
+ setField("maxTaskNum", maxTaskNum, getAllTaskType());
break;
- case "connectTimeOut":
- loadConnectTime(value);
+ case "reTryNum": //任务重试次数
+ setField("reTryNum", checkInt(value) ? Integer.parseInt(value) : 0, getAllTaskType());
break;
- case "iOTimeOut":
- loadIOTimeout(value);
+ case "connectTimeOut": // 连接超时时间
+ setField("connectTimeOut", checkInt(value) ? Integer.parseInt(value) : 5 * 1000,
+ getAllTaskType());
break;
- case "reTryInterval":
- loadReTryInterval(value);
+ case "iOTimeOut": //io流超时时间
+ int iOTimeOut = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
+ if (iOTimeOut < 10 * 1000) {
+ iOTimeOut = 10 * 1000;
+ }
+ setField("iOTimeOut", iOTimeOut, getAllTaskType());
break;
- case "buffSize":
- loadBuffSize(value);
+ case "reTryInterval": //失败重试间隔
+ int reTryInterval = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
+
+ if (reTryInterval < 2 * 1000) {
+ reTryInterval = 2 * 1000;
+ }
+ setField("reTryInterval", reTryInterval, getAllTaskType());
break;
- case "useBroadcast":
- loadUseBroadcast(value);
+ case "buffSize": //缓冲大小
+ int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
+
+ if (buffSize < 2048) {
+ buffSize = 2048;
+ }
+
+ setField("buffSize", buffSize, getAllTaskType());
break;
- case "ca":
+ case "ca": // ca证书
String caName = attributes.getValue("name");
String caPath = attributes.getValue("path");
- loadCA(caName, caPath);
+ setField("caName", caName, getAllTaskType());
+ setField("caPath", caPath, getAllTaskType());
+ break;
+ case "convertSpeed": // 是否转换速度
+ setField("isConvertSpeed", !checkBoolean(value) || Boolean.parseBoolean(value),
+ getAllTaskType());
break;
- case "convertSpeed":
- loadConvertSpeed(value);
+ case "maxSpeed": // 最大速度
+ int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
+ setField("maxSpeed", maxSpeed, getAllTaskType());
break;
- case "maxSpeed":
- loadMaxSpeed(value);
+ case "queueMod": // 队列类型
+ String mod = "now";
+ if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
+ "wait"))) {
+ mod = value;
+ }
+ setField("queueMod", mod, getAllTaskType());
break;
- case "queueMod":
- loadQueueMod(value);
+ case "updateInterval": // 进度更新时间
+ setField("updateInterval", checkLong(value) ? Long.parseLong(value) : 1000,
+ getAllTaskType());
break;
- case "updateInterval":
- loadUpdateInterval(value);
+
+ case "useBlock": // 是否使用分块任务
+ setField("useBlock", checkBoolean(value) ? Boolean.valueOf(value) : false,
+ ConfigType.DOWNLOAD);
+ break;
+ case "subMaxTaskNum": // 子任务最大任务数
+ int subMaxTaskNum = checkInt(value) ? Integer.parseInt(value) : 3;
+ setField("subMaxTaskNum", subMaxTaskNum, ConfigType.D_GROUP);
break;
- case "notNetRetry":
- loadNotNetRetry(value);
+ case "subReTryNum": // 子任务重试次数
+ int subReTryNum = checkInt(value) ? Integer.parseInt(value) : 5;
+ setField("subReTryNum", subReTryNum, ConfigType.D_GROUP);
break;
- case "useBlock":
- loadUseBlock(value);
+ case "subReTryInterval": // 子任务重试间隔
+ int subReTryInterval = checkInt(value) ? Integer.parseInt(value) : 2000;
+ setField("subReTryInterval", subReTryInterval, ConfigType.D_GROUP);
break;
}
} else if (mType == ConfigType.APP) {
String value = attributes.getValue("value");
switch (qName) {
- case "useAriaCrashHandler":
- loadUseAriaCrashHandler(value);
+ case "useAriaCrashHandler": // 是否捕捉崩溃日志
+ setField("useAriaCrashHandler", checkBoolean(value) ? Boolean.valueOf(value) : true,
+ ConfigType.APP);
+ break;
+ case "logLevel": // 日记等级
+ int level = checkInt(value) ? Integer.parseInt(value) : ALog.LOG_LEVEL_VERBOSE;
+ if (level < ALog.LOG_LEVEL_VERBOSE || level > ALog.LOG_CLOSE) {
+ ALog.w(TAG, "level【" + level + "】错误");
+ level = ALog.LOG_LEVEL_VERBOSE;
+ }
+ setField("level", level, ConfigType.APP);
break;
- case "logLevel":
- loadLogLevel(value);
+ case "netCheck": // 是否检查网络
+ setField("netCheck", checkBoolean(value) ? Boolean.valueOf(value) : false,
+ ConfigType.APP);
break;
- case "netCheck":
- loadNetCheck(value);
+ case "useBroadcast": // 是否使用广播
+ setField("useBroadcast", checkBoolean(value) ? Boolean.valueOf(value) : false,
+ ConfigType.APP);
+ break;
+ case "notNetRetry": // 没有网络也重试
+ setField("notNetRetry", checkBoolean(value) ? Boolean.valueOf(value) : false,
+ ConfigType.APP);
break;
}
}
}
- private void loadNetCheck(String value) {
- boolean b = checkBoolean(value), temp = false;
- if (b) {
- temp = Boolean.valueOf(value);
- }
- mAppConfig.netCheck = temp;
- }
-
- private void loadUseBroadcast(String value) {
- boolean b = checkBoolean(value), temp = false;
-
- if (b) {
- temp = Boolean.valueOf(value);
- }
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.useBroadcast = temp;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.useBroadcast = temp;
- }
- }
-
- private void loadUseBlock(String value) {
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.useBlock = checkBoolean(value) ? Boolean.valueOf(value) : false;
- }
+ /**
+ * 获取任务类型集合,类型有 {@link ConfigType#DOWNLOAD}、{@link ConfigType#UPLOAD}、{@link ConfigType#D_GROUP}
+ */
+ private int[] getAllTaskType() {
+ return new int[] {ConfigType.DOWNLOAD, ConfigType.UPLOAD,
+ ConfigType.D_GROUP};
}
- private void loadNotNetRetry(String value) {
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
+ private void setField(String key, Object value, int... types) {
+ for (int type : types) {
+ if (type == ConfigType.DOWNLOAD) {
+ setField(Configuration.DownloadConfig.class, mDownloadConfig, key, value);
+ } else if (type == ConfigType.UPLOAD) {
+ setField(Configuration.UploadConfig.class, mUploadConfig, key, value);
+ } else if (type == ConfigType.APP) {
+ setField(Configuration.AppConfig.class, mAppConfig, key, value);
+ } else if (type == ConfigType.D_GROUP) {
+ setField(Configuration.DGroupConfig.class, mDGroupConfig, key, value);
+ }
}
}
- private void loadLogLevel(String value) {
- int level;
+ private void setField(Class clazz, Object target, String key, Object value) {
+ Field field = CommonUtil.getField(clazz, key);
try {
- level = Integer.parseInt(value);
- } catch (NumberFormatException e) {
+ field.set(target, value);
+ } catch (IllegalAccessException 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)) {
- mAppConfig.useAriaCrashHandler = Boolean.parseBoolean(value);
- } else {
- ALog.w(TAG, "useAriaCrashHandler【" + value + "】错误");
- mAppConfig.useAriaCrashHandler = true;
- }
- }
-
- private void loadUpdateInterval(String value) {
- long temp = checkLong(value) ? Long.parseLong(value) : 1000;
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.updateInterval = temp;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.updateInterval = temp;
- }
- }
-
- private void loadQueueMod(String value) {
- String mod = "now";
- if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
- "wait"))) {
- mod = value;
- }
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.queueMod = mod;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.queueMod = mod;
- }
- }
-
- private void loadMaxSpeed(String value) {
- int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.maxSpeed = maxSpeed;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.maxSpeed = maxSpeed;
- }
- }
-
- private void loadConvertSpeed(String value) {
- boolean open = true;
- if (checkBoolean(value)) {
- open = Boolean.parseBoolean(value);
- }
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.isConvertSpeed = open;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.isConvertSpeed = open;
- }
- }
-
- private void loadReTryInterval(String value) {
- int time = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
-
- if (time < 2 * 1000) {
- time = 2 * 1000;
- }
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.reTryInterval = time;
- }
- }
-
- private void loadCA(String name, String path) {
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.caName = name;
- mDownloadConfig.caPath = path;
- }
- }
-
- private void loadBuffSize(String value) {
- int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
-
- if (buffSize < 2048) {
- buffSize = 2048;
- }
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.buffSize = buffSize;
- }
-
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.buffSize = buffSize;
- }
- }
-
- private void loadIOTimeout(String value) {
- int time = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
-
- if (time < 10 * 1000) {
- time = 10 * 1000;
- }
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.iOTimeOut = time;
- }
-
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.iOTimeOut = time;
- }
- }
-
- private void loadConnectTime(String value) {
- int time = checkInt(value) ? Integer.parseInt(value) : 5 * 1000;
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.connectTimeOut = time;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.connectTimeOut = time;
- }
- }
-
- private void loadReTry(String value) {
- int num = checkInt(value) ? Integer.parseInt(value) : 0;
-
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.reTryNum = num;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.reTryNum = num;
- }
- }
-
- private void loadMaxQueue(String value) {
- int num = checkInt(value) ? Integer.parseInt(value) : 2;
- if (num < 1) {
- ALog.w(TAG, "任务队列数不能小于 1");
- num = 2;
- }
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.maxTaskNum = num;
- }
- if (mType == ConfigType.UPLOAD) {
- mUploadConfig.maxTaskNum = num;
- }
- }
-
- private void loadThreadNum(String value) {
- int num = checkInt(value) ? Integer.parseInt(value) : 3;
- if (num < 1) {
- ALog.e(TAG, "下载线程数不能小于 1");
- num = 1;
- }
- if (mType == ConfigType.DOWNLOAD) {
- mDownloadConfig.threadNum = num;
}
}
@@ -338,8 +226,8 @@ class ConfigHelper extends DefaultHandler {
return false;
}
try {
- Integer l = Integer.parseInt(value);
- return true;
+ int l = Integer.parseInt(value);
+ return l >= 0;
} catch (NumberFormatException e) {
e.printStackTrace();
return false;
@@ -387,5 +275,6 @@ class ConfigHelper extends DefaultHandler {
mDownloadConfig.save();
mUploadConfig.save();
mAppConfig.save();
+ mDGroupConfig.save();
}
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back
new file mode 100644
index 00000000..f076a411
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back
@@ -0,0 +1,441 @@
+/*
+ * 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 android.text.TextUtils;
+import com.arialyy.aria.util.ALog;
+import javax.xml.validation.Validator;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Created by lyy on 2017/5/22. 读取配置文件
+ */
+class ConfigHelper extends DefaultHandler {
+ private final String TAG = "ConfigHelper";
+
+ private Configuration.DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg;
+ private Configuration.UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg;
+ private Configuration.AppConfig mAppConfig = Configuration.getInstance().appCfg;
+ private Configuration.DGroupConfig mDGroupConfig = Configuration.getInstance().dGroupCfg;
+ private @ConfigType int mType;
+
+ @Override public void startDocument() throws SAXException {
+ super.startDocument();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes)
+ throws SAXException {
+ super.startElement(uri, localName, qName, attributes);
+ switch (qName) {
+ case "download":
+ mType = ConfigType.DOWNLOAD;
+ break;
+ case "upload":
+ mType = ConfigType.UPLOAD;
+ break;
+ case "app":
+ mType = ConfigType.APP;
+ break;
+ case "dGroup":
+ mType = ConfigType.D_GROUP;
+ break;
+ }
+
+ if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD || mType == ConfigType.D_GROUP) {
+
+ String value = attributes.getValue("value");
+ switch (qName) {
+ case "threadNum":
+ loadThreadNum(value);
+ break;
+ case "maxTaskNum":
+ loadMaxQueue(value);
+ break;
+ case "reTryNum":
+ loadReTry(value);
+ break;
+ case "connectTimeOut":
+ loadConnectTime(value);
+ break;
+ case "iOTimeOut":
+ loadIOTimeout(value);
+ break;
+ case "reTryInterval":
+ loadReTryInterval(value);
+ break;
+ case "buffSize":
+ loadBuffSize(value);
+ break;
+ case "ca":
+ String caName = attributes.getValue("name");
+ String caPath = attributes.getValue("path");
+ loadCA(caName, caPath);
+ break;
+ case "convertSpeed":
+ loadConvertSpeed(value);
+ break;
+ case "maxSpeed":
+ loadMaxSpeed(value);
+ break;
+ case "queueMod":
+ loadQueueMod(value);
+ break;
+ case "updateInterval":
+ loadUpdateInterval(value);
+ break;
+ case "notNetRetry":
+ loadNotNetRetry(value);
+ break;
+ case "useBlock":
+ loadUseBlock(value);
+ break;
+ case "subMaxTaskNum":
+ loadSubMaxTaskNum(value);
+ break;
+ case "subReTryNum":
+ loadSubReTryNum(value);
+ break;
+ case "subReTryInterval":
+ loadSubReTryInterval(value);
+ break;
+ }
+ } else if (mType == ConfigType.APP) {
+ String value = attributes.getValue("value");
+ switch (qName) {
+ case "useAriaCrashHandler":
+ loadUseAriaCrashHandler(value);
+ break;
+ case "logLevel":
+ loadLogLevel(value);
+ break;
+ case "netCheck":
+ loadNetCheck(value);
+ break;
+ case "useBroadcast":
+ loadUseBroadcast(value);
+ break;
+ }
+ }
+ }
+
+ private void loadSubReTryInterval(String value) {
+ int temp = checkInt(value) ? Integer.parseInt(value) : 2000;
+ if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.subReTryInterval = temp;
+ }
+ }
+
+ private void loadSubReTryNum(String value) {
+ int temp = checkInt(value) ? Integer.parseInt(value) : 5;
+ if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.subReTryNum = temp;
+ }
+ }
+
+ private void loadSubMaxTaskNum(String value) {
+ int temp = checkInt(value) ? Integer.parseInt(value) : 3;
+ if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.subMaxTaskNum = temp;
+ }
+ }
+
+ private void loadNetCheck(String value) {
+ boolean b = checkBoolean(value), temp = false;
+ if (b) {
+ temp = Boolean.valueOf(value);
+ }
+ mAppConfig.netCheck = temp;
+ }
+
+ private void loadUseBroadcast(String value) {
+ boolean b = checkBoolean(value), temp = false;
+
+ if (b) {
+ temp = Boolean.valueOf(value);
+ }
+ if (mType == ConfigType.APP) {
+ mAppConfig.useBroadcast = temp;
+ }
+ }
+
+ private void loadUseBlock(String value) {
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.useBlock = checkBoolean(value) ? Boolean.valueOf(value) : false;
+ }
+ }
+
+ private void loadNotNetRetry(String value) {
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
+ }
+ }
+
+ 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)) {
+ mAppConfig.useAriaCrashHandler = Boolean.parseBoolean(value);
+ } else {
+ ALog.w(TAG, "useAriaCrashHandler【" + value + "】错误");
+ mAppConfig.useAriaCrashHandler = true;
+ }
+ }
+
+ private void loadUpdateInterval(String value) {
+ long temp = checkLong(value) ? Long.parseLong(value) : 1000;
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.updateInterval = temp;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.updateInterval = temp;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.updateInterval = temp;
+ }
+ }
+
+ private void loadQueueMod(String value) {
+ String mod = "now";
+ if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
+ "wait"))) {
+ mod = value;
+ } else if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.queueMod = mod;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.queueMod = mod;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.queueMod = mod;
+ }
+ }
+
+ private void loadMaxSpeed(String value) {
+ int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.maxSpeed = maxSpeed;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.maxSpeed = maxSpeed;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDownloadConfig.maxSpeed = maxSpeed;
+ }
+ }
+
+ private void loadConvertSpeed(String value) {
+ boolean open = true;
+ if (checkBoolean(value)) {
+ open = Boolean.parseBoolean(value);
+ }
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.isConvertSpeed = open;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.isConvertSpeed = open;
+ } else if (mType == ConfigType.D_GROUP) {
+ mUploadConfig.isConvertSpeed = open;
+ }
+ }
+
+ private void loadReTryInterval(String value) {
+ int time = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
+
+ if (time < 2 * 1000) {
+ time = 2 * 1000;
+ }
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.reTryInterval = time;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.reTryInterval = time;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.reTryInterval = time;
+ }
+ }
+
+ private void loadCA(String name, String path) {
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.caName = name;
+ mDownloadConfig.caPath = path;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.caName = name;
+ mUploadConfig.caPath = path;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.caName = name;
+ mDGroupConfig.caPath = path;
+ }
+ }
+
+ private void loadBuffSize(String value) {
+ int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
+
+ if (buffSize < 2048) {
+ buffSize = 2048;
+ }
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.buffSize = buffSize;
+ }
+
+ if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.buffSize = buffSize;
+ }
+ }
+
+ private void loadIOTimeout(String value) {
+ int time = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
+
+ if (time < 10 * 1000) {
+ time = 10 * 1000;
+ }
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.iOTimeOut = time;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.iOTimeOut = time;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.iOTimeOut = time;
+ }
+ }
+
+ private void loadConnectTime(String value) {
+ int time = checkInt(value) ? Integer.parseInt(value) : 5 * 1000;
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.connectTimeOut = time;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.connectTimeOut = time;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.connectTimeOut = time;
+ }
+ }
+
+ private void loadReTry(String value) {
+ int num = checkInt(value) ? Integer.parseInt(value) : 0;
+
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.reTryNum = num;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.reTryNum = num;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.reTryNum = num;
+ }
+ }
+
+ private void loadMaxQueue(String value) {
+ int num = checkInt(value) ? Integer.parseInt(value) : 2;
+ if (num < 1) {
+ ALog.w(TAG, "任务队列数不能小于 1");
+ num = 2;
+ }
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.maxTaskNum = num;
+ } else if (mType == ConfigType.UPLOAD) {
+ mUploadConfig.maxTaskNum = num;
+ } else if (mType == ConfigType.D_GROUP) {
+ mDGroupConfig.maxTaskNum = num;
+ }
+ }
+
+ private void loadThreadNum(String value) {
+ int num = checkInt(value) ? Integer.parseInt(value) : 3;
+ if (num < 1) {
+ ALog.e(TAG, "下载线程数不能小于 1");
+ num = 1;
+ }
+ if (mType == ConfigType.DOWNLOAD) {
+ mDownloadConfig.threadNum = num;
+ }
+ }
+
+ /**
+ * 检查是否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 {
+ super.characters(ch, start, length);
+ }
+
+ @Override public void endElement(String uri, String localName, String qName) throws SAXException {
+ super.endElement(uri, localName, qName);
+ }
+
+ @Override public void endDocument() throws SAXException {
+ super.endDocument();
+ mDownloadConfig.save();
+ mUploadConfig.save();
+ mAppConfig.save();
+ mDGroupConfig.save();
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java
index 3fc9ed35..c4fc5114 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java
@@ -22,10 +22,12 @@ import java.lang.annotation.RetentionPolicy;
@IntDef({
ConfigType.DOWNLOAD,
ConfigType.UPLOAD,
- ConfigType.APP
+ ConfigType.APP,
+ ConfigType.D_GROUP
})
@Retention(RetentionPolicy.SOURCE) @interface ConfigType {
int DOWNLOAD = 1;
int UPLOAD = 2;
int APP = 3;
+ int D_GROUP = 4;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
index 609714f2..4867c87b 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
@@ -17,13 +17,13 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
-import com.arialyy.aria.core.queue.ITaskQueue;
+import com.arialyy.aria.core.queue.AbsTaskQueue;
/**
* Created by AriaL on 2017/6/29.
*/
public abstract class AbsCmd
*
- * {@literal @}DownloadGroup.onPre(groupName)
+ * {@literal @}DownloadGroup.onPre(groupHash)
* protected void onPre(DownloadGroupTask task) {
* }
*
*
- * {@literal @}Download.onPre("myGroupName"),如果你的注解中增加了url描述,
- * 则表示,所有下载任务中,只有下载地址为"myGroupName"的任务才能回调该注解的方法。
+ * {@literal @}Download.onPre("mGroupHash"),如果你的注解中增加了url描述,
+ * 则表示,所有下载任务中,只有下载地址为"myGroupHash"的任务才能回调该注解的方法。
*
*
* 如果希望获取子任务的状态,可以使用onSub..类的注解
* *- * {@literal @}DownloadGroup.onSubPre(groupName) + * {@literal @}DownloadGroup.onSubPre(groupHash) * protected void onPre(DownloadGroupTask task, String url) { * } *
diff --git a/DEV_LOG.md b/DEV_LOG.md index def36cf5..de5a7371 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,6 +1,9 @@ ## 开发日志 - + v_3.5.5 + + v_3.6 - 优化数据库写入\修改的速度 + - 精减任务实体的存储 + - 增加下载组合任务的配置 + - useBroadcast\notNetRetry这两个配置,统一在AppConfig中 + v_3.5.4 (2019/1/8) - 修复不支持断点的下载地址,重复下载出现的数据库主键冲突问题 + v_3.5.3 (2018/12/23) diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index cc753665..349a3db7 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -1,6 +1,8 @@+ + \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/DbTestActivity.java b/app/src/main/java/com/arialyy/simple/DbTestActivity.java index b38ce61e..b1dbe3d4 100644 --- a/app/src/main/java/com/arialyy/simple/DbTestActivity.java +++ b/app/src/main/java/com/arialyy/simple/DbTestActivity.java @@ -59,8 +59,6 @@ public class DbTestActivity extends BaseActivity- + @@ -8,10 +10,15 @@ + + + + + @@ -27,9 +34,6 @@ --> +- - - - - - - + + - - @@ -108,9 +107,55 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { entity.setDownloadPath(key); DTaskWrapper dte = new DTaskWrapper(entity); - dte.setUrl(url); - dte.setKey(key); datas.add(entity); } diff --git a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt index ef873639..0587f32e 100644 --- a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt +++ b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt @@ -68,7 +68,7 @@ // private fun startD() { // Aria.download(this) // .load(DOWNLOAD_URL) -// .addHeader("groupName", "value") +// .addHeader("groupHash", "value") // .setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk") // .start() // } diff --git a/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java b/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java index 0b013adb..3506178a 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java +++ b/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java @@ -18,7 +18,6 @@ package com.arialyy.simple.download.group; import android.annotation.SuppressLint; import android.content.Context; import android.os.Bundle; -import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -46,7 +45,7 @@ import java.util.List; @Bind(R.id.sub_task) TextView mSub; @Bind(R.id.task_group) TextView mGroup; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; - private String mGroupName; + private String mGroupHash; private String mChildName; private List mUrls; private DownloadEntity mChildEntity; @@ -55,7 +54,7 @@ import java.util.List; super(context); setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog); mChildEntity = childEntity; - mGroupName = "任务组测试"; + mGroupHash = "任务组测试"; mUrls = urls; mChildName = childEntity.getFileName(); } @@ -72,7 +71,7 @@ import java.util.List; } private void initWidget() { - mGroup.setText("任务组:" + mGroupName); + mGroup.setText("任务组:" + mGroupHash); mSub.setText("子任务:" + mChildName); mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize())); diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java index c2009ccf..d0af5e6a 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java @@ -62,7 +62,7 @@ public class DownloadAdapter extends AbsRVAdapter