fix bug https://github.com/AriaLyy/Aria/issues/309 修复刷新url后,文件无法删除的 bug

v3.6.6
laoyuyu 6 years ago
parent 09e49a28de
commit 9fc5f47a6b
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  3. 23
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  4. 4
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  5. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  6. 72
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java
  9. 55
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  10. 2
      DEV_LOG.md
  11. 3
      app/src/main/AndroidManifest.xml
  12. 22
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  13. 5
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  14. 2
      build.gradle

@ -130,7 +130,7 @@ import org.xml.sax.SAXException;
DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class,
DownloadTaskEntity.class, UploadTaskEntity.class, DownloadGroupTaskEntity.class
};
String sql = "UPDATE %s SET state=2 WHERE state=4";
String sql = "UPDATE %s SET state=2 WHERE state in (3,4,5,6)";
for (Class clazz : clazzs) {
String temp = String.format(sql, clazz.getSimpleName());
DbEntity.exeSql(temp);

@ -23,6 +23,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
@ -83,7 +84,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
*/
void sendWaitState() {
if (tempTask != null) {
tempTask.getOutHandler().obtainMessage(ISchedulers.WAIT, tempTask).sendToTarget();
sendWaitState(tempTask);
}
}
@ -92,6 +93,9 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
*/
void sendWaitState(AbsTask task) {
if (task != null) {
task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT);
task.getTaskEntity().setState(IEntity.STATE_WAIT);
task.getTaskEntity().update();
task.getOutHandler().obtainMessage(ISchedulers.WAIT, task).sendToTarget();
}
}

