修复组任务中,其中一个子任务是30x地址,导致调度器无法出现该子任务状态的问题

增加组任务groupHash冲突检查 https://github.com/AriaLyy/Aria/issues/635
pull/640/head
laoyuyu 5 years ago
parent 9cb6490da9
commit de09add3a3
  1. 32
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java
  2. 9
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java
  3. 9
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java
  4. 2
      DEV_LOG.md
  5. 8
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
  6. 1
      PublicComponent/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java
  7. 13
      PublicComponent/src/main/java/com/arialyy/aria/core/download/AbsGroupTaskWrapper.java
  8. 5
      PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  9. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalTTBuilder.java
  10. 8
      PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  11. 12
      PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java
  12. 5
      app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  13. 2
      app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  14. 25
      app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java
  15. 6
      app/src/main/res/values/strings.xml
  16. 2
      build.gradle

@ -15,9 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.text.LoginFilter;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.controller.FeatureController;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
@ -25,7 +23,6 @@ import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.RecordUtil;
import java.io.File;
import java.util.ArrayList;
@ -46,6 +43,9 @@ public class CheckDGEntityUtil implements ICheckEntityUtil {
private boolean needModifyPath = false;
private int action;
/**
* @param action {@link FeatureController#ACTION_CREATE}
*/
public static CheckDGEntityUtil newInstance(DGTaskWrapper wrapper, int action) {
return new CheckDGEntityUtil(wrapper, action);
}
@ -115,6 +115,27 @@ public class CheckDGEntityUtil implements ICheckEntityUtil {
}
}
/**
* 检查和处理组合任务的路径冲突
*
* @param isIgnoreTaskOccupy true如果hash冲突将删除其它任务的记录的
* @param groupHash 组任务hash
* @return false 任务不再执行true 任务继续执行
*/
private boolean checkGroupHash(boolean isIgnoreTaskOccupy, String groupHash) {
if (DbEntity.checkDataExist(DownloadGroupEntity.class, "groupHash=?", groupHash)) {
if (!isIgnoreTaskOccupy) {
ALog.e(TAG, String.format("下载失败,数据库中已存在相同的url的组任务,groupHash = %s", groupHash));
return false;
} else {
ALog.w(TAG, String.format("数据库中已存在相同的url的组任务,将删除groupHash = %s 的旧任务", groupHash));
RecordUtil.delGroupTaskRecordByHash(groupHash, true);
return true;
}
}
return true;
}
@Override
public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
@ -122,6 +143,11 @@ public class CheckDGEntityUtil implements ICheckEntityUtil {
return false;
}
if ((action == FeatureController.ACTION_CREATE || action == FeatureController.ACTION_ADD)
&& !checkGroupHash(mWrapper.isIgnoreTaskOccupy(), mEntity.getGroupHash())) {
return false;
}
if (!checkDirPath()) {
return false;
}

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download.target;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
@ -105,6 +106,14 @@ public class GroupBuilderTarget extends AbsBuilderTarget<GroupBuilderTarget> {
return this;
}
/**
* {@code true} 忽略任务冲突不考虑组任务hash冲突的情况
*/
public GroupBuilderTarget ignoreTaskOccupy() {
((AbsGroupTaskWrapper) getTaskWrapper()).setIgnoreTaskOccupy(true);
return this;
}
/**
* 设置任务组的文件夹路径在Aria中任务组的所有子任务都会下载到以任务组组名的文件夹中
* groupDirPath = "/mnt/sdcard/download/group_test"

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download.target;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
@ -73,6 +74,14 @@ public class GroupNormalTarget extends AbsNormalTarget<GroupNormalTarget> {
return mConfigHandler.updateUrls(urls);
}
/**
* {@code true} 忽略任务冲突不考虑组任务hash冲突的情况
*/
public GroupNormalTarget ignoreTaskOccupy() {
((AbsGroupTaskWrapper) getTaskWrapper()).setIgnoreTaskOccupy(true);
return this;
}
/**
* 更新任务组的文件夹路径在Aria中任务组的所有子任务都会下载到以任务组组名的文件夹中
* groupDirPath = "/mnt/sdcard/download/group_test"

@ -5,6 +5,8 @@
- 修复wait模式下,resume(true)无效问题
- 修复now模式下的一些问题 https://github.com/AriaLyy/Aria/issues/620
- 修复组任务,其中一个子任务在获取文件长度失败后,重新恢复组合任务,组合任务状态变为完成的问题 https://github.com/AriaLyy/Aria/issues/628
- 修复组任务中,其中一个子任务是30x地址,导致调度器无法出现该子任务状态的问题
- 增加组任务groupHash冲突检查 https://github.com/AriaLyy/Aria/issues/635
+ v_3.8.6 (2020/2/17)
- fix bug https://github.com/AriaLyy/Aria/issues/608
- fix bug https://github.com/AriaLyy/Aria/issues/579#issuecomment-586665035

@ -57,7 +57,7 @@ import java.util.UUID;
* 下载文件信息获取
*/
final class HttpDFileInfoTask implements IInfoTask, Runnable {
private static final String TAG = "HttpFileInfoThread";
private static final String TAG = "HttpDFileInfoTask";
private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper;
private int mConnectTimeOut;
@ -164,12 +164,6 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable {
taskOption.getFileNameAdapter().handleFileName(headers, mEntity.getKey());
mEntity.setServerFileName(newName);
renameFile(newName);
} else if (conn.getHeaderField("Content-Type") != null) {
String contentType = conn.getHeaderField("Content-Type");
String type = contentType.substring(contentType.indexOf(File.separator) + 1);
String newName = String.format("%s.%s", mEntity.getFileName(), type);
mEntity.setServerFileName(newName);
renameFile(newName);
}
}
}

