From cb6f08aa0d8b2f79805da1e239db62673dd5e59d Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Sat, 9 Jun 2018 19:45:15 +0800 Subject: [PATCH] fix bug --- .../core/command/normal/ResumeAllCmd.java | 83 ++++++++++--------- .../arialyy/aria/core/common/AbsFileer.java | 7 +- .../arialyy/aria/core/common/ProxyHelper.java | 21 ++--- .../aria/core/download/DownloadReceiver.java | 25 ++++++ .../download/downloader/AbsGroupUtil.java | 3 + .../downloader/DownloadGroupUtil.java | 6 +- .../com/arialyy/aria/core/inf/AbsEntity.java | 3 + .../aria/core/scheduler/AbsSchedulers.java | 2 +- .../aria/core/upload/UploadReceiver.java | 7 +- .../com/arialyy/aria/util/CommonUtil.java | 27 ++++-- app/src/main/AndroidManifest.xml | 4 +- .../simple/download/group/GroupModule.java | 2 +- .../multi_download/MultiTaskActivity.java | 2 + app/src/main/res/values/strings.xml | 5 ++ build.gradle | 2 +- 15 files changed, 127 insertions(+), 72 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index ef4cf1d2..c87cad90 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -1,18 +1,19 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; 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.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.core.upload.UploadEntity; 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.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -43,10 +44,10 @@ final class ResumeAllCmd extends AbsNormalCmd { return; } if (isDownloadCmd) { - resumeTask(findTaskData(1)); - resumeTask(findTaskData(2)); + findTaskData(1); + findTaskData(2); } else { - resumeTask(findTaskData(3)); + findTaskData(3); } resumeWaitTask(); } @@ -56,53 +57,49 @@ final class ResumeAllCmd extends AbsNormalCmd { * * @param type {@code 1}单任务下载任务;{@code 2}任务组下载任务;{@code 3} 单任务上传任务 */ - private List findTaskData(int type) { - List tempList = new ArrayList<>(); + private void findTaskData(int type) { if (type == 1) { - List wrappers = DbEntity.findRelationData(DTEWrapper.class, - "DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state!=?", "false", "1"); - if (wrappers != null && !wrappers.isEmpty()) { - for (DTEWrapper w : wrappers) { - tempList.add(w.taskEntity); + List entities = + DbEntity.findDatas(DownloadEntity.class, + "isGroupChild=? and state!=?", "false", "1"); + if (entities != null && !entities.isEmpty()) { + for (DownloadEntity entity : entities) { + resumeTask(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey())); } } } else if (type == 2) { - List wrappers = - DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.state!=?", "1"); - if (wrappers != null && !wrappers.isEmpty()) { - for (DGTEWrapper w : wrappers) { - tempList.add(w.taskEntity); + List entities = + DbEntity.findDatas(DownloadGroupEntity.class, "state!=?", "1"); + if (entities != null && !entities.isEmpty()) { + for (DownloadGroupEntity entity : entities) { + resumeTask( + TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls())); } } } else if (type == 3) { - List wrappers = - DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.state!=?", "1"); - if (wrappers != null && !wrappers.isEmpty()) { - for (UTEWrapper w : wrappers) { - tempList.add(w.taskEntity); + List entities = + DbEntity.findDatas(UploadEntity.class, "state!=?", "1"); + if (entities != null && !entities.isEmpty()) { + for (UploadEntity entity : entities) { + resumeTask(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey())); } } } - return tempList; } /** * 恢复任务 */ - private void resumeTask(List taskList) { - if (taskList != null && !taskList.isEmpty()) { - for (AbsTaskEntity te : taskList) { - if (te == null || te.getEntity() == null) continue; - int state = te.getState(); - if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) { - resumeEntity(te); - } else if (state == IEntity.STATE_WAIT) { - mWaitList.add(te); - } else if (state == IEntity.STATE_RUNNING) { - if (!mQueue.taskIsRunning(te.getEntity().getKey())) { - resumeEntity(te); - } - } + private void resumeTask(AbsTaskEntity te) { + if (te == null || te.getEntity() == null) return; + int state = te.getState(); + if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) { + resumeEntity(te); + } else if (state == IEntity.STATE_WAIT) { + mWaitList.add(te); + } else if (state == IEntity.STATE_RUNNING) { + if (!mQueue.taskIsRunning(te.getEntity().getKey())) { + resumeEntity(te); } } } @@ -117,6 +114,13 @@ final class ResumeAllCmd extends AbsNormalCmd { if (mQueue.getCurrentExePoolNum() < maxTaskNum) { startTask(createTask(te)); } else { + if (te instanceof DownloadTaskEntity) { + mQueue = DownloadTaskQueue.getInstance(); + } else if (te instanceof UploadTaskEntity) { + mQueue = UploadTaskQueue.getInstance(); + } else if (te instanceof DownloadGroupTaskEntity) { + mQueue = DownloadGroupTaskQueue.getInstance(); + } createTask(te); } } @@ -129,7 +133,8 @@ final class ResumeAllCmd extends AbsNormalCmd { */ private void resumeEntity(AbsTaskEntity te) { if (te instanceof DownloadTaskEntity) { - if (te.getRequestType() == AbsTaskEntity.D_FTP || te.getRequestType() == AbsTaskEntity.U_FTP) { + if (te.getRequestType() == AbsTaskEntity.D_FTP + || te.getRequestType() == AbsTaskEntity.U_FTP) { te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); } mQueue = DownloadTaskQueue.getInstance(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 6bff75d7..99956f21 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -511,7 +511,12 @@ public abstract class AbsFileer downloadCounter, uploadCounter, downloadGroupCounter, downloadGroupSubCounter; + public Set downloadCounter = new HashSet<>(), uploadCounter = new HashSet<>(), + downloadGroupCounter = new HashSet<>(), downloadGroupSubCounter = new HashSet<>(); public static volatile ProxyHelper INSTANCE = null; @@ -47,9 +47,10 @@ public class ProxyHelper { } private void init() { - List classes = CommonUtil.getClassName(AriaManager.APP, "com.arialyy.aria"); + List classes = CommonUtil.getClassName(AriaManager.APP, + "com.arialyy.aria.ProxyClassCounter"); for (String className : classes) { - if (!className.startsWith("com.arialyy.aria.ProxyClassCounter")){ + if (!className.startsWith("com.arialyy.aria.ProxyClassCounter")) { continue; } count(className); @@ -66,30 +67,18 @@ public class ProxyHelper { Object object = clazz.newInstance(); Object dc = download.invoke(object); if (dc != null) { - if (downloadCounter == null) { - downloadCounter = new HashSet<>(); - } downloadCounter.addAll((Set) dc); } Object dgc = downloadGroup.invoke(object); if (dgc != null) { - if (downloadGroupCounter == null) { - downloadGroupCounter = new HashSet<>(); - } downloadGroupCounter.addAll((Set) dgc); } Object dgsc = downloadGroupSub.invoke(object); if (dgsc != null) { - if (downloadGroupSubCounter == null) { - downloadGroupSubCounter = new HashSet<>(); - } downloadGroupSubCounter.addAll((Set) dgsc); } Object uc = upload.invoke(object); if (uc != null) { - if (uploadCounter == null) { - uploadCounter = new HashSet<>(); - } uploadCounter.addAll((Set) uc); } } catch (ClassNotFoundException e) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 5ded3c79..8a8e64d0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -294,6 +294,9 @@ public class DownloadReceiver extends AbsReceiver { if (!CheckUtil.checkUrl(downloadUrl)) { return null; } + if (!taskExists(downloadUrl)) { + return null; + } return TEManager.getInstance().getTEntity(DownloadTaskEntity.class, downloadUrl); } @@ -308,6 +311,9 @@ public class DownloadReceiver extends AbsReceiver { ALog.e(TAG, "获取任务组实体失败:任务组子任务下载地址列表为null"); return null; } + if (!taskExists(urls)) { + return null; + } return TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, urls); } @@ -322,6 +328,11 @@ public class DownloadReceiver extends AbsReceiver { ALog.e(TAG, "获取FTP文件夹实体失败:下载路径为null"); return null; } + boolean b = + DownloadGroupEntity.findFirst(DownloadGroupEntity.class, "groupName=?", dirUrl) != null; + if (!b) { + return null; + } return TEManager.getInstance().getFDTEntity(DownloadGroupTaskEntity.class, dirUrl); } @@ -332,6 +343,20 @@ public class DownloadReceiver extends AbsReceiver { return DownloadEntity.findFirst(DownloadEntity.class, "url=?", downloadUrl) != null; } + /** + * 判断任务组是否存在 + * + * @return {@code true} 存在;{@code false} 不存在 + */ + public boolean taskExists(List urls) { + if (urls == null || urls.isEmpty()) { + return false; + } + String groupName = CommonUtil.getMd5Code(urls); + return DownloadGroupEntity.findFirst(DownloadGroupEntity.class, "groupName=?", groupName) + != null; + } + /** * 获取所有普通下载任务 * 获取未完成的普通任务列表{@link #getAllNotCompletTask()} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 285c2b15..01726e0c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -259,6 +259,9 @@ public abstract class AbsGroupUtil implements IUtil { dt.stop(); } } + if (mDownloaderMap.size() == 0){ + mListener.onStop(mCurrentLocation); + } } protected void onStop() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index b82fdc3f..a552f8b2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -44,6 +44,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { private int mInitFailNum; private boolean isStop = false; private boolean isStart = false; + private int mExeNum; /** * 文件信息回调组 @@ -89,6 +90,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { return; } Set keys = mExeMap.keySet(); + mExeNum = mExeMap.size(); for (String key : keys) { DownloadTaskEntity taskEntity = mExeMap.get(key); if (taskEntity != null) { @@ -161,11 +163,11 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { */ private void checkStartFlow() { synchronized (DownloadGroupUtil.class) { - if (mInitFailNum == mExeMap.size()) { + if (mInitFailNum == mExeNum) { closeTimer(false); mListener.onFail(true); } - if (!isStart && mInitCompleteNum + mInitFailNum == mExeMap.size() || !isNeedLoadFileSize) { + if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) { startRunningFlow(); updateFileSize(); isStart = true; diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java index c4a10c5c..34e3367e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -50,6 +50,9 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable */ private String convertFileSize; + /** + * 任务状态{@link IEntity} + */ private int state = STATE_WAIT; /** * 当前下载进度 diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 90f5f8f9..730d00bf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -158,7 +158,7 @@ abstract class AbsSchedulers { /** * 通过上传路径获取上传实体 + * 如果任务不存在,方便null */ public UploadEntity getUploadEntity(String filePath) { + if (TextUtils.isEmpty(filePath)) { + return null; + } return DbEntity.findFirst(UploadEntity.class, "filePath=?", filePath); } @@ -98,7 +102,6 @@ public class UploadReceiver extends AbsReceiver { "isGroupChild=? and isComplete=?", "false", "true"); } - @Override public void stopAllTask() { AriaManager.getInstance(AriaManager.APP) .setCmd(NormalCmdFactory.getInstance() diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index fda45c05..47446a22 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -40,6 +40,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.orm.DbEntity; import dalvik.system.DexFile; +import dalvik.system.PathClassLoader; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -74,26 +75,36 @@ public class CommonUtil { /** * 获取某包下所有类 * - * @param packageName 包名 + * @param className 过滤的类名 * @return 类的完整名称 */ - public static List getClassName(Context context, String packageName) { + public static List getClassName(Context context, String className) { List classNameList = new ArrayList<>(); try { String pPath = context.getPackageCodePath(); File dir = new File(pPath).getParentFile(); + //PathClassLoader classLoader = (PathClassLoader) context.getClassLoader(); String dPath = dir.getPath(); for (String path : dir.list()) { String fPath = dPath + "/" + path; + Log.d(TAG, fPath); if (!fPath.endsWith(".apk")) { continue; } DexFile df = new DexFile(fPath);//通过DexFile查找当前的APK中可执行文件 Enumeration enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式 - while (enumeration.hasMoreElements()) {//遍历 - String className = enumeration.nextElement(); - if (className.contains(packageName)) {//在当前所有可执行的类里面查找包含有该包名的所有类 - classNameList.add(className); + while (enumeration.hasMoreElements()) { + String _className = enumeration.nextElement(); + if (!_className.contains(className)) { + continue; + } + //Class clazz = classLoader.loadClass(_className); // 处理4.4手机无法获取到类的问题 + //String cn = clazz.getName(); + //if (clazz.getName().contains(className)) {//在当前所有可执行的类里面查找包含有该包名的所有类 + // classNameList.add(_className); + //} + if (_className.contains(className)){ + classNameList.add(_className); } } df.close(); @@ -101,6 +112,9 @@ public class CommonUtil { } catch (IOException e) { e.printStackTrace(); } + //catch (ClassNotFoundException e) { + // e.printStackTrace(); + //} return classNameList; } @@ -395,7 +409,6 @@ public class CommonUtil { if (subs != null) { for (DownloadEntity sub : subs) { File file = new File(sub.getDownloadPath()); - Log.d(TAG, "exist == " + file.exists() + ", rf == " + removeFile + ", complete = " + sub.isComplete()); if (file.exists() && (removeFile || !sub.isComplete())) { file.delete(); } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 17633b96..ae9d6fd3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,10 +16,10 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java b/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java index 8595df26..b102585e 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java +++ b/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java @@ -32,7 +32,7 @@ public class GroupModule extends BaseModule { public List getUrls() { List urls = new ArrayList<>(); - String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); + String[] str = getContext().getResources().getStringArray(R.array.group_url4); Collections.addAll(urls, str); return urls; } diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java index e2eaa945..8591cb13 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java @@ -121,6 +121,7 @@ public class MultiTaskActivity extends BaseActivity { @DownloadGroup.onTaskStop void groupTaskStop(DownloadGroupTask task) { mAdapter.updateBtState(task.getKey(), true); + Log.d(TAG, String.format("group【%s】stop", task.getTaskName())); } @DownloadGroup.onTaskCancel void groupTaskCancel(DownloadGroupTask task) { @@ -129,6 +130,7 @@ public class MultiTaskActivity extends BaseActivity { @DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) { mAdapter.updateBtState(task.getKey(), true); + Log.d(TAG, String.format("group【%s】fail", task.getTaskName())); } @DownloadGroup.onTaskComplete void taskComplete(DownloadGroupTask task) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 911363ca..e8ac188a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,11 @@ http://static.gaoshouyou.com/d/92/12/5592a647b8126755647abbe8074fde39.apk + + http://120.79.135.3/img/20180601/VR Karts Sprint.ver.1.04.build.15_crack_align.apk + http://120.79.135.3/img/20180601/main.11.com.daydvr.acefishing.vr.freefull.google.global.android.common.obb + + 战斗吧剑灵.apk diff --git a/build.gradle b/build.gradle index fdd15da1..24224353 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.4.2_dev1' + publishVersion = '3.4.2_dev6' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'