修复任务组崩溃问题
This commit is contained in:
@@ -100,7 +100,7 @@ class ConfigHelper extends DefaultHandler {
|
||||
}
|
||||
} else if (isAppConfig) {
|
||||
String value = attributes.getValue("value");
|
||||
switch (value) {
|
||||
switch (qName) {
|
||||
case "useAriaCrashHandler":
|
||||
loadUseAriaCrashHandler(value);
|
||||
break;
|
||||
|
||||
@@ -60,7 +60,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
List<AbsTaskEntity> tempList = new ArrayList<>();
|
||||
if (type == 1) {
|
||||
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
|
||||
"DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state!=?", "1");
|
||||
"DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state!=?", "false", "1");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (DTEWrapper w : wrappers) {
|
||||
tempList.add(w.taskEntity);
|
||||
@@ -75,8 +75,8 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
}
|
||||
}
|
||||
} else if (type == 3) {
|
||||
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class,
|
||||
"UploadTaskEntity.state!=?", "1");
|
||||
List<UTEWrapper> wrappers =
|
||||
DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.state!=?", "1");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (UTEWrapper w : wrappers) {
|
||||
tempList.add(w.taskEntity);
|
||||
|
||||
@@ -119,7 +119,7 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
List<AbsTaskEntity> waitList = new ArrayList<>();
|
||||
if (type == 1) {
|
||||
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
|
||||
"DownloadTaskEntity.isGroupTask=false and DownloadTaskEntity.state=?", "3");
|
||||
"DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state=?", "false", "3");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (DTEWrapper w : wrappers) {
|
||||
waitList.add(w.taskEntity);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.manager.SubTaskManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
@@ -155,9 +155,9 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
|
||||
* 更新所有改动的子任务文件名
|
||||
*/
|
||||
private void updateSingleSubFileName() {
|
||||
List<DownloadEntity> entities = mEntity.getSubEntities();
|
||||
List<DownloadTaskEntity> entities = mTaskEntity.getSubTaskEntities();
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : entities) {
|
||||
for (DownloadTaskEntity entity : entities) {
|
||||
if (i < mSubNameTemp.size()) {
|
||||
String newName = mSubNameTemp.get(i);
|
||||
updateSingleSubFileName(entity, newName);
|
||||
@@ -215,7 +215,8 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
|
||||
/**
|
||||
* 更新单个子任务文件名
|
||||
*/
|
||||
private void updateSingleSubFileName(DownloadEntity entity, String newName) {
|
||||
private void updateSingleSubFileName(DownloadTaskEntity taskEntity, String newName) {
|
||||
DownloadEntity entity = taskEntity.getEntity();
|
||||
if (!newName.equals(entity.getFileName())) {
|
||||
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
|
||||
String newPath = mEntity.getDirPath() + "/" + newName;
|
||||
@@ -224,8 +225,8 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
|
||||
oldFile.renameTo(new File(newPath));
|
||||
}
|
||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newName);
|
||||
// TODO: 2018/4/11 需要校验数据库级联操作是否生效
|
||||
entity.setDownloadPath(newPath);
|
||||
taskEntity.key = newPath;
|
||||
entity.setFileName(newName);
|
||||
entity.update();
|
||||
}
|
||||
|
||||
@@ -308,10 +308,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
}
|
||||
|
||||
private void clearState(){
|
||||
mExeMap.clear();
|
||||
mDownloaderMap.clear();
|
||||
mFailMap.clear();
|
||||
mTasksMap.clear();
|
||||
}
|
||||
|
||||
private void closeTimer(boolean isRunning) {
|
||||
|
||||
@@ -78,20 +78,17 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
return;
|
||||
}
|
||||
Set<String> keys = mExeMap.keySet();
|
||||
int i = 0;
|
||||
for (String key : keys) {
|
||||
DownloadTaskEntity taskEntity = mExeMap.get(key);
|
||||
if (taskEntity != null) {
|
||||
if (taskEntity.getState() != IEntity.STATE_FAIL
|
||||
&& taskEntity.getState() != IEntity.STATE_WAIT) {
|
||||
createChildDownload(taskEntity);
|
||||
i++;
|
||||
} else {
|
||||
mInfoPool.execute(createFileInfoThread(taskEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i != 0 && i == mExeMap.size()) startRunningFlow();
|
||||
if (mCurrentLocation == mTotalLen) {
|
||||
mListener.onComplete();
|
||||
}
|
||||
@@ -115,6 +112,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
}
|
||||
createChildDownload(te);
|
||||
}
|
||||
mInitCompleteNum ++;
|
||||
|
||||
if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) {
|
||||
startRunningFlow();
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.arialyy.aria.orm;
|
||||
import android.content.ContentValues;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
@@ -90,7 +91,6 @@ class DelegateUpdate extends AbsDelegate {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//print(MODIFY_DATA, sql.toString());
|
||||
if (values.size() > 0) {
|
||||
db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?",
|
||||
new String[] { String.valueOf(dbEntity.rowID) });
|
||||
|
||||
@@ -35,7 +35,8 @@ public class AriaCrashHandler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
ALog.d(thread.getName(), ex.getLocalizedMessage());
|
||||
ex.printStackTrace();
|
||||
//ALog.d(thread.getName(), ex.getLocalizedMessage());
|
||||
handleException(thread.getName(), ex);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<!--android:name=".MainActivity"-->
|
||||
<!--android:name=".test.TestGroupActivity"-->
|
||||
<!--android:name=".test.TestActivity"-->
|
||||
<!--android:name=".test.AnyRunActivity"-->
|
||||
<activity
|
||||
android:name=".test.AnyRunActivity"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
||||
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
||||
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||
"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||
//"https://static.donguo.me//video/ip/course/pfys_1.mp4";
|
||||
@Bind(R.id.start) Button mStart;
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@@ -107,67 +107,87 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
@Download.onWait void onWait(DownloadTask task) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onPre protected void onPre(DownloadTask task) {
|
||||
setBtState(false);
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning protected void running(DownloadTask task) {
|
||||
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
getBinding().setProgress(0);
|
||||
} else {
|
||||
getBinding().setProgress(task.getPercent());
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
Log.d(TAG, task.getKey());
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
getBinding().setProgress(0);
|
||||
} else {
|
||||
getBinding().setProgress(task.getPercent());
|
||||
}
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
}
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
mStart.setText("暂停");
|
||||
setBtState(false);
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mStart.setText("暂停");
|
||||
setBtState(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
mStart.setText("恢复");
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mStart.setText("恢复");
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
getBinding().setProgress(0);
|
||||
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("开始");
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
Log.d(TAG, "cancel");
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
getBinding().setProgress(0);
|
||||
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("开始");
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
Log.d(TAG, "cancel");
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||
setBtState(true);
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||
setBtState(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
getBinding().setProgress(100);
|
||||
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("重新开始?");
|
||||
mCancel.setEnabled(false);
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
getBinding().setProgress(100);
|
||||
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("重新开始?");
|
||||
mCancel.setEnabled(false);
|
||||
setBtState(true);
|
||||
getBinding().setSpeed("");
|
||||
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.simple.download.group;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
@@ -84,7 +85,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
|
||||
.setGroupAlias("任务组测试")
|
||||
.setSubFileName(getModule(GroupModule.class).getSubName())
|
||||
.setFileSize(32895492)
|
||||
//.setFileSize(32895492)
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
@@ -126,10 +127,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) {
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
L.d(TAG, "group task start");
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
|
||||
Log.d(TAG, "group running");
|
||||
getBinding().setProgress(task.getPercent());
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
mChildList.updateChildProgress(task.getEntity().getSubEntities());
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_urls_1">
|
||||
<item>http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk</item>
|
||||
<!--<item>http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk</item>-->
|
||||
<!--<item>https://atom-installer.github.com/v1.13.0/AtomSetup.exe</item>-->
|
||||
<item>http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk</item>
|
||||
</string-array>
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
<string-array name="group_names">
|
||||
<!--<item>王者荣耀.apk</item>-->
|
||||
<item>战斗吧剑灵.apk</item>
|
||||
<!--<item>战斗吧剑灵.apk</item>-->
|
||||
<item>天魔幻想.apk</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
@@ -154,11 +154,8 @@ class Configuration {
|
||||
Properties properties = CommonUtil.loadConfig(file);
|
||||
for (Field field : fields) {
|
||||
int m = field.getModifiers();
|
||||
if (field.isSynthetic()
|
||||
|| Modifier.isFinal(m)
|
||||
|| Modifier.isStatic(m)
|
||||
|| field.getName().equals("shadow$_klass_")
|
||||
|| field.getName().equals("shadow$_monitor_")) {
|
||||
if (field.isSynthetic() || Modifier.isFinal(m) || Modifier.isStatic(m) || field.getName()
|
||||
.equals("shadow$_klass_") || field.getName().equals("shadow$_monitor_")) {
|
||||
continue;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
@@ -447,7 +444,7 @@ class Configuration {
|
||||
* 是否使用{@link AriaCrashHandler}来捕获异常
|
||||
* {@code true} 使用;{@code false} 不使用
|
||||
*/
|
||||
Boolean useAriaCrashHandler;
|
||||
boolean useAriaCrashHandler;
|
||||
|
||||
/**
|
||||
* 设置Aria的日志级别
|
||||
@@ -480,11 +477,11 @@ class Configuration {
|
||||
return logLevel;
|
||||
}
|
||||
|
||||
public Boolean getUseAriaCrashHandler() {
|
||||
public boolean getUseAriaCrashHandler() {
|
||||
return useAriaCrashHandler;
|
||||
}
|
||||
|
||||
public AppConfig setUseAriaCrashHandler(Boolean useAriaCrashHandler) {
|
||||
public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) {
|
||||
this.useAriaCrashHandler = useAriaCrashHandler;
|
||||
saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler));
|
||||
if (useAriaCrashHandler) {
|
||||
|
||||
Reference in New Issue
Block a user