@ -36,6 +36,7 @@ public class SubThreadConfig {
public boolean isBlock = false;
// 启动的线程
public int startThreadNum;
// 真正的下载地址,如果是30x,则是30x后的地址
public String url;
public File tempFile;
// 线程记录

@ -32,4 +32,17 @@ public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends
public abstract List<SUB> getSubTaskWrapper();
public abstract void setSubTaskWrapper(List<SUB> subTaskWrapper);
/**
* {@code true} 忽略任务冲突不考虑组任务hash冲突的情况
*/
private boolean ignoreTaskOccupy = false;
public boolean isIgnoreTaskOccupy() {
return ignoreTaskOccupy;
}
public void setIgnoreTaskOccupy(boolean ignoreTaskOccupy) {
this.ignoreTaskOccupy = ignoreTaskOccupy;
}
}

@ -74,8 +74,11 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
return m3U8Entity;
}
/**
* 如果是30x则是30x后的地址
*/
@Override public String getKey() {
return getUrl();
return isRedirect() ? getRedirectUrl() : getUrl();
}
@Override public int getTaskType() {

@ -115,7 +115,7 @@ public final class NormalTTBuilder implements IThreadTaskBuilder {
b = new Bundle();
}
b.putString(IThreadStateManager.DATA_THREAD_NAME,
CommonUtil.getThreadName(getEntity().getUrl(), tr.threadId));
CommonUtil.getThreadName(getEntity().getKey(), tr.threadId));
msg.setData(b);
msg.sendToTarget();
continue;

