From a63222a220747b40893909b81f22ffae4605a843 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Fri, 17 Aug 2018 21:38:10 +0800 Subject: [PATCH] fix bug https://github.com/AriaLyy/Aria/issues/288 https://github.com/AriaLyy/Aria/issues/282 --- .../arialyy/aria/core/common/ProxyHelper.java | 2 +- .../aria/core/download/BaseNormalTarget.java | 2 +- .../aria/core/download/DownloadReceiver.java | 18 +++++++++--------- .../core/download/downloader/AbsGroupUtil.java | 9 +++++---- .../aria/core/manager/ThreadTaskManager.java | 4 ++++ .../aria/core/scheduler/AbsSchedulers.java | 1 + .../aria/core/upload/UploadReceiver.java | 11 ++++++++--- .../com/arialyy/aria/orm/DelegateUpdate.java | 6 +++--- .../java/com/arialyy/aria/util/CommonUtil.java | 11 +++++++---- DEV_LOG.md | 5 +++++ README.md | 13 +++++-------- app/src/main/AndroidManifest.xml | 4 ++-- .../simple/download/SingleTaskActivity.java | 7 +++++-- .../arialyy/simple/test/AnyRunActivity.java | 3 ++- .../com/arialyy/simple/test/AnyRunnModule.java | 10 +++++----- .../arialyy/simple/test/TestFTPActivity.java | 5 ++--- build.gradle | 2 +- 17 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java index 8dd0e254..a1d64f23 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java @@ -49,7 +49,7 @@ public class ProxyHelper { public static int PROXY_TYPE_UPLOAD = 0x04; public Set downloadCounter = new HashSet<>(), uploadCounter = new HashSet<>(), downloadGroupCounter = new HashSet<>(), downloadGroupSubCounter = new HashSet<>(); - private Map> mProxyCache = new ConcurrentHashMap<>(); + public Map> mProxyCache = new ConcurrentHashMap<>(); public static volatile ProxyHelper INSTANCE = null; private boolean canLoadClass = false; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java index b272d294..154ecd1e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java @@ -86,7 +86,7 @@ abstract class BaseNormalTarget * @return {@code true}任务存在 */ @Override public boolean taskExists() { - return DownloadTaskQueue.getInstance().getTask(mEntity.getUrl()) != null; + return DownloadTaskQueue.getInstance().getTask(mEntity.getKey()) != null; } /** 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 143c0a69..b3c84d77 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 @@ -206,15 +206,15 @@ public class DownloadReceiver extends AbsReceiver { ALog.e(TAG, String.format("【%s】观察者为空", targetName)); return; } - Set dCounter = ProxyHelper.getInstance().downloadCounter; - Set dgCounter = ProxyHelper.getInstance().downloadGroupCounter; - Set dgsCounter = ProxyHelper.getInstance().downloadGroupSubCounter; - if (dCounter != null && dCounter.contains(targetName)) { - DownloadSchedulers.getInstance().unRegister(obj); - } - if (dgCounter != null && dgCounter.contains(targetName) || (dgsCounter != null - && dgsCounter.contains(targetName))) { - DownloadGroupSchedulers.getInstance().unRegister(obj); + Set set = ProxyHelper.getInstance().mProxyCache.get(obj.getClass().getName()); + if (set != null) { + for (Integer integer : set) { + if (integer == ProxyHelper.PROXY_TYPE_DOWNLOAD) { + DownloadSchedulers.getInstance().unRegister(obj); + } else if (integer == ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP) { + DownloadGroupSchedulers.getInstance().unRegister(obj); + } + } } } 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 03a1b21b..9e9ed848 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 @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -63,22 +64,22 @@ public abstract class AbsGroupUtil implements IUtil { /** * 保存所有没有下载完成的任务,key为下载地址 */ - Map mExeMap = new HashMap<>(); + Map mExeMap = new ConcurrentHashMap<>(); /** * 下载失败的映射表,key为下载地址 */ - Map mFailMap = new HashMap<>(); + Map mFailMap = new ConcurrentHashMap<>(); /** * 该任务组对应的所有任务 */ - private Map mTasksMap = new HashMap<>(); + private Map mTasksMap = new ConcurrentHashMap<>(); /** * 下载器映射表,key为下载地址 */ - private Map mDownloaderMap = new HashMap<>(); + private Map mDownloaderMap = new ConcurrentHashMap<>(); /** * 是否需要读取文件长度,{@code true}需要 diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java new file mode 100644 index 00000000..d0ccb984 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java @@ -0,0 +1,4 @@ +package com.arialyy.aria.core.manager; + +public class ThreadTaskManager { +} 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 ceb1a5c6..46831b45 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 @@ -259,6 +259,7 @@ abstract class AbsSchedulers dCounter = ProxyHelper.getInstance().uploadCounter; - if (dCounter != null && dCounter.contains(targetName)) { - UploadSchedulers.getInstance().unRegister(obj); + + Set set = ProxyHelper.getInstance().mProxyCache.get(obj.getClass().getName()); + if (set != null) { + for (Integer integer : set) { + if (integer == ProxyHelper.PROXY_TYPE_UPLOAD) { + UploadSchedulers.getInstance().unRegister(obj); + } + } } } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java index f1a87b81..66239fb9 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java @@ -82,7 +82,7 @@ class DelegateUpdate extends AbsDelegate { /** * 删除某条数据 */ - void delData(SQLiteDatabase db, Class clazz, String... expression) { + synchronized void delData(SQLiteDatabase db, Class clazz, String... expression) { db = checkDb(db); CheckUtil.checkSqlExpression(expression); @@ -101,7 +101,7 @@ class DelegateUpdate extends AbsDelegate { /** * 修改某行数据 */ - void modifyData(SQLiteDatabase db, DbEntity dbEntity) { + synchronized void modifyData(SQLiteDatabase db, DbEntity dbEntity) { db = checkDb(db); Class clazz = dbEntity.getClass(); List fields = CommonUtil.getAllFields(clazz); @@ -141,7 +141,7 @@ class DelegateUpdate extends AbsDelegate { /** * 插入数据 */ - void insertData(SQLiteDatabase db, DbEntity dbEntity) { + synchronized void insertData(SQLiteDatabase db, DbEntity dbEntity) { db = checkDb(db); Class clazz = dbEntity.getClass(); List fields = CommonUtil.getAllFields(clazz); 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 326c406d..3d33e56c 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -502,11 +502,14 @@ public class CommonUtil { } } } - File dir = new File(groupEntity.getDirPath()); - if (dir.exists() && (removeFile || !groupEntity.isComplete())) { - dir.delete(); + + if (!TextUtils.isEmpty(groupEntity.getDirPath())) { + File dir = new File(groupEntity.getDirPath()); + if (dir.exists() && (removeFile || !groupEntity.isComplete())) { + dir.delete(); + } + groupEntity.deleteData(); } - groupEntity.deleteData(); } /** diff --git a/DEV_LOG.md b/DEV_LOG.md index 1760c145..1143fec3 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,9 @@ ## 开发日志 + + v_3.4.11 + - fix bug https://github.com/AriaLyy/Aria/issues/288 + - fix bug https://github.com/AriaLyy/Aria/issues/282 + + v_3.4.10 + - fix bug https://github.com/AriaLyy/Aria/issues/280 + v_3.4.9 - fix bug https://github.com/AriaLyy/Aria/issues/276 + v_3.4.8 diff --git a/README.md b/README.md index 0c57ecc4..cf24cb27 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.4.9' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.9' +compile 'com.arialyy.aria:aria-core:3.4.11' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.11' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:'`替换为 ``` @@ -101,12 +101,9 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 - + v_3.4.8 - - 组合任务新增`updateUrls(List)`用于修改组合子任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/update_url.html) - - 出于安全考虑,FTP数据库去掉密码的保存 - - 增加FTPS支持 [see](https://aria.laoyuyu.me/aria_doc/download/ftps.html) - - 增加速度限制支持[see](https://aria.laoyuyu.me/aria_doc/api/speed_handle.html) - - 增加内存空间不足验证 + + v_3.4.11 + - fix bug https://github.com/AriaLyy/Aria/issues/288 + - fix bug https://github.com/AriaLyy/Aria/issues/282 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 87d31608..314d14ce 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/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 7093e227..0bb2cc84 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -33,6 +33,7 @@ import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; @@ -130,6 +131,7 @@ public class SingleTaskActivity extends BaseActivity { } @Download.onTaskRunning protected void running(DownloadTask task) { + ALog.d(TAG, String.format("%s_running_%s", getClass().getName(), hashCode())); if (task.getKey().equals(DOWNLOAD_URL)) { //Log.d(TAG, task.getKey()); long len = task.getFileSize(); @@ -220,8 +222,9 @@ public class SingleTaskActivity extends BaseActivity { startD(); break; case R.id.stop: - Aria.download(this).load(DOWNLOAD_URL).stop(); - //startActivity(new Intent(this, SingleTaskActivity.class)); + //Aria.download(this).load(DOWNLOAD_URL).stop(); + startActivity(new Intent(this, SingleTaskActivity.class)); + Aria.download(this).unRegister(); //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; case R.id.cancel: diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java index 4a903a86..8433f960 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java @@ -26,11 +26,12 @@ public class AnyRunActivity extends BaseActivity { //String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk"; //String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar"; - String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; + //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; //String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk"; //String URL = "ftps://192.168.29.140:990/download/SDK_Demo-release.apk"; //String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176"; //String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv"; + String URL = "https://app-dl.byfen.com//app//201810//ef0400d637e768e9c630b4d38633ee06.zip"; //private String URL = "https://www.bilibili.com/bangumi/play/ep77693"; //private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1"; diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java index 6ca15480..5388313f 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java @@ -64,7 +64,7 @@ public class AnyRunnModule { void start(String url) { mUrl = url; - String path = Environment.getExternalStorageDirectory().getPath() + "/mmm1.mp4"; + String path = Environment.getExternalStorageDirectory().getPath() + "/mmm2.mp4"; Aria.download(this) .load(url) .setRequestMode(RequestEnum.GET) @@ -79,10 +79,10 @@ public class AnyRunnModule { .loadFtp(url) .login("lao", "123456") .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/") - .asFtps() - .setStorePath("/mnt/sdcard/Download/server.crt") - .setAlias("www.laoyuyu.me") - .setStorePass("123456") + //.asFtps() + //.setStorePath("/mnt/sdcard/Download/server.crt") + //.setAlias("www.laoyuyu.me") + //.setStorePass("123456") .start(); } diff --git a/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java b/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java index 3ca181e2..39747303 100644 --- a/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/TestFTPActivity.java @@ -25,7 +25,7 @@ public class TestFTPActivity extends BaseActivity { //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 FILE_PATH = "/mnt/sdcard/mmm.mp4"; - private final String URL = "ftps://192.168.29.140:990/aa/你好"; + private final String URL = "ftps://9.9.9.59:990/aa/你好"; @Override protected int setLayoutId() { @@ -82,8 +82,7 @@ public class TestFTPActivity extends BaseActivity { .loadFtp(FILE_PATH) .login("lao", "123456") .setUploadUrl(URL) - .setExtendField("韩寒哈大双") - .asFtps() + //.asFtps() //.setStorePath("/mnt/sdcard/Download/server.crt") //.setAlias("www.laoyuyu.me") .start(); diff --git a/build.gradle b/build.gradle index f7206410..5cadcae4 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.9' + publishVersion = '3.4.11' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'