@ -38,9 +38,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Created by lyy on 2016/8/22.
* 开始命令
* 队列模型{@link QueueMod#NOW}{@link QueueMod#WAIT}
* Created by lyy on 2016/8/22. 开始命令 队列模型{@link QueueMod#NOW}{@link QueueMod#WAIT}
*/
class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
@ -70,13 +68,18 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
if (mod.equals(QueueMod.NOW.getTag())) {
startTask();
} else if (mod.equals(QueueMod.WAIT.getTag())) {
if (mQueue.getCurrentExePoolNum() < maxTaskNum
|| task.getState() == IEntity.STATE_STOP
|| task.getState() == IEntity.STATE_FAIL
|| task.getState() == IEntity.STATE_OTHER
|| task.getState() == IEntity.STATE_POST_PRE
|| task.getState() == IEntity.STATE_COMPLETE) {
resumeTask();
int state = task.getState();
if (mQueue.getCurrentExePoolNum() < maxTaskNum){
if (state == IEntity.STATE_STOP
|| task.getState() == IEntity.STATE_FAIL
|| task.getState() == IEntity.STATE_OTHER
|| task.getState() == IEntity.STATE_PRE
|| task.getState() == IEntity.STATE_POST_PRE
|| task.getState() == IEntity.STATE_COMPLETE) {
resumeTask();
}else {
startTask();
}
} else {
sendWaitState(task);
}

@ -45,7 +45,7 @@ public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEnti
}
@Override public void supportBreakpoint(boolean support) {
if (!support){
if (!support) {
sendInState2Target(ISchedulers.NO_SUPPORT_BREAK_POINT);
}
}
@ -62,7 +62,7 @@ public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEnti
if (record != null) {
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), mEntity);
} else {
mEntity.deleteData();
CommonUtil.delTaskRecord(mEntity.getDownloadPath(), 1, mTaskEntity.isRemoveFile());
}
}
return;

@ -55,6 +55,9 @@ public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
*/
void stop(int type);
/**
* 删除任务
*/
void cancel();
/**

@ -29,14 +29,13 @@ import java.util.Map;
import java.util.Set;
/**
* Created by lyy on 2017/2/23.
* 任务队列
* Created by lyy on 2017/2/23. 任务队列
*/
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity>
implements ITaskQueue<TASK, TASK_ENTITY> {
protected final int TYPE_D_QUEUE = 1;
protected final int TYPE_DG_QUEUE = 2;
protected final int TYPE_U_QUEUE = 3;
final int TYPE_D_QUEUE = 1;
final int TYPE_DG_QUEUE = 2;
final int TYPE_U_QUEUE = 3;
private final String TAG = "AbsTaskQueue";
BaseCachePool<TASK> mCachePool;
@ -63,9 +62,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
}
/**
* 恢复任务
* 如果执行队列任务未满则直接启动任务
* 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
* 恢复任务 如果执行队列任务未满则直接启动任务 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
*
* @param task 需要恢复的任务
*/
@ -197,14 +194,34 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
}
@Override public void stopTask(TASK task) {
if (!task.isRunning()) {
ALog.w(TAG, String.format("停止任务【%s】失败,原因:已停止", task.getTaskName()));
int state = task.getState();
boolean canStop = false;
switch (state) {
case IEntity.STATE_WAIT:
mCachePool.removeTask(task);
canStop = true;
break;
case IEntity.STATE_POST_PRE:
case IEntity.STATE_PRE:
case IEntity.STATE_RUNNING:
mExecutePool.removeTask(task);
canStop = true;
break;
case IEntity.STATE_STOP:
case IEntity.STATE_OTHER:
case IEntity.STATE_FAIL:
ALog.w(TAG, String.format("停止任务【%s】失败,原因:已停止", task.getTaskName()));
break;
case IEntity.STATE_CANCEL:
ALog.w(TAG, String.format("停止任务【%s】失败,原因:任务已删除", task.getTaskName()));
break;
case IEntity.STATE_COMPLETE:
ALog.w(TAG, String.format("停止任务【%s】失败,原因:已完成", task.getTaskName()));
break;
}
if (mExecutePool.removeTask(task)) {
task.stop();
} else {
if (canStop) {
task.stop();
ALog.w(TAG, String.format("删除任务【%s】失败,原因:执行队列中没有该任务", task.getTaskName()));
}
}
@ -226,11 +243,28 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
ALog.e(TAG, "任务重试失败,原因:task 为null");
return;
}
if (!task.isRunning()) {
task.start();
} else {
task.stop();
ALog.e(TAG, String.format("任务【%s】重试失败,原因:任务没有完全停止", task.getTaskName()));
int state = task.getState();
switch (state) {
case IEntity.STATE_POST_PRE:
case IEntity.STATE_PRE:
case IEntity.STATE_RUNNING:
ALog.w(TAG, String.format("任务【%s】没有停止,即将重新下载", task.getTaskName()));
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
task.start();
break;
case IEntity.STATE_WAIT:
case IEntity.STATE_STOP:
case IEntity.STATE_OTHER:
case IEntity.STATE_FAIL:
task.start();
break;
case IEntity.STATE_CANCEL:
ALog.e(TAG, String.format("任务【%s】重试失败,原因:任务没已删除", task.getTaskName()));
break;
case IEntity.STATE_COMPLETE:
ALog.e(TAG, String.format("任务【%s】重试失败,原因:已完成", task.getTaskName()));
break;
}
}

@ -261,9 +261,9 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
*/
private void handleFailTask(final TASK task) {
if (!task.needRetry || task.isStop() || task.isCancel()) {
callback(FAIL, task);
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
callback(FAIL, task);
return;
}
long interval = 2000;
@ -283,10 +283,10 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
final int reTryNum = num;
if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry)
|| task.getTaskEntity().getEntity().getFailNum() > reTryNum) {
callback(FAIL, task);
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
TEManager.getInstance().removeTEntity(task.getKey());
callback(FAIL, task);
return;
}

@ -46,6 +46,8 @@ class BaseUListener extends BaseListener<UploadEntity, UploadTaskEntity, UploadT
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskEntity.getKey());
if (record != null) {
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), mEntity);
}else {
CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskEntity.isRemoveFile());
}
}
//else if (mEntity instanceof AbsGroupEntity) {