@ -22,8 +22,8 @@ import android.os.Message;
import android.os.Process;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.ThreadRecord;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IThreadStateManager;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.manager.ThreadTaskManager;
@ -50,7 +50,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
*/
private final int RETRY_NUM = 2;
private final String TAG = CommonUtil.getClassName(getClass());
private IEntity mEntity;
private AbsEntity mEntity;
protected AbsTaskWrapper mTaskWrapper;
private int mFailTimes = 0;
private long mLastSaveTime, mLastSendProgressTime;
@ -147,7 +147,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
/**
* 获取实体
*/
protected IEntity getEntity() {
protected AbsEntity getEntity() {
return mEntity;
}
@ -244,7 +244,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
@Override public String getThreadName() {
return mThreadName == null ? (mThreadName =
CommonUtil.getThreadName(getConfig().url, getThreadId())) : mThreadName;
CommonUtil.getThreadName(getEntity().getKey(), getThreadId())) : mThreadName;
}
/**

@ -60,6 +60,18 @@ public class FileUtil {
private static final String EXTERNAL_STORAGE_PATH =
Environment.getExternalStorageDirectory().getPath();
/**
* 获取文件后缀名
* @return 获取不到文件名后缀返回null
*/
public static String getFileExtensionName(String fileName) {
if (TextUtils.isEmpty(fileName)) {
return null;
}
int endP = fileName.lastIndexOf(".");
return endP > -1 ? fileName.substring(endP + 1) : null;
}
/**
* 通过流创建文件
*

@ -58,9 +58,10 @@ public class HttpDownloadModule extends BaseViewModule {
//String url = "https://imtt.dd.qq.com/16891/apk/70BFFDB05AB8686F2A4CF3E07588A377.apk?fsname=com.tencent.tmgp.speedmobile_1.16.0.33877_1160033877.apk&csr=1bbd";
//String url = "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg";
//String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath);
String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip";
//String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip";
String url = "https://video-hkt1-1.xx.fbcdn.net/v/t42.9040-2/89465702_658301101378505_5469280744218034176_n.mp4?_nc_cat=107&_nc_sid=985c63&efg=eyJ2ZW5jb2RlX3RhZyI6ImxlZ2FjeV9zZCJ9&_nc_oc=AQmzYwQG9vccyqr7S44-cfHc4wJ9010O1nvspG2DPV4cTct1pLrjKl1e1UmOJV99bJw&_nc_ht=video-hkt1-1.xx&oh=49bd04435aaa8b4459b8d5cb7d1e7c79&oe=5E672E37";
//String url = "http://donuts.aigauss.com/doc_fPhW2DBGj3_1578932414.png";
String filePath = "/mnt/sdcard/update.zip";
String filePath = "/mnt/sdcard/update.mp4";
//String url = "https://dhfspace.360drm.com/1_12809_1543904946_VID_20180808_212829.vep?e=1578554567&token=gUBmfZgZS5wy4wdQIDZG8UVxlNCyVSjvksIb13K5:WYSZRgmLbH1_9hjgqOAGmqR27JM=";
//String filePath = "/mnt/sdcard/sssss.zip";

@ -73,7 +73,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
mTaskId = Aria.download(this)
.loadGroup(mUrls)
.setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_imgs")
Environment.getExternalStorageDirectory().getPath() + "/Download/group_imgs1")
//.setSubFileName(getModule(GroupModule.class).getSubName2())
.setSubFileName(getModule(GroupModule.class).getSubName())
.unknownSize()

@ -32,32 +32,37 @@ public class GroupModule extends BaseModule {
public List<String> getUrls() {
List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
Collections.addAll(urls, str);
//String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
//Collections.addAll(urls, str);
//urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-9/fr/cp0/e15/q65/85148967_168821394550033_6164348723502514176_n.jpg?_nc_cat=105&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQni9wIDOcxkQGfqH7jFwLuRWV3cIi0We11MXp1V0_vfrQ3-SBV4Ue034aJXzzIzdNI&_nc_ht=scontent-hkt1-1.xx&_nc_tp=14&oh=37829bbfd4f7179fcc3527a7a7971f53&oe=5F00FC35");
//urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/84206444_168821471216692_7979166053252988928_n.jpg?_nc_cat=106&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQny1ZTkxw-sq4mSH2TThaQNRJB89uKG2cW9e3DgcI78qXE7b8Jlyox749lXkcngYBs&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=6714e2c9b3d76e12eff960b6aa22cdfb&oe=5EEE640F");
//urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/86702402_168821534550019_6064732312896012288_n.jpg?_nc_cat=101&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQnfJfW55cqVfs0lzZOjEa8kGoxvrA--\\brjaelZgcf8MzqQUhjH3moqGoekMQlATXRM&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=96f4f776c05b2c200cfb720fa36f938b&oe=5EFA310D");
//urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-0/cp0/e15/q65/p480x480/85236032_168821577883348_2800973234302877696_n.jpg?_nc_cat=106&_nc_sid=110474&efg=eyJpIjoidCJ9&_nc_oc=AQlNvaTlYUspquMWBLnkgVOHdzG4pX2XW3NSHYxvVYsaJF8Ehy9tGn6R6Ned5UwcwAM&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=6fd5e6442712e4da111d09e8902c68c5&oe=5EFE1528");
//urls.add("https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-1/cp0/e15/q65/p120x120/80398195_141232180642288_3692820603451998208_n.jpg?_nc_cat=109&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_oc=AQmsZxgvLgoObkqHbcKS8qIZ3w_QhssRwLSF5o-8P6q_kf962w32kmjLqcg6lH9qxWI&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=269e655e7b901e8d07d9362142a0fdda&oe=5EF43734");
urls.add(
"https://video-hkt1-1.xx.fbcdn.net/v/t42.9040-2/89465702_658301101378505_5469280744218034176_n.mp4?_nc_cat=107&_nc_sid=985c63&efg=eyJ2ZW5jb2RlX3RhZyI6ImxlZ2FjeV9zZCJ9&_nc_oc=AQmzYwQG9vccyqr7S44-cfHc4wJ9010O1nvspG2DPV4cTct1pLrjKl1e1UmOJV99bJw&_nc_ht=video-hkt1-1.xx&oh=49bd04435aaa8b4459b8d5cb7d1e7c79&oe=5E672E37");
urls.add(
"https://scontent-hkt1-1.xx.fbcdn.net/v/t15.5256-10/fr/cp0/e15/q65/83913248_211240646743277_4802581788427812864_n.jpg?_nc_cat=103&_nc_sid=f2c4d5&_nc_oc=AQkT-0QmghK66vtY6tfr01niqxjePFuU-6JAYcAW7MKJoC8MgQDSRXg_iXW6FUZZa3A&_nc_ht=scontent-hkt1-1.xx&_nc_tp=14&oh=6f020a513d181256b98edc3896b1c3c7&oe=5E8FE498");
urls.add(
"https://scontent-hkt1-1.xx.fbcdn.net/v/t1.0-1/cp0/e15/q65/p480x480/75642413_2805764969481542_7020281898245029888_n.jpg?_nc_cat=1&_nc_sid=dbb9e7&_nc_oc=AQmgACYknk9eS0cgeReiSuYuB2qfybLSQwqH98trPB1AFh9dSKXHn7cCcKcKO6YDKdM&_nc_ht=scontent-hkt1-1.xx&_nc_tp=3&oh=78e0717a056391e1f9c917f290f74aab&oe=5E9433B8");
return urls;
}
List<String> getUrls1() {
List<String> urls = new ArrayList<>();
//String[] str = getContext().getResources().getStringArray(R.array.group_urls);
//Collections.addAll(urls, str);
urls.add("https://d.pcs.baidu.com/file/130335545f3f4d9cc38afe709c19af5a?fid=1411168371-250528-1010657263806840&dstime=1531134607&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-sNCujT7lC42aMcfiHcgqAzYHuw4%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=4401967667009194668&dp-callid=0&r=540192514");
urls.add(
"https://d.pcs.baidu.com/file/130335545f3f4d9cc38afe709c19af5a?fid=1411168371-250528-1010657263806840&dstime=1531134607&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-sNCujT7lC42aMcfiHcgqAzYHuw4%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=4401967667009194668&dp-callid=0&r=540192514");
return urls;
}
List<String> getSubName() {
List<String> names = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_names);
Collections.addAll(names, str);
//names.add("1.png");
//names.add("2.png");
//names.add("3.png");
//String[] str = getContext().getResources().getStringArray(R.array.group_names);
//Collections.addAll(names, str);
names.add("1.mp4");
names.add("2.png");
names.add("3.png");
//names.add("4.png");
//names.add("5.png");
return names;

@ -135,8 +135,10 @@
</string-array>
<string-array name="group_urls_3">
<item>https://downs.muzhiwan.com/2019/07/23/com.amazid.me_5d36bade614d9.apk</item>
<item>https://downs.muzhiwan.com/2019/07/30/com.counter.terrorist.attack.fps.sniper.fight_5d3fe8f0a7edf.apk</item>
<item>http://down.muzhiwan.com/2017/04/05/org.sanguoqy01_58e4993914424.apk</item>
<item>http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1</item>
<!-- <item>https://downs.muzhiwan.com/2019/07/23/com.amazid.me_5d36bade614d9.apk</item>-->
<!-- <item>https://downs.muzhiwan.com/2019/07/30/com.counter.terrorist.attack.fps.sniper.fight_5d3fe8f0a7edf.apk</item>-->
</string-array>
<string-array name="group_url4">

@ -45,7 +45,7 @@ task clean(type: Delete) {
ext {
versionCode = 387
versionName = '3.8.7-beta-5'
versionName = '3.8.7-beta-8'
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = versionName

Loading…
Cancel
Save