修复任务组崩溃问题

pull/330/head
laoyuyu 7 years ago
parent a7ca196258
commit c6d548ec48
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  4. 1
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  5. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
  9. 3
      Aria/src/main/java/com/arialyy/aria/util/AriaCrashHandler.java
  10. 4
      app/src/main/AndroidManifest.xml
  11. 22
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 5
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  13. 4
      app/src/main/res/values/strings.xml
  14. 13
      aria/src/main/java/com/arialyy/aria/core/Configuration.java

@ -100,7 +100,7 @@ class ConfigHelper extends DefaultHandler {
} }
} else if (isAppConfig) { } else if (isAppConfig) {
String value = attributes.getValue("value"); String value = attributes.getValue("value");
switch (value) { switch (qName) {
case "useAriaCrashHandler": case "useAriaCrashHandler":
loadUseAriaCrashHandler(value); loadUseAriaCrashHandler(value);
break; break;

@ -60,7 +60,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
List<AbsTaskEntity> tempList = new ArrayList<>(); List<AbsTaskEntity> tempList = new ArrayList<>();
if (type == 1) { if (type == 1) {
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class, 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()) { if (wrappers != null && !wrappers.isEmpty()) {
for (DTEWrapper w : wrappers) { for (DTEWrapper w : wrappers) {
tempList.add(w.taskEntity); tempList.add(w.taskEntity);
@ -75,8 +75,8 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
} }
} }
} else if (type == 3) { } else if (type == 3) {
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class, List<UTEWrapper> wrappers =
"UploadTaskEntity.state!=?", "1"); DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.state!=?", "1");
if (wrappers != null && !wrappers.isEmpty()) { if (wrappers != null && !wrappers.isEmpty()) {
for (UTEWrapper w : wrappers) { for (UTEWrapper w : wrappers) {
tempList.add(w.taskEntity); tempList.add(w.taskEntity);

@ -119,7 +119,7 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
List<AbsTaskEntity> waitList = new ArrayList<>(); List<AbsTaskEntity> waitList = new ArrayList<>();
if (type == 1) { if (type == 1) {
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class, 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()) { if (wrappers != null && !wrappers.isEmpty()) {
for (DTEWrapper w : wrappers) { for (DTEWrapper w : wrappers) {
waitList.add(w.taskEntity); waitList.add(w.taskEntity);

@ -16,6 +16,7 @@
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;

@ -155,9 +155,9 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
* 更新所有改动的子任务文件名 * 更新所有改动的子任务文件名
*/ */
private void updateSingleSubFileName() { private void updateSingleSubFileName() {
List<DownloadEntity> entities = mEntity.getSubEntities(); List<DownloadTaskEntity> entities = mTaskEntity.getSubTaskEntities();
int i = 0; int i = 0;
for (DownloadEntity entity : entities) { for (DownloadTaskEntity entity : entities) {
if (i < mSubNameTemp.size()) { if (i < mSubNameTemp.size()) {
String newName = mSubNameTemp.get(i); String newName = mSubNameTemp.get(i);
updateSingleSubFileName(entity, newName); 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())) { if (!newName.equals(entity.getFileName())) {
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
String newPath = mEntity.getDirPath() + "/" + newName; String newPath = mEntity.getDirPath() + "/" + newName;
@ -224,8 +225,8 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
oldFile.renameTo(new File(newPath)); oldFile.renameTo(new File(newPath));
} }
CommonUtil.renameDownloadConfig(oldFile.getName(), newName); CommonUtil.renameDownloadConfig(oldFile.getName(), newName);
// TODO: 2018/4/11 需要校验数据库级联操作是否生效
entity.setDownloadPath(newPath); entity.setDownloadPath(newPath);
taskEntity.key = newPath;
entity.setFileName(newName); entity.setFileName(newName);
entity.update(); entity.update();
} }

@ -308,10 +308,8 @@ public abstract class AbsGroupUtil implements IUtil {
} }
private void clearState(){ private void clearState(){
mExeMap.clear();
mDownloaderMap.clear(); mDownloaderMap.clear();
mFailMap.clear(); mFailMap.clear();
mTasksMap.clear();
} }
private void closeTimer(boolean isRunning) { private void closeTimer(boolean isRunning) {

@ -78,20 +78,17 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
return; return;
} }
Set<String> keys = mExeMap.keySet(); Set<String> keys = mExeMap.keySet();
int i = 0;
for (String key : keys) { for (String key : keys) {
DownloadTaskEntity taskEntity = mExeMap.get(key); DownloadTaskEntity taskEntity = mExeMap.get(key);
if (taskEntity != null) { if (taskEntity != null) {
if (taskEntity.getState() != IEntity.STATE_FAIL if (taskEntity.getState() != IEntity.STATE_FAIL
&& taskEntity.getState() != IEntity.STATE_WAIT) { && taskEntity.getState() != IEntity.STATE_WAIT) {
createChildDownload(taskEntity); createChildDownload(taskEntity);
i++;
} else { } else {
mInfoPool.execute(createFileInfoThread(taskEntity)); mInfoPool.execute(createFileInfoThread(taskEntity));
} }
} }
} }
if (i != 0 && i == mExeMap.size()) startRunningFlow();
if (mCurrentLocation == mTotalLen) { if (mCurrentLocation == mTotalLen) {
mListener.onComplete(); mListener.onComplete();
} }
@ -115,6 +112,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
} }
createChildDownload(te); createChildDownload(te);
} }
mInitCompleteNum ++;
if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) {
startRunningFlow(); startRunningFlow();

@ -18,6 +18,7 @@ package com.arialyy.aria.orm;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.orm.annotation.Primary; import com.arialyy.aria.orm.annotation.Primary;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -90,7 +91,6 @@ class DelegateUpdate extends AbsDelegate {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
//print(MODIFY_DATA, sql.toString());
if (values.size() > 0) { if (values.size() > 0) {
db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?", db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?",
new String[] { String.valueOf(dbEntity.rowID) }); new String[] { String.valueOf(dbEntity.rowID) });

@ -35,7 +35,8 @@ public class AriaCrashHandler implements Thread.UncaughtExceptionHandler {
@Override @Override
public void uncaughtException(Thread thread, Throwable ex) { 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); handleException(thread.getName(), ex);
try { try {
Thread.sleep(1000); Thread.sleep(1000);

@ -14,11 +14,11 @@
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".MainActivity"-->
<!--android:name=".test.TestGroupActivity"--> <!--android:name=".test.TestGroupActivity"-->
<!--android:name=".test.TestActivity"--> <!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<activity <activity
android:name=".test.AnyRunActivity" android:name=".MainActivity"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

@ -107,19 +107,26 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
@Download.onWait void onWait(DownloadTask task) { @Download.onWait void onWait(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
} }
}
@Download.onPre protected void onPre(DownloadTask task) { @Download.onPre protected void onPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false); setBtState(false);
} }
}
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
} }
}
@Download.onTaskRunning protected void running(DownloadTask task) { @Download.onTaskRunning protected void running(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
Log.d(TAG, task.getKey());
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
getBinding().setProgress(0); getBinding().setProgress(0);
@ -128,19 +135,25 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
} }
}
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mStart.setText("暂停"); mStart.setText("暂停");
setBtState(false); setBtState(false);
} }
}
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mStart.setText("恢复"); mStart.setText("恢复");
setBtState(true); setBtState(true);
getBinding().setSpeed(""); getBinding().setSpeed("");
} }
}
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
getBinding().setProgress(0); getBinding().setProgress(0);
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show(); Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
mStart.setText("开始"); mStart.setText("开始");
@ -148,13 +161,17 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
getBinding().setSpeed(""); getBinding().setSpeed("");
Log.d(TAG, "cancel"); Log.d(TAG, "cancel");
} }
}
@Download.onTaskFail void taskFail(DownloadTask task) { @Download.onTaskFail void taskFail(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show(); Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
setBtState(true); setBtState(true);
} }
}
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
getBinding().setProgress(100); getBinding().setProgress(100);
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
mStart.setText("重新开始?"); mStart.setText("重新开始?");
@ -165,10 +182,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
} }
}
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
} }
}
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_single; return R.layout.activity_single;