@ -71,8 +71,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by lyy on 2016/1/22.
* 通用工具
* Created by lyy on 2016/1/22. 通用工具
*/
public class CommonUtil {
private static final String TAG = "CommonUtil";
@ -483,8 +482,7 @@ public class CommonUtil {
/**
* 删除任务组记录
*
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经删除完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经删除完成的文件 {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delGroupTaskRecord(boolean removeFile, DownloadGroupEntity groupEntity) {
if (groupEntity == null) {
@ -533,8 +531,7 @@ public class CommonUtil {
/**
* 删除任务记录
*
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经完成的文件 {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delTaskRecord(TaskRecord record, boolean removeFile, AbsNormalEntity dEntity) {
if (dEntity == null) return;
@ -573,10 +570,10 @@ public class CommonUtil {
* 删除任务记录默认删除文件
*
* @param filePath 文件路径
* @param type {@code 1}下载任务的记录{@code 2} 上传任务的记录
* {@code false}如果任务已经完成只删除任务数据库记录
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经删除完成的文件 {@code false}如果任务已经完成只删除任务数据库记录
* @param type {@code 1}下载任务的记录{@code 2} 上传任务的记录 {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delTaskRecord(String filePath, int type) {
public static void delTaskRecord(String filePath, int type, boolean removeFile) {
if (TextUtils.isEmpty(filePath)) {
throw new NullPointerException("删除记录失败,文件路径为空");
}
@ -584,35 +581,45 @@ public class CommonUtil {
throw new IllegalArgumentException("任务记录类型错误");
}
TaskRecord record = DbEntity.findFirst(TaskRecord.class, "filePath=?", filePath);
File file = new File(filePath);
if (record == null) {
ALog.w(TAG, "删除记录失败,记录为空");
return;
}
File file = new File(filePath);
// 删除分块文件
if (record.isBlock) {
for (int i = 0, len = record.threadNum; i < len; i++) {
File partFile = new File(String.format(AbsFileer.SUB_PATH, record.filePath, i));
if (partFile.exists()) {
partFile.delete();
} else {
// 删除分块文件
if (record.isBlock) {
for (int i = 0, len = record.threadNum; i < len; i++) {
File partFile = new File(String.format(AbsFileer.SUB_PATH, record.filePath, i));
if (partFile.exists()) {
partFile.delete();
}
}
}
record.deleteData();
}
if (file.exists()) {
if (file.exists() && removeFile) {
file.delete();
}
record.deleteData();
//下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除
if (type == 1) {
DbEntity.deleteData(DownloadTaskEntity.class, "key=?", filePath);
DbEntity.deleteData(DownloadEntity.class, "downloadPath=?", filePath);
}else {
} else {
DbEntity.deleteData(UploadTaskEntity.class, "key=?", filePath);
DbEntity.deleteData(UploadEntity.class, "filePath=?", filePath);
}
}
/**
* 删除任务记录默认删除文件
*
* @param filePath 文件路径
* @param type {@code 1}下载任务的记录{@code 2} 上传任务的记录 {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delTaskRecord(String filePath, int type) {
delTaskRecord(filePath, type, false);
}
/**
* 获取CPU核心数
*/
@ -983,9 +990,7 @@ public class CommonUtil {
}
/**
* 创建文件
* 当文件不存在的时候就创建一个文件
* 如果文件存在先删除原文件然后重新创建一个新文件
* 创建文件 当文件不存在的时候就创建一个文件 如果文件存在先删除原文件然后重新创建一个新文件
*/
public static void createFile(String path) {
if (TextUtils.isEmpty(path)) {

@ -17,6 +17,8 @@
- 修复分卡下载失败的问题 https://github.com/AriaLyy/Aria/issues/326
- 初始化Aria时会将所有数据库状态为下载中的任务改为已停止,防止应用被kill后,任务状态错误
- 初始化时自动判断文件是否被删除,文件被删除的任务将自动重置默认值
- 修复刷新url后,文件无法删除的 bug
- fix bug https://github.com/AriaLyy/Aria/issues/309
+ v_3.5.1
- 优化`taskExists`方法
- 添加`post`参数请求支持

@ -18,8 +18,9 @@
<!--android:name=".test.TestFTPDirActivity"-->
<!--android:name=".test.TestFTPActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".MainActivity"-->
<activity
android:name=".download.SingleTaskActivity"
android:name=".download.SingleTaskActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

@ -51,17 +51,17 @@ 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.apks";
//"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.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";
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
//"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";
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@ -183,6 +183,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
if (task.getKey().equals(DOWNLOAD_URL)) {
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
setBtState(true);
Aria.download(this)
.load(DOWNLOAD_URL)
.updateUrl("http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip")
.start();
//ALog.d(TAG, ALog.getExceptionString(e));
}
}
@ -255,7 +259,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//Aria.get(this).setLogLevel(ALog.LOG_CLOSE);
//Aria.download(this).load("aaaa.apk");
//String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg11.ota";
String path = "/sdcard/ggsg11.ota";
String path = "/sdcard/ggsg11.mp4";
//File file = new File(path);
//if (file.exists()){
// file.delete();

@ -205,9 +205,10 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
//删除按钮事件
holder.cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
mData.remove(entity);
// mData.remove(entity);
notifyDataSetChanged();
cancel(entity);
// cancel(entity);
stop(entity);
}
});
//if (holder instanceof GroupHolder){

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

Loading…
Cancel
Save