修复组合任务单线程下载过程中应用被杀,文件变大的问题

pull/330/head
laoyuyu 6 years ago
parent 671ae11e2b
commit 3c05d8cafc
  1. 178
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 104
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 16
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  4. 5
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  7. 9
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  10. 2
      app/src/main/AndroidManifest.xml
  11. 59
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  12. 3
      app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java
  13. 4
      app/src/main/res/values/strings.xml
  14. 2
      build.gradle

@ -109,6 +109,28 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
startFlow(); startFlow();
} }
/**
* 重置任务状态
*/
private void resetState() {
closeTimer();
mCompleteThreadNum = 0;
mTotalThreadNum = 0;
mStartThreadNum = 0;
if (mFixedThreadPool != null) {
mFixedThreadPool.shutdown();
}
if (mTask != null && !mTask.isEmpty()) {
for (int i = 0; i < mTask.size(); i++) {
AbsThreadTask task = mTask.get(i);
if (task != null && !task.isRunning()) {
task.breakTask();
}
}
mTask.clear();
}
}
/** /**
* 开始流程 * 开始流程
*/ */
@ -116,8 +138,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (isBreak()) { if (isBreak()) {
return; return;
} }
resetState();
mConstance.resetState(); mConstance.resetState();
checkRecord(); checkRecord();
mConstance.isRunning = true;
mConstance.TASK_RECORD = mRecord; mConstance.TASK_RECORD = mRecord;
if (mListener instanceof IDownloadListener) { if (mListener instanceof IDownloadListener) {
((IDownloadListener) mListener).onPostPre(mEntity.getFileSize()); ((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
@ -281,13 +305,75 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) { if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
initRecord(true); initRecord(true);
} else if (mRecord.isBlock) { } else if (mRecord.isBlock) {
handleBlockRecord();
} else {
handleNormalRecord();
}
}
}
}
/**
* 处理普通任务的记录
*/
private void handleNormalRecord() {
File file = new File(mRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));
mRecord.deleteData();
initRecord(true);
return;
}
if (mRecord.isOpenDynamicFile) {
ThreadRecord tr = mRecord.threadRecords.get(0);
if (tr == null) {
mTaskEntity.setNewTask(true);
mTotalThreadNum = 1;
return;
}
if (file.length() > mEntity.getFileSize()) {
ALog.i(TAG, String.format("文件【%s】错误,任务重新开始", file.getPath()));
file.delete();
tr.startLocation = 0;
tr.isComplete = false;
tr.endLocation = mEntity.getFileSize();
mStartThreadNum++;
} else if (file.length() == mEntity.getFileSize()) {
tr.isComplete = true;
mCompleteThreadNum++;
} else {
if (file.length() != tr.startLocation) {
ALog.i(TAG, String.format("修正【%s】的进度记录为:%s", file.getPath(), file.length()));
tr.startLocation = file.length();
tr.isComplete = false;
mStartThreadNum++;
}
}
} else {
for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
mStartThreadNum++;
}
}
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
}
/**
* 处理分块任务的记录
*/
private void handleBlockRecord() {
final int threadNum = mRecord.threadRecords.size(); final int threadNum = mRecord.threadRecords.size();
final long blockLen = mEntity.getFileSize() / threadNum; final long blockLen = mEntity.getFileSize() / threadNum;
int i = 0; int i = 0;
for (ThreadRecord tr : mRecord.threadRecords) { for (ThreadRecord tr : mRecord.threadRecords) {
File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId)); File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId));
if (!temp.exists()) { if (!temp.exists()) {
ALog.w(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath())); ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false; tr.isComplete = false;
tr.startLocation = -1; tr.startLocation = -1;
mStartThreadNum++; mStartThreadNum++;
@ -296,7 +382,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mCompleteThreadNum++; mCompleteThreadNum++;
} else { } else {
long realLocation = i * blockLen + temp.length(); long realLocation = i * blockLen + temp.length();
ALog.w(TAG, String.format( ALog.i(TAG, String.format(
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s", "startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s",
tr.startLocation, tr.endLocation, blockLen, temp.length(), i)); tr.startLocation, tr.endLocation, blockLen, temp.length(), i));
if (tr.endLocation == realLocation) { if (tr.endLocation == realLocation) {
@ -307,10 +393,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} else { } else {
tr.isComplete = false; tr.isComplete = false;
if (realLocation < tr.startLocation) { if (realLocation < tr.startLocation) {
ALog.w(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation)); ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
tr.startLocation = realLocation; tr.startLocation = realLocation;
} else if (realLocation > tr.endLocation) { } else if (realLocation > tr.endLocation) {
ALog.w(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath())); ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
temp.delete(); temp.delete();
tr.startLocation = i * blockLen; tr.startLocation = i * blockLen;
} }
@ -322,26 +408,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} }
mTotalThreadNum = mRecord.threadRecords.size(); mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false); mTaskEntity.setNewTask(false);
} else {
File file = new File(mRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));
mRecord.deleteData();
initRecord(true);
return;
}
for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
mStartThreadNum++;
}
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
}
}
}
} }
/** /**
@ -463,7 +529,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private AbsThreadTask createSingThreadTask(int i, long startL, long endL, long fileLength, private AbsThreadTask createSingThreadTask(int i, long startL, long endL, long fileLength,
ThreadRecord record) { ThreadRecord record) {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>(); SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
config.FILE_SIZE = fileLength; config.TOTAL_FILE_SIZE = fileLength;
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl(); config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE = config.TEMP_FILE =
mRecord.isBlock ? new File(String.format(SUB_PATH, mTempFile.getPath(), i)) : mTempFile; mRecord.isBlock ? new File(String.format(SUB_PATH, mTempFile.getPath(), i)) : mTempFile;
@ -566,34 +632,36 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} }
/** /**
* 重试线程任务只有线程创建成功才能重试 * 重试任务
*/ */
public void retryThreadTask() { public void retryTask() {
if (isBreak()) { ALog.w(TAG, String.format("任务【%s】开始重试", mEntity.getFileName()));
return; startFlow();
} //if (isBreak()) {
// return;
if (mTask == null || mTask.size() == 0) { //}
ALog.w(TAG, "没有线程任务"); //if (mTask == null || mTask.size() == 0) {
return; // ALog.w(TAG, "没有线程任务");
} // return;
Set<Integer> keys = mTask.keySet(); //}
for (Integer key : keys) { //Set<Integer> keys = mTask.keySet();
AbsThreadTask task = mTask.get(key); //for (Integer key : keys) {
if (task != null && !task.isThreadComplete()) { // AbsThreadTask task = mTask.get(key);
task.getConfig().START_LOCATION = task.getConfig().THREAD_RECORD.startLocation; // if (task != null && !task.isThreadComplete()) {
mConstance.resetState(); //
startTimer(); // task.getConfig().START_LOCATION = task.getConfig().THREAD_RECORD.startLocation;
ALog.d(TAG, String.format("任务【%s】开始重试,线程__%s__【开始位置:%s,结束位置:%s】", mEntity.getFileName(), // mConstance.resetState();
key, task.getConfig().START_LOCATION, task.getConfig().END_LOCATION)); // startTimer();
if (!mFixedThreadPool.isShutdown()) { // ALog.d(TAG, String.format("任务【%s】开始重试,线程__%s__【开始位置:%s,结束位置:%s】", mEntity.getFileName(),
mFixedThreadPool.execute(task); // key, task.getConfig().START_LOCATION, task.getConfig().END_LOCATION));
} else { // if (!mFixedThreadPool.isShutdown()) {
ALog.w(TAG, "线程池已关闭"); // mFixedThreadPool.execute(task);
mListener.onFail(true); // } else {
} // ALog.w(TAG, "线程池已关闭");
} // mListener.onFail(true);
} // }
// }
//}
} }
/** /**
@ -608,17 +676,17 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/ */
private void handleNoSupportBP() { private void handleNoSupportBP() {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>(); SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
config.FILE_SIZE = mEntity.getFileSize(); config.TOTAL_FILE_SIZE = mEntity.getFileSize();
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl(); config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE = mTempFile; config.TEMP_FILE = mTempFile;
config.THREAD_ID = 0; config.THREAD_ID = 0;
config.START_LOCATION = 0; config.START_LOCATION = 0;
config.END_LOCATION = config.FILE_SIZE; config.END_LOCATION = config.TOTAL_FILE_SIZE;
config.SUPPORT_BP = mTaskEntity.isSupportBP(); config.SUPPORT_BP = mTaskEntity.isSupportBP();
config.TASK_ENTITY = mTaskEntity; config.TASK_ENTITY = mTaskEntity;
ThreadRecord record = new ThreadRecord(); ThreadRecord record = new ThreadRecord();
record.startLocation = 0; record.startLocation = 0;
record.endLocation = config.FILE_SIZE; record.endLocation = config.TOTAL_FILE_SIZE;
record.key = mTempFile.getPath(); record.key = mTempFile.getPath();
config.THREAD_RECORD = record; config.THREAD_RECORD = record;
AbsThreadTask task = selectThreadTask(config); AbsThreadTask task = selectThreadTask(config);

@ -104,6 +104,52 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return mConfig.THREAD_RECORD.isComplete; return mConfig.THREAD_RECORD.isComplete;
} }
/**
* 获取任务记录
*/
public TaskRecord getTaskRecord() {
return STATE.TASK_RECORD;
}
/**
* 获取线程记录
*/
public ThreadRecord getThreadRecord() {
return mConfig.THREAD_RECORD;
}
/**
* 中断任务
*/
public void breakTask() {
synchronized (AriaManager.LOCK) {
taskBreak = true;
if (mConfig.SUPPORT_BP) {
final long currentTemp = mChildCurrentLocation;
STATE.STOP_NUM++;
ALog.d(TAG, String.format("任务【%s】thread__%s__中断【停止位置:%s】", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID, currentTemp));
writeConfig(false, currentTemp);
if (STATE.isStop()) {
ALog.i(TAG, String.format("任务【%s】已中断", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false;
}
} else {
ALog.i(TAG, String.format("任务【%s】已中断", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false;
}
}
}
/**
* 是否在运行
*
* @return {@code true}正在运行
*/
public boolean isRunning() {
return STATE.isRunning;
}
/** /**
* 获取线程配置信息 * 获取线程配置信息
*/ */
@ -250,7 +296,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) { protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (ex != null) { if (ex != null) {
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex)); //ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
} else { } else {
ALog.e(TAG, msg); ALog.e(TAG, msg);
} }
@ -280,7 +326,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mConfig.THREAD_ID)); mConfig.THREAD_ID));
} }
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP) if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
|| isNotNetRetry) && isBreak()) { || isNotNetRetry) && !isBreak()) {
mFailTimer = new Timer(true); mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() { mFailTimer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
@ -291,8 +337,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mFailTimes++; mFailTimes++;
ALog.w(TAG, String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), ALog.w(TAG, String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID)); mConfig.THREAD_ID));
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION handleRetryRecord();
: mConfig.THREAD_RECORD.startLocation;
AbsThreadTask.this.run(); AbsThreadTask.this.run();
} }
}, RETRY_INTERVAL); }, RETRY_INTERVAL);
@ -301,6 +346,44 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
} }
} }
/**
* 处理线程重试的记录只有多线程任务才会执行
*/
private void handleRetryRecord() {
if (getTaskRecord().isBlock) {
ThreadRecord tr = getThreadRecord();
long block = mEntity.getFileSize() / getTaskRecord().threadRecords.size();
File file = mConfig.TEMP_FILE;
if (file.length() > tr.endLocation) {
ALog.i(TAG, String.format("分块【%s】错误,将重新下载该分块", file.getPath()));
boolean b = file.delete();
ALog.w(TAG, "删除:" + b);
tr.startLocation = block * tr.threadId;
tr.isComplete = false;
mConfig.START_LOCATION = tr.startLocation;
} else if (file.length() == tr.endLocation) {
STATE.COMPLETE_THREAD_NUM++;
tr.isComplete = true;
} else {
tr.startLocation = file.length();
mConfig.START_LOCATION = file.length();
tr.isComplete = false;
long size = 0;
for (int i = 0, len = getTaskRecord().threadRecords.size(); i < len; i++) {
File temp = new File(String.format(AbsFileer.SUB_PATH, getTaskRecord().filePath, i));
if (temp.exists()) {
size += file.length();
}
}
STATE.CURRENT_LOCATION = size;
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s", file.getPath(), tr.startLocation));
}
} else {
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
: mConfig.THREAD_RECORD.startLocation;
}
}
/** /**
* 处理失败状态 * 处理失败状态
* *
@ -328,12 +411,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
*/ */
protected void writeConfig(boolean isComplete, final long record) { protected void writeConfig(boolean isComplete, final long record) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (mConfig.THREAD_RECORD != null) { ThreadRecord tr = getThreadRecord();
mConfig.THREAD_RECORD.isComplete = isComplete; if (tr != null) {
tr.isComplete = isComplete;
if (getTaskRecord().isBlock || getTaskRecord().isOpenDynamicFile) {
tr.startLocation = mConfig.TEMP_FILE.length();
} else {
if (0 < record && record < mConfig.END_LOCATION) { if (0 < record && record < mConfig.END_LOCATION) {
mConfig.THREAD_RECORD.startLocation = record; tr.startLocation = record;
}
} }
mConfig.THREAD_RECORD.update(); tr.update();
} }
} }
} }

