Skip to content
Permalink
Browse files

fix bug #543 (comment)

fix bug #542
fix bug #547
修复下载失败时,中断重试无效的问题
增加忽略权限检查的api,`ignoreCheckPermissions()`
  • Loading branch information
AriaLyy committed Dec 2, 2019
1 parent 91daecd commit 669aa6981c56f47fa38e402b095818f5c6c1ce9d
Showing with 294 additions and 241 deletions.
  1. +0 −10 Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. +2 −1 Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java
  3. +2 −2 Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java
  4. +8 −7 Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  5. +9 −1 Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java
  6. +8 −0 Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java
  7. +20 −9 Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java
  8. +2 −2 Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  9. +3 −2 Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  10. +4 −4 Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java
  11. +5 −5 Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java
  12. +3 −2 Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java
  13. +2 −1 Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java
  14. +2 −2 Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
  15. +2 −2 Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java
  16. +38 −29 Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java
  17. +14 −14 Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java
  18. +2 −1 Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  19. +6 −0 DEV_LOG.md
  20. +4 −6 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java
  21. +4 −0 M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java
  22. +2 −1 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java
  23. +10 −0 PublicComponent/src/main/java/com/arialyy/aria/core/AriaConfig.java
  24. +0 −55 PublicComponent/src/main/java/com/arialyy/aria/core/listener/UploadListener.java
  25. +1 −1 PublicComponent/src/main/java/com/arialyy/aria/core/loader/ThreadStateManager.java
  26. +9 −8 PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  27. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java
  28. +18 −0 PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
  29. +52 −39 PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  30. +1 −1 PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java
  31. +41 −4 PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java
  32. +8 −3 app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  33. +6 −2 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  34. +2 −2 app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java
  35. +2 −2 build.gradle
  36. +0 −15 py/.vscode/launch.json
  37. +0 −6 py/.vscode/settings.json
  38. BIN test/347/AndroidAria.db
@@ -23,8 +23,6 @@
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.PopupWindow;
import com.arialyy.aria.core.command.CommandManager;
import com.arialyy.aria.core.common.QueueMod;
@@ -76,7 +74,6 @@
*/
private Map<String, List<String>> mSubClass = new ConcurrentHashMap<>();
private static Context APP;
private Handler mAriaHandler;
private DelegateWrapper mDbWrapper;
private AriaConfig mConfig;

@@ -168,13 +165,6 @@ private void amendTaskState() {
}
}

public synchronized Handler getAriaHandler() {
if (mAriaHandler == null) {
mAriaHandler = new Handler(Looper.getMainLooper());
}
return mAriaHandler;
}

public Map<String, AbsReceiver> getReceiver() {
return mReceivers;
}
@@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.command;

import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
@@ -41,7 +42,7 @@

@Override public void executeCmd() {
if (!canExeCmd) return;
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())){
if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())){
ALog.e(TAG, "启动任务失败,网络未连接");
return;
}
@@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.command;

import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
@@ -36,7 +36,7 @@
}

@Override public void executeCmd() {
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) {
if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())) {
ALog.w(TAG, "恢复任务失败,网络未连接");
return;
}
@@ -16,7 +16,7 @@

package com.arialyy.aria.core.command;

import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.AbsTask;
@@ -37,6 +37,7 @@