@ -17,6 +17,7 @@ package com.arialyy.simple.download.group;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log;
import android.view.View; import android.view.View;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.DownloadGroup; import com.arialyy.annotations.DownloadGroup;
@ -84,7 +85,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3") Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
.setGroupAlias("任务组测试") .setGroupAlias("任务组测试")
.setSubFileName(getModule(GroupModule.class).getSubName()) .setSubFileName(getModule(GroupModule.class).getSubName())
.setFileSize(32895492) //.setFileSize(32895492)
.start(); .start();
break; break;
case R.id.stop: case R.id.stop:
@ -126,10 +127,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) { @DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) {
getBinding().setFileSize(task.getConvertFileSize());
L.d(TAG, "group task start"); L.d(TAG, "group task start");
} }
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) { @DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
Log.d(TAG, "group running");
getBinding().setProgress(task.getPercent()); getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
mChildList.updateChildProgress(task.getEntity().getSubEntities()); mChildList.updateChildProgress(task.getEntity().getSubEntities());

@ -64,7 +64,7 @@
</string-array> </string-array>
<string-array name="group_urls_1"> <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>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> <item>http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk</item>
</string-array> </string-array>
@ -81,7 +81,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>

@ -154,11 +154,8 @@ class Configuration {
Properties properties = CommonUtil.loadConfig(file); Properties properties = CommonUtil.loadConfig(file);
for (Field field : fields) { for (Field field : fields) {
int m = field.getModifiers(); int m = field.getModifiers();
if (field.isSynthetic() if (field.isSynthetic() || Modifier.isFinal(m) || Modifier.isStatic(m) || field.getName()
|| Modifier.isFinal(m) .equals("shadow$_klass_") || field.getName().equals("shadow$_monitor_")) {
|| Modifier.isStatic(m)
|| field.getName().equals("shadow$_klass_")
|| field.getName().equals("shadow$_monitor_")) {
continue; continue;
} }
field.setAccessible(true); field.setAccessible(true);
@ -447,7 +444,7 @@ class Configuration {
* 是否使用{@link AriaCrashHandler}来捕获异常 * 是否使用{@link AriaCrashHandler}来捕获异常
* {@code true} 使用{@code false} 不使用 * {@code true} 使用{@code false} 不使用
*/ */
Boolean useAriaCrashHandler; boolean useAriaCrashHandler;
/** /**
* 设置Aria的日志级别 * 设置Aria的日志级别
@ -480,11 +477,11 @@ class Configuration {
return logLevel; return logLevel;
} }
public Boolean getUseAriaCrashHandler() { public boolean getUseAriaCrashHandler() {
return useAriaCrashHandler; return useAriaCrashHandler;
} }
public AppConfig setUseAriaCrashHandler(Boolean useAriaCrashHandler) { public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) {
this.useAriaCrashHandler = useAriaCrashHandler; this.useAriaCrashHandler = useAriaCrashHandler;
saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler)); saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler));
if (useAriaCrashHandler) { if (useAriaCrashHandler) {

Loading…
Cancel
Save