@ -109,14 +109,26 @@ public class ProxyHelper {
try { try {
if (Class.forName(className.concat("$$DownloadGroupListenerProxy")) != null) { if (Class.forName(className.concat("$$DownloadGroupListenerProxy")) != null) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP); result.add(PROXY_TYPE_DOWNLOAD_GROUP);
} else if (Class.forName(className.concat("$$DownloadListenerProxy")) != null) { }
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
try {
if (Class.forName(className.concat("$$DownloadListenerProxy")) != null) {
result.add(PROXY_TYPE_DOWNLOAD); result.add(PROXY_TYPE_DOWNLOAD);
} else if (Class.forName(className.concat("$$UploadListenerProxy")) != null) { }
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
try {
if (Class.forName(className.concat("$$UploadListenerProxy")) != null) {
result.add(PROXY_TYPE_UPLOAD); result.add(PROXY_TYPE_UPLOAD);
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
//e.printStackTrace(); //e.printStackTrace();
} }
if (!result.isEmpty()) { if (!result.isEmpty()) {
mProxyCache.put(clazz.getName(), result); mProxyCache.put(clazz.getName(), result);
} }

@ -40,10 +40,13 @@ public class StateConstance {
public void resetState() { public void resetState() {
isCancel = false; isCancel = false;
isStop = false; isStop = false;
isRunning = true; isRunning = false;
CANCEL_NUM = 0; CANCEL_NUM = 0;
STOP_NUM = 0; STOP_NUM = 0;
FAIL_NUM = 0; FAIL_NUM = 0;
COMPLETE_THREAD_NUM = 0;
START_THREAD_NUM = 0;
CURRENT_LOCATION = 0;
} }
/** /**

@ -9,8 +9,8 @@ import java.io.File;
public class SubThreadConfig<TASK_ENTITY extends AbsTaskEntity> { public class SubThreadConfig<TASK_ENTITY extends AbsTaskEntity> {
//线程Id //线程Id
public int THREAD_ID; public int THREAD_ID;
//下载文件大小 //文件总长度
public long FILE_SIZE; public long TOTAL_FILE_SIZE;
//子线程启动下载位置 //子线程启动下载位置
public long START_LOCATION; public long START_LOCATION;
//子线程结束下载位置 //子线程结束下载位置

@ -170,7 +170,7 @@ public class DownloadReceiver extends AbsReceiver {
} }
} }
} else { } else {
ALog.i(TAG, "没有Aria的注解方法"); ALog.w(TAG, "没有Aria的注解方法");
} }
} }

@ -275,6 +275,7 @@ public abstract class AbsGroupUtil implements IUtil {
*/ */
protected void onPre() { protected void onPre() {
mListener.onPre(); mListener.onPre();
isRunning = true;
mGroupSize = mGTEntity.getSubTaskEntities().size(); mGroupSize = mGTEntity.getSubTaskEntities().size();
mTotalLen = mGTEntity.getEntity().getFileSize(); mTotalLen = mGTEntity.getEntity().getFileSize();
isNeedLoadFileSize = mTotalLen <= 10; isNeedLoadFileSize = mTotalLen <= 10;
@ -492,20 +493,22 @@ public abstract class AbsGroupUtil implements IUtil {
subEntity.setFailNum(subEntity.getFailNum() + 1); subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen); saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0); handleSpeed(0);
reTry(needRetry); //reTry(needRetry);
reTry(false);
} }
/** /**
* 重试下载只有全部都下载失败才会执行任务组的整体重试否则只会执行单个子任务的重试 * 重试下载只有全部都下载失败才会执行任务组的整体重试否则只会执行单个子任务的重试
*/ */
private void reTry(boolean needRetry) { private void reTry(boolean needRetry) {
Downloader dt = mDownloaderMap.get(subEntity.getUrl());
synchronized (AbsGroupUtil.LOCK) { synchronized (AbsGroupUtil.LOCK) {
Downloader dt = mDownloaderMap.get(subEntity.getUrl());
if (!isCancel && !isStop && dt != null if (!isCancel && !isStop && dt != null
&& !dt.isBreak() && !dt.isBreak()
&& needRetry && needRetry
&& subEntity.getFailNum() < 3 && subEntity.getFailNum() < 3
&& (NetUtils.isConnected(AriaManager.APP) || isNotNetRetry)) { && (NetUtils.isConnected(AriaManager.APP) || isNotNetRetry)) {
ALog.d(TAG, "downloader retry");
reStartTask(dt); reStartTask(dt);
} else { } else {
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity); mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
@ -531,7 +534,7 @@ public abstract class AbsGroupUtil implements IUtil {
timer.schedule(new TimerTask() { timer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
if (dt != null) { if (dt != null) {
dt.retryThreadTask(); dt.retryTask();
} }
} }
}, 5000); }, 5000);

@ -163,6 +163,10 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
*/ */
private void checkStartFlow() { private void checkStartFlow() {
synchronized (DownloadGroupUtil.class) { synchronized (DownloadGroupUtil.class) {
if (isStop) {
closeTimer();
return;
}
if (mInitFailNum == mExeNum) { if (mInitFailNum == mExeNum) {
closeTimer(); closeTimer();
mListener.onFail(true); mListener.onFail(true);

@ -60,7 +60,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
} }
@Override public void run() { @Override public void run() {
if (mConfig.THREAD_RECORD.isComplete) { if (getThreadRecord().isComplete) {
handleComplete(); handleComplete();
return; return;
} }

@ -14,10 +14,10 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".test.TestActivity"--> <!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.TestGroupActivity"--> <!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"--> <!--android:name=".MainActivity"-->
<!--android:name="com.arialyy.simple.test.AnyRunActivity"--> <!--android:name="com.arialyy.simple.test.AnyRunActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<activity <activity
android:name=".download.group.DownloadGroupActivity" android:name=".download.group.DownloadGroupActivity"
android:label="@string/app_name"> android:label="@string/app_name">

@ -46,7 +46,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
super.init(savedInstanceState); super.init(savedInstanceState);
Aria.download(this).register(); Aria.download(this).register();
setTitle("任务组"); setTitle("任务组");
mUrls = getModule(GroupModule.class).getUrls2(); mUrls = getModule(GroupModule.class).getUrls1();
DownloadGroupTaskEntity entity = Aria.download(this).getGroupTask(mUrls); DownloadGroupTaskEntity entity = Aria.download(this).getGroupTask(mUrls);
if (entity != null && entity.getEntity() != null) { if (entity != null && entity.getEntity() != null) {
DownloadGroupEntity groupEntity = entity.getEntity(); DownloadGroupEntity groupEntity = entity.getEntity();
@ -83,9 +83,11 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this) Aria.download(this)
.loadGroup(mUrls) .loadGroup(mUrls)
.setDirPath( .setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_5") //Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_5")
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_1")
.setGroupAlias("任务组测试") .setGroupAlias("任务组测试")
.setSubFileName(getModule(GroupModule.class).getSubName2()) //.setSubFileName(getModule(GroupModule.class).getSubName2())
.setSubFileName(getModule(GroupModule.class).getSubName())
//.setFileSize(32895492) //.setFileSize(32895492)
.start(); .start();
break; break;
@ -134,12 +136,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) { @DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
//Log.d(TAG, "group running, p = " Log.d(TAG, "group running, p = "
// + task.getPercent() + task.getPercent()
// + ", speed = " + ", speed = "
// + task.getConvertSpeed() + task.getConvertSpeed()
// + "current_p = " + "current_p = "
// + task.getCurrentProgress()); + task.getCurrentProgress());
getBinding().setProgress(task.getPercent()); getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
//Log.d(TAG, "sub_len = " + task.getEntity().getSubEntities().size()); //Log.d(TAG, "sub_len = " + task.getEntity().getSubEntities().size());
@ -175,26 +177,25 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask, @DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
DownloadEntity subEntity) { DownloadEntity subEntity) {
//ALog.d(TAG, "sub_percent = " + subEntity.getPercent()); //Log.e(TAG, "gHash = "
Log.e(TAG, "gHash = " // + groupTask.getEntity().getSubEntities().get(0).hashCode()
+ groupTask.getEntity().getSubEntities().get(0).hashCode() // + "; subHash = "
+ "; subHash = " // + groupTask.getTaskEntity().getSubTaskEntities().get(0).getEntity().hashCode() +
+ groupTask.getTaskEntity().getSubTaskEntities().get(0).getEntity().hashCode() + // "; subHash = " + subEntity.hashCode());
"; subHash = " + subEntity.hashCode()); //int percent = subEntity.getPercent();
int percent = subEntity.getPercent(); ////如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s
//如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s //String convertSpeed = subEntity.getConvertSpeed();
String convertSpeed = subEntity.getConvertSpeed(); ////当前下载完成的进度,长度bytes
//当前下载完成的进度,长度bytes //long completedSize = subEntity.getCurrentProgress();
long completedSize = subEntity.getCurrentProgress(); //Log.d(TAG, "subTask名字:"
Log.d(TAG, "subTask名字:" // + subEntity.getFileName()
+ subEntity.getFileName() // + ", "
+ ", " // + " speed:"
+ " speed:" // + convertSpeed
+ convertSpeed // + ",percent: "
+ ",percent: " // + percent
+ percent // + "%, completedSize:"
+ "%, completedSize:" // + completedSize);
+ completedSize);
} }
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask, @DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,

@ -35,7 +35,7 @@ import java.util.WeakHashMap;
* Created by Aria.Lao on 2017/7/17. * Created by Aria.Lao on 2017/7/17.
*/ */
public class SubStateLinearLayout extends LinearLayout implements View.OnClickListener { public class SubStateLinearLayout extends LinearLayout implements View.OnClickListener {
private final String TAG = "SubStateLinearLayout";
interface OnShowCallback { interface OnShowCallback {
void onShow(boolean visibility); void onShow(boolean visibility);
} }
@ -106,7 +106,6 @@ public class SubStateLinearLayout extends LinearLayout implements View.OnClickLi
if (position != -1) { if (position != -1) {
TextView child = ((TextView) getChildAt(position)); TextView child = ((TextView) getChildAt(position));
int p = getPercent(entity); int p = getPercent(entity);
Log.d("TAG", "p = " + p);
child.setText(entity.getFileName() + ": " + p + "%" + " | " + entity.getConvertSpeed()); child.setText(entity.getFileName() + ": " + p + "%" + " | " + entity.getConvertSpeed());
child.invalidate(); child.invalidate();
} }

@ -60,7 +60,7 @@
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>--> <!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>--> <!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item> <item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item> <!--<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>-->
</string-array> </string-array>
<string-array name="group_urls_1"> <string-array name="group_urls_1">
@ -87,7 +87,7 @@
<string-array name="group_names"> <string-array name="group_names">
<!--<item>王者荣耀.apk</item>--> <!--<item>王者荣耀.apk</item>-->
<item>战斗吧剑灵.apk</item> <item>战斗吧剑灵.apk</item>
<item>天魔幻想.apk</item> <!--<item>天魔幻想.apk</item>-->
</string-array> </string-array>
<string-array name="group_names_1"> <string-array name="group_names_1">

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

Loading…
Cancel
Save