/**
* 立即执行任务
*
* @param newStart true 立即执行任务,无论执行队列是否满了
*/
public void setNewStart(boolean newStart) {
@@ -45,17 +46,17 @@ public void setNewStart(boolean newStart) {

@Override public void executeCmd() {
if (!canExeCmd) return;
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) {
if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())) {
ALog.e(TAG, "启动任务失败,网络未连接");
return;
}
String mod;
int maxTaskNum = mQueue.getMaxTaskNum();
AriaManager manager = AriaManager.getInstance();
AriaConfig config = AriaConfig.getInstance();
if (isDownloadCmd) {
mod = manager.getDownloadConfig().getQueueMod();
mod = config.getDConfig().getQueueMod();
} else {
mod = manager.getUploadConfig().getQueueMod();
mod = config.getUConfig().getQueueMod();
}

AbsTask task = getTask();
@@ -81,9 +82,9 @@ public void setNewStart(boolean newStart) {
startTask();
}
} else {
if (newStart){
if (newStart) {
startTask();
}else {
} else {
sendWaitState(task);
}
}
@@ -15,8 +15,8 @@
*/
package com.arialyy.aria.core.common;

import com.arialyy.aria.core.common.controller.IStartFeature;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.core.common.controller.IStartFeature;
import com.arialyy.aria.core.inf.AbsTarget;

/**
@@ -34,6 +34,14 @@ private synchronized BuilderController getController() {
return mStartController;
}

/**
* 是否忽略权限检查
*/
public TARGET ignoreCheckPermissions() {
getController().ignoreCheckPermissions();
return (TARGET) this;
}

/**
* 添加任务
*
@@ -31,6 +31,14 @@
public abstract class AbsNormalTarget<TARGET extends AbsNormalTarget> extends AbsTarget<TARGET>
implements INormalFeature {

/**
* 是否忽略权限检查
*/
public TARGET ignoreCheckPermissions() {
getController().ignoreCheckPermissions();
return (TARGET) this;
}

/**
* 任务是否在执行
*
@@ -19,21 +19,21 @@
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.download.CheckDEntityUtil;
import com.arialyy.aria.core.download.CheckDGEntityUtil;
import com.arialyy.aria.core.download.CheckFtpDirEntityUtil;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.upload.CheckUEntityUtil;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Constructor;
@@ -46,6 +46,10 @@
private final String TAG;

private AbsTaskWrapper mTaskWrapper;
/**
* 是否忽略权限检查 true 忽略权限检查
*/
private boolean ignoreCheckPermissions = false;

FeatureController(AbsTaskWrapper wrapper) {
mTaskWrapper = wrapper;
@@ -87,6 +91,13 @@
return null;
}

/**
* 是否忽略权限检查
*/
public void ignoreCheckPermissions() {
this.ignoreCheckPermissions = true;
}

protected AbsTaskWrapper getTaskWrapper() {
return mTaskWrapper;
}
@@ -111,7 +122,7 @@ int checkTaskType() {
* 如果检查实体失败,将错误回调
*/
boolean checkConfig() {
if (!checkPermission()) {
if (!ignoreCheckPermissions && !checkPermission()) {
return false;
}
boolean b = checkEntity();
@@ -134,21 +145,21 @@ boolean checkConfig() {
*/
private boolean checkPermission() {

if (AriaManager.getInstance()
if (AriaConfig.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.WRITE_EXTERNAL_STORAGE");
return false;
}
if (AriaManager.getInstance()
if (AriaConfig.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.INTERNET");
return false;
}
if (AriaManager.getInstance()
if (AriaConfig.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
@@ -23,6 +23,7 @@
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.RecordUtil;
import java.io.File;

@@ -65,8 +66,7 @@ private void handleM3U8() {
File file = new File(mWrapper.getTempFilePath());
Object bw = mWrapper.getM3U8Params().getParam(IOptionConstant.bandWidth);
int bandWidth = bw == null ? 0 : (int) bw;
// 缓存文件夹格式:问文件夹/.文件名_码率
String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(), bandWidth);
String cacheDir = FileUtil.getTsCacheDir(file.getPath(), bandWidth);

mWrapper.getM3U8Params().setParams(IOptionConstant.cacheDir, cacheDir);
M3U8Entity m3U8Entity = mEntity.getM3U8Entity();
@@ -18,6 +18,7 @@
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CancelAllCmd;
import com.arialyy.aria.core.command.CmdHelper;
@@ -64,7 +65,7 @@
*/
@Deprecated
public DownloadReceiver setMaxSpeed(int maxSpeed) {
AriaManager.getInstance().getDownloadConfig().setMaxSpeed(maxSpeed);
AriaConfig.getInstance().getDConfig().setMaxSpeed(maxSpeed);
return this;
}

@@ -287,7 +288,7 @@ public DownloadGroupEntity getGroupEntity(long taskId) {
* @return 如果实体不存在,返回null
*/
public DownloadGroupEntity getGroupEntity(List<String> urls) {
if (CheckUtil.checkDownloadUrlsIsEmpty(urls)){
if (CheckUtil.checkDownloadUrlsIsEmpty(urls)) {
return null;
}
return DbDataHelper.getDGEntity(CommonUtil.getMd5Code(urls));
@@ -16,13 +16,13 @@

package com.arialyy.aria.core.queue;

import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.event.DGMaxNumEvent;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.util.ALog;

/**
@@ -57,7 +57,7 @@ public void maxTaskNum(DGMaxNumEvent event) {
}

@Override public int getMaxTaskNum() {
return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum();
return AriaConfig.getInstance().getDConfig().getMaxTaskNum();
}

@Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) {
@@ -74,6 +74,6 @@ public void maxTaskNum(DGMaxNumEvent event) {
}

@Override public int getOldMaxNum() {
return AriaManager.getInstance().getDGroupConfig().oldMaxTaskNum;
return AriaConfig.getInstance().getDGConfig().oldMaxTaskNum;
}
}
@@ -16,14 +16,14 @@

package com.arialyy.aria.core.queue;

import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.event.DMaxNumEvent;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -60,7 +60,7 @@ public void maxTaskNum(DMaxNumEvent event) {
}

@Override public int getOldMaxNum() {
return AriaManager.getInstance().getDownloadConfig().oldMaxTaskNum;
return AriaConfig.getInstance().getDConfig().oldMaxTaskNum;
}

/**
@@ -81,7 +81,7 @@ public void setTaskHighestPriority(DownloadTask task) {
}
}
}
int maxSize = AriaManager.getInstance().getDownloadConfig().getMaxTaskNum();
int maxSize = AriaConfig.getInstance().getDConfig().getMaxTaskNum();
int currentSize = mExecutePool.size();
if (currentSize == 0 || currentSize < maxSize) {
startTask(task);
@@ -126,6 +126,6 @@ public void setTaskHighestPriority(DownloadTask task) {
}

@Override public int getMaxTaskNum() {
return AriaManager.getInstance().getDownloadConfig().getMaxTaskNum();
return AriaConfig.getInstance().getDConfig().getMaxTaskNum();
}
}
@@ -16,6 +16,7 @@

package com.arialyy.aria.core.queue;

import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
@@ -55,11 +56,11 @@ public void maxTaskNum(UMaxNumEvent event){
}

@Override public int getOldMaxNum() {
return AriaManager.getInstance().getUploadConfig().oldMaxTaskNum;
return AriaConfig.getInstance().getUConfig().oldMaxTaskNum;
}

@Override public int getMaxTaskNum() {
return AriaManager.getInstance().getUploadConfig().getMaxTaskNum();
return AriaConfig.getInstance().getUConfig().getMaxTaskNum();
}

@Override public UploadTask createTask(UTaskWrapper wrapper) {

0 comments on commit 669aa69

Please sign in to comment.
You can’t perform that action at this time.