修复异步是timer为null的问题

pull/330/head
laoyuyu 6 years ago
parent 1d116f71b7
commit 99f875c4c3
  1. 12
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  3. 47
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  5. 6
      app/src/main/AndroidManifest.xml
  6. 2
      app/src/main/assets/aria_config.xml
  7. 8
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  8. 4
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  9. 2
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  10. 6
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java

@ -26,7 +26,6 @@ import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadEntity;
@ -71,7 +70,6 @@ import org.xml.sax.SAXException;
* activity 和其DialogFragment的映射表
*/
private Map<String, List<String>> mSubClass = new ConcurrentHashMap<>();
private List<String> mActivityCount = new ArrayList<>();
public static Context APP;
private List<ICmd> mCommands = new ArrayList<>();
private Configuration.DownloadConfig mDConfig;
@ -470,9 +468,6 @@ import org.xml.sax.SAXException;
private class LifeCallback implements Application.ActivityLifecycleCallbacks {
@Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
mActivityCount.add(
String.format("%s_%s", activity.getClass().getName(), activity.hashCode()));
ALog.w(TAG, "size = " + mActivityCount.size());
}
@Override public void onActivityStarted(Activity activity) {
@ -497,13 +492,6 @@ import org.xml.sax.SAXException;
@Override public void onActivityDestroyed(Activity activity) {
removeReceiver(activity);
mActivityCount.remove(
String.format("%s_%s", activity.getClass().getName(), activity.hashCode()));
ALog.w(TAG, "size = " + mActivityCount.size());
if (mActivityCount.size() == 0) {
ALog.e(TAG, "gggg");
//Toast.makeText(activity, "destroy", Toast.LENGTH_SHORT).show();
}
}
}
}

@ -17,6 +17,7 @@
package com.arialyy.aria.core.command.normal;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
@ -82,14 +83,14 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|| task.getState() == IEntity.STATE_COMPLETE) {
resumeTask();
} else {
sendWaitState();
sendWaitState(task);
}
}
} else {
//任务没执行并且执行队列中没有该任务,才认为任务没有运行中
if (!task.isRunning() && !mQueue.taskIsRunning(task.getKey())) {
resumeTask();
}else {
} else {
ALog.w(TAG, String.format("任务【%s】已经在运行", task.getTaskName()));
}
}
@ -152,7 +153,8 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
AbsTask task = getTask(te.getEntity());
if (task != null) continue;
if (te instanceof DownloadTaskEntity) {
if (te.getRequestType() == AbsTaskEntity.D_FTP || te.getRequestType() == AbsTaskEntity.U_FTP) {
if (te.getRequestType() == AbsTaskEntity.D_FTP
|| te.getRequestType() == AbsTaskEntity.U_FTP) {
te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
}
mQueue = DownloadTaskQueue.getInstance();

@ -117,7 +117,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
return;
}
mConstance.resetState();
checkTask();
checkRecord();
mConstance.TASK_RECORD = mRecord;
if (mListener instanceof IDownloadListener) {
((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
@ -183,12 +183,14 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
protected void closeTimer() {
synchronized (AbsFileer.class) {
if (mTimer != null) {
mTimer.purge();
mTimer.cancel();
mTimer = null;
}
}
}
/**
* 设置定时器更新间隔
@ -261,14 +263,13 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
/**
* 检查任务检查线程数
* 新任务条件
* 1文件不存在
* 2任务记录文件缺失或不匹配
* 3数据库记录不存在
* 4不支持断点则是新任务
* 检查记录
* 对于分块任务
* 子分块不存在或被删除子线程将重新下载
* 对于普通任务
* 预下载文件不存在则任务任务呗删除
*/
private void checkTask() {
private void checkRecord() {
mConfigFile = new File(CommonUtil.getFileConfigPath(false, mEntity.getFileName()));
if (mConfigFile.exists()) {
convertDb();
@ -279,12 +280,32 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} else {
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
initRecord(true);
} else if (mRecord.isBlock) {
for (ThreadRecord tr : mRecord.threadRecords) {
File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId));
if (!temp.exists()) {
ALog.w(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false;
tr.startLocation = -1;
mStartThreadNum++;
} else {
if (tr.isComplete) {
mCompleteThreadNum++;
} else {
mStartThreadNum++;
}
}
mTotalThreadNum = mRecord.threadRecords.size();
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;
}
//else if (mTempFile.length() == 0) {
// mRecord.deleteData();
// initRecord(true);
//}
else {
for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) {
mCompleteThreadNum++;

@ -321,6 +321,7 @@ public abstract class AbsGroupUtil implements IUtil {
}
void closeTimer() {
synchronized (LOCK) {
isRunning = false;
if (mTimer != null) {
mTimer.purge();
@ -328,6 +329,7 @@ public abstract class AbsGroupUtil implements IUtil {
mTimer = null;
}
}
}
/**
* 开始进度流程

@ -15,11 +15,11 @@
android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"-->
<!--android:name="com.arialyy.simple.test.AnyRunActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<activity
android:name="com.arialyy.simple.test.AnyRunActivity"
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

@ -34,7 +34,7 @@
<threadNum value="3"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/>
<maxTaskNum value="1"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="2"/>

@ -46,13 +46,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private static final String DOWNLOAD_URL =
//"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://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//"https://static.donguo.me//video/ip/course/pfys_1.mp4";
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
//"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@ -220,8 +220,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
startD();
break;
case R.id.stop:
//Aria.download(this).load(DOWNLOAD_URL).stop();
startActivity(new Intent(this, SingleTaskActivity.class));
Aria.download(this).load(DOWNLOAD_URL).stop();
//startActivity(new Intent(this, SingleTaskActivity.class));
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break;
case R.id.cancel:

@ -92,8 +92,8 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this).loadGroup(mUrls).stop();
break;
case R.id.cancel:
//Aria.download(this).load(mUrls).cancel(true);
Aria.download(this).removeAllTask(true);
Aria.download(this).loadGroup(mUrls).cancel(true);
//Aria.download(this).removeAllTask(true);
//mUrls = getModule(GroupModule.class).getUrls1();
//Aria.download(this)
// .load(mUrls)

@ -117,7 +117,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
}
@DownloadGroup.onWait void groupTaskWait(DownloadGroupTask task) {
ALog.d(TAG, String.format("group【%s】wait", task.getTaskName()));
ALog.d(TAG, String.format("group【%s】wait---", task.getTaskName()));
mAdapter.updateState(task.getEntity());
}

@ -29,6 +29,7 @@ import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
@ -119,6 +120,11 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
mAdapter.updateBtState(task.getKey(), false);
}
@DownloadGroup.onWait void groupTaskWait(DownloadGroupTask task) {
ALog.d(TAG, String.format("group【%s】wait---", task.getTaskName()));
mAdapter.updateBtState(task.getKey(), true);
}
@DownloadGroup.onTaskStop void groupTaskStop(DownloadGroupTask task) {
mAdapter.updateBtState(task.getKey(), true);
Log.d(TAG, String.format("group【%s】stop", task.getTaskName()));

Loading…
Cancel
Save