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 480795d3..97a2787b 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 @@ -15,26 +15,47 @@ */ package com.arialyy.aria.core.common; +import android.os.Build; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; /** * Created by Aria.Lao on 2017/7/10. * 代理参数获取 */ public class ProxyHelper { + /** + * 普通下载任务类型 + */ + public static int PROXY_TYPE_DOWNLOAD = 0x01; + /** + * 组合下载任务类型 + */ + public static int PROXY_TYPE_DOWNLOAD_GROUP = 0x02; + ///** + // * 组合任务子任务类型 + // */ + //public static int PROXY_TYPE_DOWNLOAD_GROUP_SUB = 0x03; + /** + * 普通上传任务类型 + */ + 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 static volatile ProxyHelper INSTANCE = null; + private boolean canLoadClass = false; private ProxyHelper() { - init(); + //init(); } public static ProxyHelper getInstance() { @@ -46,14 +67,63 @@ public class ProxyHelper { return INSTANCE; } + /** + * @since 3.4.6 版本开始,已经在ElementHandler中关闭了ProxyClassCounter对象的生成 + */ + @Deprecated private void init() { List classes = CommonUtil.getPkgClassNames(AriaManager.APP, "com.arialyy.aria.ProxyClassCounter"); - for (String className : classes) { - count(className); + canLoadClass = classes != null + && !classes.isEmpty() + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + if (canLoadClass) { + for (String className : classes) { + count(className); + } + } + } + + /** + * 是否能读取到代理计数文件 + * + * @return {@code true} 可以读取,{@code false} 不能读取 + */ + public boolean isCanLoadCountClass() { + return canLoadClass; + } + + /** + * 检查观察者对象的代理文件类型 + * + * @param clazz 观察者对象 + * @return {@link #PROXY_TYPE_DOWNLOAD},如果没有实体对象则返回空的list + */ + public Set checkProxyType(Class clazz) { + final String className = clazz.getName(); + Set result = mProxyCache.get(clazz.getName()); + if (result != null) { + return result; + } + result = new HashSet<>(); + try { + if (Class.forName(className.concat("$$DownloadGroupListenerProxy")) != null) { + result.add(PROXY_TYPE_DOWNLOAD_GROUP); + } else if (Class.forName(className.concat("$$DownloadListenerProxy")) != null) { + result.add(PROXY_TYPE_DOWNLOAD); + } else if (Class.forName(className.concat("$$UploadListenerProxy")) != null) { + result.add(PROXY_TYPE_UPLOAD); + } + } catch (ClassNotFoundException e) { + //e.printStackTrace(); + } + if (!result.isEmpty()) { + mProxyCache.put(clazz.getName(), result); } + return result; } + @Deprecated private void count(String className) { try { Class clazz = Class.forName(className); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java index cad1c6e1..9201fa85 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java @@ -50,8 +50,8 @@ public class StateConstance { * 所有子线程是否都已经停止 */ public boolean isStop() { - ALog.d(TAG, String.format("stop_num=%s; start_thread_num=%s; complete_num=%s", STOP_NUM, - START_THREAD_NUM, COMPLETE_THREAD_NUM)); + //ALog.d(TAG, String.format("stop_num=%s; start_thread_num=%s; complete_num=%s", STOP_NUM, + // START_THREAD_NUM, COMPLETE_THREAD_NUM)); return STOP_NUM == START_THREAD_NUM || STOP_NUM + COMPLETE_THREAD_NUM == START_THREAD_NUM; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index 85100747..8cbb23dc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core.download; import android.support.annotation.CheckResult; import android.support.annotation.NonNull; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.delegate.HttpHeaderDelegate; import com.arialyy.aria.core.inf.IHttpHeaderTarget; @@ -66,8 +67,8 @@ public class DownloadGroupTarget extends BaseGroupTarget im private void init() { mGroupName = CommonUtil.getMd5Code(mUrls); mTaskEntity = TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, mUrls); + //ALog.d(TAG, "gHash=" + mEntity.getSubEntities().get(0).hashCode() + "; subHash="+mEntity.getT) mEntity = mTaskEntity.getEntity(); - if (mEntity != null) { mDirPathTemp = mEntity.getDirPath(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 78cd6e7b..28c3a725 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -49,7 +49,6 @@ public class DownloadGroupTask extends AbsGroupTask { mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity); break; } - Log.d(TAG, "FTP_TASK_MD5:" + mTaskEntity.hashCode()); } @Override public boolean isRunning() { 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 b688ffaf..686ec364 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 @@ -160,15 +160,17 @@ 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().register(obj); - } - if ((dgCounter != null && dgCounter.contains(targetName)) || (dgsCounter != null - && dgsCounter.contains(targetName))) { - DownloadGroupSchedulers.getInstance().register(obj); + Set set = ProxyHelper.getInstance().checkProxyType(obj.getClass()); + if (set != null && !set.isEmpty()) { + for (Integer type : set) { + if (type == ProxyHelper.PROXY_TYPE_DOWNLOAD) { + DownloadSchedulers.getInstance().register(obj); + } else if (type == ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP) { + DownloadGroupSchedulers.getInstance().register(obj); + } + } + } else { + ALog.i(TAG, "没有Aria的注解方法"); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java index 5dd0f510..73582af9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java @@ -59,15 +59,11 @@ class DGTEFactory implements IGTEFactory keys = am.getReceiver().keySet(); for (String key : keys) { am.getReceiver().remove(key); @@ -148,9 +150,15 @@ public class UploadReceiver extends AbsReceiver { ALog.e(TAG, String.format("【%s】观察者为空", targetName)); return; } - Set cCounter = ProxyHelper.getInstance().uploadCounter; - if (cCounter != null && cCounter.contains(targetName)) { - UploadSchedulers.getInstance().register(obj); + Set set = ProxyHelper.getInstance().checkProxyType(obj.getClass()); + if (set != null && !set.isEmpty()) { + for (Integer type : set) { + if (type == ProxyHelper.PROXY_TYPE_UPLOAD) { + UploadSchedulers.getInstance().register(obj); + } + } + } else { + ALog.i(TAG, "没有Aria的注解方法"); } } diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java b/AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java index 7a6ed484..3783e222 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java @@ -35,7 +35,7 @@ import javax.lang.model.element.Modifier; * Created by lyy on 2017/9/6. * 各类注解统计技术类 */ -final class CountFiler { +@Deprecated final class CountFiler { private Filer mFiler; private ParamObtainUtil mPbUtil; diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java index e497fe65..9d92dd12 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java @@ -142,7 +142,7 @@ class ElementHandler { void createProxyFile() { try { new EventProxyFiler(mFiler, mPbUtil).createEventProxyFile(); - new CountFiler(mFiler, mPbUtil).createCountFile(); + //new CountFiler(mFiler, mPbUtil).createCountFile(); } catch (IOException e) { e.printStackTrace(); } diff --git a/DEV_LOG.md b/DEV_LOG.md index a5ba12cc..8052e351 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,10 @@ ## 开发日志 + + v_3.4.6 + - 修复android 4.4.4 版本多dex下无法进行回调的问题 + - 优化分块下载 + - 修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题 + - 修复连接中有`+`导致的地址呗使用问题。 + - 修复表重复创建导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/264 + v_3.4.4 - 实现[多线程分块下载](https://aria.laoyuyu.me/aria_doc/start/config.html) - 修复`stopAll()`和`resumeAll()`导致的进度为0问题 diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index 6811af74..dc705a90 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -22,6 +22,7 @@ import android.view.View; import butterknife.Bind; import com.arialyy.annotations.DownloadGroup; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; @@ -133,14 +134,15 @@ public class DownloadGroupActivity extends BaseActivity