修复4.4.4系统在多个dex的情况下,无法进行回调的问题;修复组合任务子任务索引问题

pull/330/head
laoyuyu 6 years ago
parent 8201eef571
commit 671ae11e2b
  1. 76
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  3. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  4. 1
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  5. 20
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  6. 6
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java
  7. 22
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  8. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java
  9. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java
  10. 6
      DEV_LOG.md
  11. 64
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  12. 12
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  13. 2
      app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java
  14. 2
      build.gradle

@ -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<String> downloadCounter = new HashSet<>(), uploadCounter = new HashSet<>(),
downloadGroupCounter = new HashSet<>(), downloadGroupSubCounter = new HashSet<>();
private Map<String, Set<Integer>> 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<String> 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<Integer> checkProxyType(Class clazz) {
final String className = clazz.getName();
Set<Integer> 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);

@ -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;
}

@ -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<DownloadGroupTarget> 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();
}

@ -49,7 +49,6 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity> {
mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity);
break;
}
Log.d(TAG, "FTP_TASK_MD5:" + mTaskEntity.hashCode());
}
@Override public boolean isRunning() {

@ -160,15 +160,17 @@ public class DownloadReceiver extends AbsReceiver {
ALog.e(TAG, String.format("【%s】观察者为空", targetName));
return;
}
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
Set<String> 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<Integer> 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的注解方法");
}
}

@ -59,15 +59,11 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
if (gte == null) {
// 创建新的任务组任务实体
gte = new DownloadGroupTaskEntity();
//创建子任务的任务实体
gte.setSubTaskEntities(createDGSubTaskEntity(entity));
} else if (gte.getSubTaskEntities() == null || gte.getSubTaskEntities().isEmpty()) {
gte.setSubTaskEntities(createDGSubTaskEntity(entity));
}
} else {
gte = new DownloadGroupTaskEntity();
gte.setSubTaskEntities(createDGSubTaskEntity(entity));
}
gte.setSubTaskEntities(createDGSubTaskEntity(entity));
gte.setKey(entity.getGroupName());
gte.setEntity(entity);

@ -20,6 +20,7 @@ import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelAllCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.inf.AbsReceiver;
@ -125,10 +126,11 @@ public class UploadReceiver extends AbsReceiver {
*/
public void removeAllTask(boolean removeFile) {
final AriaManager am = AriaManager.getInstance(AriaManager.APP);
am.setCmd(CommonUtil.createNormalCmd(targetName, new UploadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD)).exe();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(targetName, new UploadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD);
cancelCmd.removeFile = removeFile;
am.setCmd(cancelCmd).exe();
Set<String> 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<String> cCounter = ProxyHelper.getInstance().uploadCounter;
if (cCounter != null && cCounter.contains(targetName)) {
UploadSchedulers.getInstance().register(obj);
Set<Integer> 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的注解方法");
}
}

@ -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;

@ -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();
}

@ -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问题

@ -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<ActivityDownloadGroupBin
}
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
Log.d(TAG, "group running, p = "
+ task.getPercent()
+ ", speed = "
+ task.getConvertSpeed()
+ "current_p = "
+ task.getCurrentProgress());
//Log.d(TAG, "group running, p = "
// + task.getPercent()
// + ", speed = "
// + task.getConvertSpeed()
// + "current_p = "
// + task.getCurrentProgress());
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
//Log.d(TAG, "sub_len = " + task.getEntity().getSubEntities().size());
mChildList.updateChildProgress(task.getEntity().getSubEntities());
}
@ -170,4 +172,54 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
T.showShort(this, "任务组下载完成");
L.d(TAG, "任务组下载完成");
}
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
//ALog.d(TAG, "sub_percent = " + subEntity.getPercent());
Log.e(TAG, "gHash = "
+ groupTask.getEntity().getSubEntities().get(0).hashCode()
+ "; subHash = "
+ groupTask.getTaskEntity().getSubTaskEntities().get(0).getEntity().hashCode() +
"; subHash = " + subEntity.hashCode());
int percent = subEntity.getPercent();
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
String convertSpeed = subEntity.getConvertSpeed();
//当前下载完成的进度,长度bytes
long completedSize = subEntity.getCurrentProgress();
Log.d(TAG, "subTask名字:"
+ subEntity.getFileName()
+ ", "
+ " speed:"
+ convertSpeed
+ ",percent: "
+ percent
+ "%, completedSize:"
+ completedSize);
}
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
}
@DownloadGroup.onSubTaskStop void onSubTaskStop(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
}
@DownloadGroup.onSubTaskStart void onSubTaskStart(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
}
//@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
// DownloadEntity subEntity) {
// Log.d(TAG, "new Size: " + groupTask.getConvertFileSize());
// mSub.setText("子任务:" + mChildName + ",状态:取消下载");
//}
@DownloadGroup.onSubTaskComplete void onSubTaskComplete(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
}
@DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
}
}

@ -58,8 +58,8 @@ public class GroupModule extends BaseModule {
// taskSubFile.add("2115.mp4");
//taskSubFile.add("2009.mp4");
//taskSubFile.add("1893.mp4");
//taskSubFile.add("1952.mp4");
//taskSubFile.add("1958.mp4");
taskSubFile.add("1952.mp4");
taskSubFile.add("1958.mp4");
taskSubFile.add("1994.mp4");
//taskSubFile.add("2083.mp4");
taskSubFile.add("2305.JPG");
@ -88,10 +88,10 @@ public class GroupModule extends BaseModule {
// "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2009&clientId=A000011106034058176");
//downLoadUrls.add(
// "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1893&clientId=A000011106034058176");
//downLoadUrls.add(
// "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1952&clientId=A000011106034058176");
//downLoadUrls.add(
// "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1958&clientId=A000011106034058176");
downLoadUrls.add(
"http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1952&clientId=A000011106034058176");
downLoadUrls.add(
"http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1958&clientId=A000011106034058176");
downLoadUrls.add(
"http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176");
//downLoadUrls.add(

@ -18,6 +18,7 @@ package com.arialyy.simple.widget;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
@ -105,6 +106,7 @@ public class SubStateLinearLayout extends LinearLayout implements View.OnClickLi
if (position != -1) {
TextView child = ((TextView) getChildAt(position));
int p = getPercent(entity);
Log.d("TAG", "p = " + p);
child.setText(entity.getFileName() + ": " + p + "%" + " | " + entity.getConvertSpeed());
child.invalidate();
}

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.4.5'
publishVersion = '3.4.6_dev2'
// publishVersion = '1.0.3' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save