laoyuyu 5 years ago
commit 22c81369b5
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  2. 31
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  3. 7
      Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java
  4. 6
      Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  8. 10
      Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java
  9. 12
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  10. 6
      Aria/src/main/java/com/arialyy/aria/core/common/BaseDelegate.java
  11. 6
      Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java
  13. 72
      Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java
  14. 68
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java
  15. 47
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java
  16. 12
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/FTPSDelegate.java
  17. 12
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java
  18. 14
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskConfig.java
  19. 9
      Aria/src/main/java/com/arialyy/aria/core/common/http/HttpDelegate.java
  20. 2
      Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java
  21. 4
      Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java
  22. 19
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  23. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  24. 47
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  25. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  26. 14
      Aria/src/main/java/com/arialyy/aria/core/download/FtpBuilderTarget.java
  27. 14
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirBuilderTarget.java
  28. 24
      Aria/src/main/java/com/arialyy/aria/core/download/GroupBuilderTarget.java
  29. 20
      Aria/src/main/java/com/arialyy/aria/core/download/HttpBuilderTarget.java
  30. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  31. 6
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java
  32. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  33. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  34. 2
      Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java
  35. 66
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java
  36. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
  37. 3
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
  38. 5
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java
  39. 2
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java
  40. 68
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java
  41. 4
      Aria/src/main/java/com/arialyy/aria/core/event/PeerIndexEvent.java
  42. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  43. 26
      Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  44. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  45. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  46. 10
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  47. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  48. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  49. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java
  50. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
  51. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java
  52. 44
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  53. 46
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  54. 124
      Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java
  55. 136
      Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java
  56. 44
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  57. 29
      Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java
  58. 14
      Aria/src/main/java/com/arialyy/aria/core/upload/FtpBuilderTarget.java
  59. 12
      Aria/src/main/java/com/arialyy/aria/core/upload/HttpBuilderTarget.java
  60. 26
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  61. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  62. 14
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java
  63. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java
  64. 12
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  65. 52
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  66. 3
      Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
  67. 97
      Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
  68. 2
      Aria/src/main/java/com/arialyy/aria/util/NetUtils.java
  69. 2
      Aria/src/main/java/com/arialyy/aria/util/SSLContextUtil.java
  70. 10
      DEV_LOG.md
  71. 33
      README.md
  72. 10
      app/src/main/AndroidManifest.xml
  73. 13
      app/src/main/java/com/arialyy/simple/base/BaseApplication.java
  74. 45
      app/src/main/java/com/arialyy/simple/common/NormalToAdapter.java
  75. 78
      app/src/main/java/com/arialyy/simple/core/download/ComponentActivity.java
  76. 47
      app/src/main/java/com/arialyy/simple/core/download/DownloadActivity.java
  77. 4
      app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java
  78. 2
      app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java
  79. 10
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  80. 2
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java
  81. 2
      app/src/main/java/com/arialyy/simple/core/download/HighestPriorityActivity.java
  82. 2
      app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  83. 2
      app/src/main/java/com/arialyy/simple/core/download/KotlinDownloadActivity.kt
  84. 2
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  85. 10
      app/src/main/java/com/arialyy/simple/core/download/fragment/DownloadFragment.java
  86. 8
      app/src/main/java/com/arialyy/simple/core/download/fragment/FragmentActivity.java
  87. 4
      app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java
  88. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java
  89. 8
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  90. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
  91. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/DownloadAdapter.java
  92. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/DownloadNumDialog.java
  93. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/FileListAdapter.java
  94. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/FileListEntity.java
  95. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiDownloadActivity.java
  96. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiEntity.java
  97. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiModule.java
  98. 2
      app/src/main/java/com/arialyy/simple/core/download/mutil/MultiTaskActivity.java
  99. 2
      app/src/main/java/com/arialyy/simple/core/download/service/DownloadNotification.java
  100. 2
      app/src/main/java/com/arialyy/simple/core/download/service/DownloadService.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -116,7 +116,7 @@ import com.arialyy.aria.util.ALog;
+ "请参考【https://aria.laoyuyu.me/aria_doc/create/any_java.html】,参数请使用 download(this) 或 upload(this);"
+ "不要使用 download(getContext()) 或 upload(getContext())");
}
return AriaManager.getInstance(context);
return AriaManager.init(context);
}
/**
@ -126,7 +126,7 @@ import com.arialyy.aria.util.ALog;
* {@link #download(Object)}{@link #upload(Object)}
*/
public static AriaManager init(Context context) {
return AriaManager.getInstance(context);
return get(context);
}
private static Context convertContext(Object obj) {

@ -86,7 +86,7 @@ import org.xml.sax.SAXException;
* activity 和其DialogFragment的映射表
*/
private Map<String, List<String>> mSubClass = new ConcurrentHashMap<>();
public static Context APP;
private static Context APP;
private DownloadConfig mDConfig;
private UploadConfig mUConfig;
private AppConfig mAConfig;
@ -96,27 +96,38 @@ import org.xml.sax.SAXException;
private AriaManager(Context context) {
APP = context.getApplicationContext();
initDb(APP);
regAppLifeCallback(context);
initConfig();
initAria();
amendTaskState();
regNetCallBack(context);
}
public static AriaManager getInstance(Context context) {
public static AriaManager getInstance() {
if (INSTANCE == null) {
throw new NullPointerException("请使用AriaManager.init(context)初始化管理器");
}
return INSTANCE;
}
static AriaManager init(Context context) {
if (INSTANCE == null) {
synchronized (LOCK) {
if (INSTANCE == null) {
INSTANCE = new AriaManager(context);
INSTANCE.initData();
}
}
}
return INSTANCE;
}
static AriaManager getInstance() {
return INSTANCE;
private void initData() {
initDb(APP);
regAppLifeCallback(APP);
initConfig();
initAria();
amendTaskState();
regNetCallBack(APP);
}
public Context getAPP() {
return APP;
}
/**

@ -94,7 +94,12 @@ public class FtpUrlEntity implements Cloneable {
* {@link ProtocolType}
*/
@ProtocolType
public String protocol;
public String protocol = ProtocolType.Default;
/**
* 安全模式 true 隐式false 显式
*/
public boolean isImplicit = true;
/**
* 私钥别名

@ -80,7 +80,7 @@ final class WidgetLiftManager {
private PopupWindow.OnDismissListener createPopupWindowListener(final PopupWindow popupWindow) {
return new PopupWindow.OnDismissListener() {
@Override public void onDismiss() {
AriaManager.getInstance(AriaManager.APP).removeReceiver(popupWindow);
AriaManager.getInstance().removeReceiver(popupWindow);
}
};
}
@ -120,7 +120,7 @@ final class WidgetLiftManager {
return new Dialog.OnCancelListener() {
@Override public void onCancel(DialogInterface dialog) {
AriaManager.getInstance(AriaManager.APP).removeReceiver(dialog);
AriaManager.getInstance().removeReceiver(dialog);
}
};
}
@ -132,7 +132,7 @@ final class WidgetLiftManager {
return new Dialog.OnDismissListener() {
@Override public void onDismiss(DialogInterface dialog) {
AriaManager.getInstance(AriaManager.APP).removeReceiver(dialog);
AriaManager.getInstance().removeReceiver(dialog);
}
};
}

@ -41,7 +41,7 @@ final class HighestPriorityCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T>
@Override public void executeCmd() {
if (!canExeCmd) return;
if (!NetUtils.isConnected(AriaManager.APP)){
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())){
ALog.e(TAG, "启动任务失败,网络未连接");
return;
}

@ -36,7 +36,7 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
}
@Override public void executeCmd() {
if (!NetUtils.isConnected(AriaManager.APP)) {
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) {
ALog.w(TAG, "恢复任务失败,网络未连接");
return;
}

@ -50,13 +50,13 @@ final class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
@Override public void executeCmd() {
if (!canExeCmd) return;
if (!NetUtils.isConnected(AriaManager.APP)) {
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) {
ALog.e(TAG, "启动任务失败,网络未连接");
return;
}
String mod;
int maxTaskNum = mQueue.getMaxTaskNum();
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
AriaManager manager = AriaManager.getInstance();
if (isDownloadCmd) {
mod = manager.getDownloadConfig().getQueueMod();
} else {

@ -16,20 +16,20 @@
package com.arialyy.aria.core.common;
import com.arialyy.aria.core.common.controller.IStartFeature;
import com.arialyy.aria.core.common.controller.StartController;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.core.inf.AbsTarget;
/**
* 处理第一次下载
*/
public abstract class AbsStartTarget<TARGET extends AbsStartTarget> extends AbsTarget<TARGET>
public abstract class AbsBuilderTarget<TARGET extends AbsBuilderTarget> extends AbsTarget<TARGET>
implements IStartFeature {
private StartController mStartController;
private BuilderController mStartController;
private synchronized StartController getController() {
private synchronized BuilderController getController() {
if (mStartController == null) {
mStartController = new StartController(getTaskWrapper());
mStartController = new BuilderController(getTaskWrapper());
}
return mStartController;
}

@ -89,7 +89,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER
mEntity = mTaskWrapper.getEntity();
mLastSaveTime = System.currentTimeMillis();
mConfigThreadPool = Executors.newCachedThreadPool();
mAridManager = AriaManager.getInstance(AriaManager.APP);
mAridManager = AriaManager.getInstance();
if (getMaxSpeed() > 0) {
mSpeedBandUtil = new BandwidthLimiter(getMaxSpeed(), config.startThreadNum);
}
@ -375,13 +375,14 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER
* 重试ts分片
*/
private void retryM3U8Peer(boolean needRetry) {
boolean isConnected = NetUtils.isConnected(AriaManager.APP);
boolean isConnected = NetUtils.isConnected(AriaManager.getInstance().getAPP());
if (!isConnected && !isNotNetRetry) {
ALog.w(TAG, String.format("ts切片【%s】重试失败,网络未连接", getFileName()));
sendFailMsg(null);
return;
}
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(
AriaManager.getInstance().getAPP())
|| isNotNetRetry) && !isBreak()) {
ALog.w(TAG, String.format("ts切片【%s】正在重试", getFileName()));
mFailTimes++;
@ -399,12 +400,13 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER
* @param needRetry 是否可以重试
*/
private void retryBlockTask(boolean needRetry) {
if (!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) {
if (!NetUtils.isConnected(AriaManager.getInstance().getAPP()) && !isNotNetRetry) {
ALog.w(TAG, String.format("分块【%s】重试失败,网络未连接", getFileName()));
sendFailMsg(null);
return;
}
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(
AriaManager.getInstance().getAPP())
|| isNotNetRetry) && !isBreak()) {
ALog.w(TAG, String.format("分块【%s】正在重试", getFileName()));
mFailTimes++;

@ -39,10 +39,10 @@ public abstract class BaseDelegate<TARGET extends AbsTarget> {
/**
* 使用对应等控制器注意
* 1对于不存在的任务第一次下载只能使用{@link ControllerType#START_CONTROLLER}
* 2对于已存在的任务只能使用{@link ControllerType#NORMAL_CONTROLLER}
* 1对于不存在的任务第一次下载只能使用{@link ControllerType#CREATE_CONTROLLER}
* 2对于已存在的任务只能使用{@link ControllerType#TASK_CONTROLLER}
*
* @param clazz {@link ControllerType#START_CONTROLLER}{@link ControllerType#NORMAL_CONTROLLER}
* @param clazz {@link ControllerType#CREATE_CONTROLLER}{@link ControllerType#TASK_CONTROLLER}
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public synchronized <T extends FeatureController> T controller(@ControllerType Class<T> clazz) {

@ -21,11 +21,11 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil;
/**
* 启动控制器
* 创建任务时使用的控制器
*/
public final class StartController extends FeatureController implements IStartFeature {
public final class BuilderController extends FeatureController implements IStartFeature {
public StartController(AbsTaskWrapper wrapper) {
public BuilderController(AbsTaskWrapper wrapper) {
super(wrapper);
}

@ -22,9 +22,9 @@ import java.lang.annotation.RetentionPolicy;
/**
* 仅用于第一次创建任务后续可调用`#create()#add()#setHighestPriority()`方法
*/
Class<StartController> START_CONTROLLER = StartController.class;
Class<BuilderController> CREATE_CONTROLLER = BuilderController.class;
/**
* 用于后续的任务控制后续可调用`#stop()#resume()#cancel()#cancel(boolean)#retry()#restart()`方法
*/
Class<NormalController> NORMAL_CONTROLLER = NormalController.class;
Class<NormalController> TASK_CONTROLLER = NormalController.class;
}

@ -15,8 +15,11 @@
*/
package com.arialyy.aria.core.common.controller;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.CheckDEntityUtil;
import com.arialyy.aria.core.download.CheckDGEntityUtil;
import com.arialyy.aria.core.download.CheckFtpDirEntityUtil;
@ -27,13 +30,12 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.upload.CheckUEntityUtil;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -41,28 +43,31 @@ import java.lang.reflect.InvocationTargetException;
* 功能控制器
*/
public abstract class FeatureController {
private final String TAG;
private AbsTaskWrapper mTaskWrapper;
FeatureController(AbsTaskWrapper wrapper) {
mTaskWrapper = wrapper;
TAG = CommonUtil.getClassName(getClass());
}
/**
* 使用对应等控制器注意
* 1对于不存在的任务第一次下载只能使用{@link ControllerType#START_CONTROLLER}
* 2对于已存在的任务只能使用{@link ControllerType#NORMAL_CONTROLLER}
* 1对于不存在的任务第一次下载只能使用{@link ControllerType#CREATE_CONTROLLER}
* 2对于已存在的任务只能使用{@link ControllerType#TASK_CONTROLLER}
*
* @param clazz {@link ControllerType#START_CONTROLLER}{@link ControllerType#NORMAL_CONTROLLER}
* @param clazz {@link ControllerType#CREATE_CONTROLLER}{@link ControllerType#TASK_CONTROLLER}
*/
public static <T extends FeatureController> T newInstance(@ControllerType Class<T> clazz,
AbsTaskWrapper wrapper) {
if (wrapper.getEntity().getId() == -1 && clazz != ControllerType.START_CONTROLLER) {
throw new IllegalArgumentException("对于不存在的任务(第一次下载),只能使用\"ControllerType.START_CONTROLLER\"");
if (wrapper.getEntity().getId() == -1 && clazz != ControllerType.CREATE_CONTROLLER) {
throw new IllegalArgumentException(
"对于不存在的任务(第一次下载),只能使用\"ControllerType.CREATE_CONTROLLER\"");
}
if (wrapper.getEntity().getId() != -1 && clazz != ControllerType.NORMAL_CONTROLLER) {
if (wrapper.getEntity().getId() != -1 && clazz != ControllerType.TASK_CONTROLLER) {
throw new IllegalArgumentException(
"对于已存在的任务,只能使用\" ControllerType.NORMAL_CONTROLLER\",请检查是否重复调用#create()方法");
"对于已存在的任务,只能使用\" ControllerType.TASK_CONTROLLER\",请检查是否重复调用#create()方法");
}
Class[] paramTypes = { AbsTaskWrapper.class };
@ -106,8 +111,11 @@ public abstract class FeatureController {
* 如果检查实体失败将错误回调
*/
boolean checkConfig() {
if (!checkPermission()) {
return false;
}
boolean b = checkEntity();
ISchedulers schedulers = getScheduler();
TaskSchedulers schedulers = TaskSchedulers.getInstance();
if (!b && schedulers != null) {
new Handler(Looper.getMainLooper(), schedulers).obtainMessage(ISchedulers.CHECK_FAIL,
checkTaskType(), -1, null).sendToTarget();
@ -116,17 +124,39 @@ public abstract class FeatureController {
return b;
}
private ISchedulers getScheduler() {
if (mTaskWrapper instanceof DTaskWrapper) {
return DownloadSchedulers.getInstance();
}
if (mTaskWrapper instanceof UTaskWrapper) {
return UploadSchedulers.getInstance();
}
if (mTaskWrapper instanceof DGTaskWrapper) {
return DownloadGroupSchedulers.getInstance();
/**
* 检查权限需要的权限有
* {@link Manifest.permission#WRITE_EXTERNAL_STORAGE}
* {@link Manifest.permission#READ_EXTERNAL_STORAGE}
* {@link Manifest.permission#INTERNET}
*
* @return {@code false} 缺少权限
*/
private boolean checkPermission() {
if (AriaManager.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.WRITE_EXTERNAL_STORAGE");
return false;
}
if (AriaManager.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.INTERNET");
return false;
}
if (AriaManager.getInstance()
.getAPP()
.checkCallingOrSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.READ_EXTERNAL_STORAGE");
return false;
}
return null;
return true;
}
private boolean checkEntity() {

@ -18,17 +18,15 @@ package com.arialyy.aria.core.common.ftp;
import android.net.TrafficStats;
import android.os.Process;
import android.text.TextUtils;
import aria.apache.commons.net.ftp.FTP;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPClientConfig;
import aria.apache.commons.net.ftp.FTPFile;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
@ -40,7 +38,6 @@ import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Regular;
import com.arialyy.aria.util.SSLContextUtil;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
@ -48,7 +45,6 @@ import java.net.UnknownHostException;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
/**
@ -72,7 +68,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
mEntity = taskWrapper.getEntity();
mTaskDelegate = taskWrapper.asFtp();
mConnectTimeOut =
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
AriaManager.getInstance().getDownloadConfig().getConnectTimeOut();
mCallback = callback;
if (mEntity instanceof UploadEntity) {
isUpload = true;
@ -98,10 +94,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
return;
}
String remotePath = CommonUtil.convertFtpChar(charSet, getRemotePath());
if (mTaskDelegate.getUrlEntity().isFtps) {
((FTPSClient) client).execPROT("P");
//((FTPSClient) client).enterLocalActiveMode();
}
FTPFile[] files = client.listFiles(remotePath);
boolean isExist = files.length != 0;
if (!isExist && !isUpload) {
@ -207,9 +200,10 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
Matcher m = p.matcher(urlEntity.hostName);
if (m.find() && m.groupCount() > 0) {
client = newInstanceClient(urlEntity);
InetAddress ip = InetAddress.getByName(urlEntity.hostName);
client.setConnectTimeout(mConnectTimeOut); // 连接10s超时
client.connect(ip, Integer.parseInt(urlEntity.port));
InetAddress ip = InetAddress.getByName(urlEntity.hostName);
client = connect(client, new InetAddress[] { ip }, 0, Integer.parseInt(urlEntity.port));
mTaskDelegate.getUrlEntity().validAddr = ip;
} else {
DNSQueryThread dnsThread = new DNSQueryThread(urlEntity.hostName);
@ -219,12 +213,6 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
client = connect(newInstanceClient(urlEntity), ips, 0, Integer.parseInt(urlEntity.port));
}
if (urlEntity.isFtps) {
int code = ((FTPSClient) client).execAUTH(
TextUtils.isEmpty(urlEntity.protocol) ? ProtocolType.TLS : urlEntity.protocol);
ALog.d(TAG, String.format("cod:%s,msg:%s", code, client.getReplyString()));
}
if (client == null) {
failDownload(new AriaIOException(TAG,
String.format("链接失败, url: %s", mTaskDelegate.getUrlEntity().url)), false);
@ -292,6 +280,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
protected void closeClient(FTPClient client) {
try {
if (client != null && client.isConnected()) {
client.logout();
client.disconnect();
}
} catch (IOException e) {
@ -303,18 +292,31 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
* 创建FTP/FTPS客户端
*/
private FTPClient newInstanceClient(FtpUrlEntity urlEntity) {
FTPClient temp = null;
FTPClient temp;
if (urlEntity.isFtps) {
SSLContext sslContext =
SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath, urlEntity.protocol);
FTPSClient sClient;
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
urlEntity.protocol);
if (sslContext == null) {
sslContext = SSLContextUtil.getDefaultSLLContext(urlEntity.protocol);
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
} else {
sClient = new FTPSClient(true, sslContext);
}
temp = new FTPSClient(true, sslContext);
temp = sClient;
} else {
temp = new FTPClient();
}
FTPClientConfig clientConfig;
if (mTaskWrapper.asFtp().getClientConfig() != null) {
clientConfig = mTaskWrapper.asFtp().getClientConfig();
} else {
clientConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
clientConfig.setServerLanguageCode("en");
}
temp.configure(clientConfig);
return temp;
}
@ -330,18 +332,20 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
client.setConnectTimeout(mConnectTimeOut); //需要先设置超时,这样才不会出现阻塞
client.connect(ips[index], port);
mTaskDelegate.getUrlEntity().validAddr = ips[index];
FtpUrlEntity urlEntity = mTaskWrapper.asFtp().getUrlEntity();
if (urlEntity.isFtps) {
FTPSClient sClient = (FTPSClient) client;
sClient.execPBSZ(0);
sClient.execPROT("P");
}
return client;
} catch (IOException e) {
//e.printStackTrace();
try {
if (client.isConnected()) {
client.disconnect();
}
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
closeClient(client);
if (index + 1 >= ips.length) {
ALog.w(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,已没有其他地址,链接失败");
ALog.w(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,已没有其他地址,链接失败;如果是ftps,请检查端口是否使用了ftp的端口而不是ftps的端口");
return null;
}
try {

@ -18,17 +18,18 @@ package com.arialyy.aria.core.common.ftp;
import android.text.TextUtils;
import aria.apache.commons.net.ftp.FTP;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPClientConfig;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.net.ssl.SSLContext;
@ -45,6 +46,17 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
super(config);
}
protected void closeClient(FTPClient client) {
try {
if (client != null && client.isConnected()) {
client.logout();
client.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 构建FTP客户端
*/
@ -77,9 +89,9 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
try {
if (urlEntity.isFtps) {
int code = ((FTPSClient) client).execAUTH(
TextUtils.isEmpty(urlEntity.protocol) ? ProtocolType.TLS : urlEntity.protocol);
ALog.d(TAG, String.format("cod:%s,msg:%s", code, client.getReplyString()));
FTPSClient sClient = (FTPSClient) client;
sClient.execPBSZ(0);
sClient.execPROT("P");
}
if (urlEntity.needLogin) {
@ -109,10 +121,8 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
client.enterLocalPassiveMode();
client.setFileType(FTP.BINARY_FILE_TYPE);
client.setControlKeepAliveTimeout(5000);
if (getTaskWrapper().asFtp().getUrlEntity().isFtps) {
((FTPSClient) client).execPROT("P");
}
} catch (java.io.IOException e) {
} catch (IOException e) {
closeClient(client);
e.printStackTrace();
}
return client;
@ -124,16 +134,29 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
private FTPClient newInstanceClient(FtpUrlEntity urlEntity) {
FTPClient temp;
if (urlEntity.isFtps) {
SSLContext sslContext =
SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath, urlEntity.protocol);
FTPSClient sClient;
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
urlEntity.protocol);
if (sslContext == null) {
sslContext = SSLContextUtil.getDefaultSLLContext(urlEntity.protocol);
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
} else {
sClient = new FTPSClient(true, sslContext);
}
temp = new FTPSClient(true, sslContext);
temp = sClient;
} else {
temp = new FTPClient();
}
FTPClientConfig clientConfig;
if (mTaskWrapper.asFtp().getClientConfig() != null) {
clientConfig = mTaskWrapper.asFtp().getClientConfig();
} else {
clientConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
clientConfig.setServerLanguageCode("en");
}
temp.configure(clientConfig);
return temp;
}

@ -34,6 +34,7 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
public FTPSDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mUrlEntity = getTaskWrapper().asFtp().getUrlEntity();
mUrlEntity.isFtps = true;
}
/**
@ -91,4 +92,15 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
mUrlEntity.storePath = storePath;
return this;
}
/**
* 设置安全模式默认true
*
* @param isImplicit true 隐式false 显式
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setImplicit(boolean isImplicit) {
mUrlEntity.isImplicit = isImplicit;
return this;
}
}

@ -15,8 +15,9 @@
*/
package com.arialyy.aria.core.common.ftp;
import androidx.annotation.CheckResult;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import aria.apache.commons.net.ftp.FTPClientConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
@ -76,6 +77,15 @@ public class FtpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
return new FTPSDelegate<>(mTarget, mWrapper);
}
/**
* 配置ftp客户端信息
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> setFtpClentConfig(FTPClientConfig config) {
getTaskWrapper().asFtp().setClientConfig(config);
return this;
}
//@Override public TARGET setProxy(Proxy proxy) {
// mTarget.getTaskWrapper().asFtp().setProxy(proxy);
// return mTarget;

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.common.ftp;
import aria.apache.commons.net.ftp.FTPClientConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.ITaskConfig;
import java.lang.ref.WeakReference;
@ -47,6 +48,19 @@ public class FtpTaskConfig implements ITaskConfig {
*/
private String newFileName;
/**
* client配置信息
*/
private FTPClientConfig clientConfig;
public FTPClientConfig getClientConfig() {
return clientConfig;
}
public void setClientConfig(FTPClientConfig clientConfig) {
this.clientConfig = clientConfig;
}
public String getNewFileName() {
return newFileName;
}

@ -77,6 +77,15 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
return this;
}
/**
* 设置http表单字段
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setFormFields(Map<String, String> params) {
getTaskWrapper().asHttp().setFormFields(params);
return this;
}
/**
* 给url请求添加Header数据
* 如果新的header数据和数据保存的不一致则更新数据库中对应的header数据

@ -24,7 +24,7 @@ abstract class BaseConfig implements Serializable {
* 保存配置
*/
void save() {
String basePath = AriaManager.APP.getFilesDir().getPath();
String basePath = AriaManager.getInstance().getAPP().getFilesDir().getPath();
String path = null;
switch (getType()) {
case TYPE_DOWNLOAD:

@ -37,7 +37,7 @@ public final class Configuration {
private Configuration() {
//删除老版本的配置文件
String basePath = AriaManager.APP.getFilesDir().getPath();
String basePath = AriaManager.getInstance().getAPP().getFilesDir().getPath();
del351Config(basePath);
File newDCfg = new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE));
File newUCfg = new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE));
@ -89,7 +89,7 @@ public final class Configuration {
* @return {@code true}配置存在{@code false}配置不存在
*/
public boolean configExists() {
String basePath = AriaManager.APP.getFilesDir().getPath();
String basePath = AriaManager.getInstance().getAPP().getFilesDir().getPath();
return (new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE))).exists()
&& (new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE))).exists()
&& (new File(String.format("%s%s", basePath, APP_CONFIG_FILE))).exists()

@ -190,17 +190,14 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
}
private boolean checkFtps() {
if (mWrapper.getRequestType() == ITaskWrapper.D_FTP && mWrapper.asFtp()
.getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
ALog.e(TAG, "证书路径为空");
return false;
}
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().keyAlias)) {
ALog.e(TAG, "证书别名为空");
return false;
}
}
//if (mWrapper.getRequestType() == ITaskWrapper.D_FTP && mWrapper.asFtp()
// .getUrlEntity().isFtps) {
// String ftpUrl = mEntity.getUrl();
// if (!ftpUrl.startsWith("ftps") && !ftpUrl.startsWith("sftp")) {
// ALog.e(TAG, String.format("地址【%s】错误,ftps地址开头必须是:ftps或sftp", ftpUrl));
// return false;
// }
//}
return true;
}
}

@ -37,7 +37,7 @@ public class DownloadGroupTask extends AbsGroupTask<DGTaskWrapper> {
private DownloadGroupTask(DGTaskWrapper taskWrapper, Handler outHandler) {
mTaskWrapper = taskWrapper;
mOutHandler = outHandler;
mContext = AriaManager.APP;
mContext = AriaManager.getInstance().getAPP();
mListener = new DownloadGroupListener(this, mOutHandler);
}

@ -22,15 +22,14 @@ import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CancelAllCmd;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
@ -55,7 +54,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@Deprecated
public DownloadReceiver setMaxSpeed(int maxSpeed) {
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMaxSpeed(maxSpeed);
AriaManager.getInstance().getDownloadConfig().setMaxSpeed(maxSpeed);
return this;
}
@ -65,15 +64,15 @@ public class DownloadReceiver extends AbsReceiver {
* @param url 下载地址
*/
@CheckResult
public HttpStartTarget load(@NonNull String url) {
public HttpBuilderTarget load(@NonNull String url) {
CheckUtil.checkUrlInvalidThrow(url);
return new HttpStartTarget(url, targetName);
return new HttpBuilderTarget(url, targetName);
}
/**
* 用于任务停止删除等操作
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -88,15 +87,15 @@ public class DownloadReceiver extends AbsReceiver {
* @param urls 组合任务只任务列被如果任务组的中的下载地址改变了则任务从新的一个任务组
*/
@CheckResult
public GroupStartTarget loadGroup(List<String> urls) {
public GroupBuilderTarget loadGroup(List<String> urls) {
CheckUtil.checkDownloadUrls(urls);
return new GroupStartTarget(urls, targetName);
return new GroupBuilderTarget(urls, targetName);
}
/**
* 加载组合任务用于任务停止删除等操作
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* * AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -109,15 +108,15 @@ public class DownloadReceiver extends AbsReceiver {
* 加载ftp单任务下载地址用于任务第一次下载如果需要控制任务停止或删除等操作请使用{@link #loadFtp(long)}
*/
@CheckResult
public FtpStartTarget loadFtp(@NonNull String url) {
public FtpBuilderTarget loadFtp(@NonNull String url) {
CheckUtil.checkUrlInvalidThrow(url);
return new FtpStartTarget(url, targetName);
return new FtpBuilderTarget(url, targetName);
}
/**
* 用于任务停止删除等操作
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -130,15 +129,15 @@ public class DownloadReceiver extends AbsReceiver {
* 加载ftp文件夹下载地址用于任务第一次下载如果需要控制任务停止或删除等操作请使用{@link #loadFtpDir(long)}
*/
@CheckResult
public FtpDirStartTarget loadFtpDir(@NonNull String dirUrl) {
public FtpDirBuilderTarget loadFtpDir(@NonNull String dirUrl) {
CheckUtil.checkUrlInvalidThrow(dirUrl);
return new FtpDirStartTarget(dirUrl, targetName);
return new FtpDirBuilderTarget(dirUrl, targetName);
}
/**
* 加载ftp文件夹下载地址用于任务停止删除等操作
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -164,13 +163,13 @@ public class DownloadReceiver extends AbsReceiver {
if (set != null && !set.isEmpty()) {
for (Integer type : set) {
if (type == ProxyHelper.PROXY_TYPE_DOWNLOAD) {
DownloadSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD);
TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD);
} else if (type == ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP) {
DownloadGroupSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP);
TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP);
} else if (type == ProxyHelper.PROXY_TYPE_M3U8_PEER) {
DownloadSchedulers.getInstance().register(obj, TaskEnum.M3U8_PEER);
TaskSchedulers.getInstance().register(obj, TaskEnum.M3U8_PEER);
} else if (type == ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP_SUB) {
DownloadGroupSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP_SUB);
TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP_SUB);
}
}
} else {
@ -193,7 +192,7 @@ public class DownloadReceiver extends AbsReceiver {
if (needRmListener) {
unRegisterListener();
}
AriaManager.getInstance(AriaManager.APP).removeReceiver(OBJ_MAP.get(getKey()));
AriaManager.getInstance().removeReceiver(OBJ_MAP.get(getKey()));
}
@Override public String getType() {
@ -214,9 +213,9 @@ public class DownloadReceiver extends AbsReceiver {
if (set != null) {
for (Integer integer : set) {
if (integer == ProxyHelper.PROXY_TYPE_DOWNLOAD) {
DownloadSchedulers.getInstance().unRegister(obj);
TaskSchedulers.getInstance().unRegister(obj);
} else if (integer == ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP) {
DownloadGroupSchedulers.getInstance().unRegister(obj);
TaskSchedulers.getInstance().unRegister(obj);
}
}
}
@ -454,7 +453,7 @@ public class DownloadReceiver extends AbsReceiver {
* 如果文件已经下载完成只删除下载记录
*/
public void removeAllTask(boolean removeFile) {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
final AriaManager ariaManager = AriaManager.getInstance();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.DOWNLOAD);

@ -39,7 +39,7 @@ public class DownloadTask extends AbsNormalTask<DTaskWrapper> {
private DownloadTask(DTaskWrapper taskWrapper, Handler outHandler) {
mTaskWrapper = taskWrapper;
mOutHandler = outHandler;
mContext = AriaManager.APP;
mContext = AriaManager.getInstance().getAPP();
if (taskWrapper.getRequestType() == AbsTaskWrapper.M3U8_VOD
|| taskWrapper.getRequestType() == AbsTaskWrapper.M3U8_LIVE) {
mListener = new M3U8Listener(this, mOutHandler);

@ -17,7 +17,7 @@ package com.arialyy.aria.core.download;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.ITaskWrapper;
@ -26,10 +26,10 @@ import com.arialyy.aria.util.CommonUtil;
/**
* 处理ftp第一次下载等逻辑
*/
public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
private DNormalConfigHandler<FtpStartTarget> mConfigHandler;
public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
private DNormalConfigHandler<FtpBuilderTarget> mConfigHandler;
FtpStartTarget(String url, String targetName) {
FtpBuilderTarget(String url, String targetName) {
mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName);
mConfigHandler.setUrl(url);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url));
@ -40,7 +40,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* 设置登陆字符串编码ftps等参数
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpStartTarget> option() {
public FtpDelegate<FtpBuilderTarget> option() {
return new FtpDelegate<>(this, getTaskWrapper());
}
@ -51,7 +51,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* 2如果保存路径是文件夹路径/mnt/sdcard/则使用FTP服务器该文件的文件名
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpStartTarget setFilePath(@NonNull String filePath) {
public FtpBuilderTarget setFilePath(@NonNull String filePath) {
int lastIndex = mConfigHandler.getUrl().lastIndexOf("/");
getEntity().setFileName(mConfigHandler.getUrl().substring(lastIndex + 1));
mConfigHandler.setTempFilePath(filePath);
@ -67,7 +67,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* @param forceDownload {@code true}强制下载不考虑文件路径是否被占用
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpStartTarget setFilePath(@NonNull String filePath, boolean forceDownload) {
public FtpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) {
mConfigHandler.setTempFilePath(filePath);
mConfigHandler.setForceDownload(forceDownload);
return this;

@ -16,7 +16,7 @@
package com.arialyy.aria.core.download;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.manager.SubTaskManager;
@ -26,10 +26,10 @@ import com.arialyy.aria.util.CommonUtil;
* Created by Aria.Lao on 2017/7/26.
* ftp文件夹下载
*/
public class FtpDirStartTarget extends AbsStartTarget<FtpDirStartTarget> {
private FtpDirConfigHandler<FtpDirStartTarget> mConfigHandler;
public class FtpDirBuilderTarget extends AbsBuilderTarget<FtpDirBuilderTarget> {
private FtpDirConfigHandler<FtpDirBuilderTarget> mConfigHandler;
FtpDirStartTarget(String url, String targetName) {
FtpDirBuilderTarget(String url, String targetName) {
setTargetName(targetName);
mConfigHandler = new FtpDirConfigHandler<>(this, -1);
getEntity().setGroupHash(url);
@ -56,7 +56,7 @@ public class FtpDirStartTarget extends AbsStartTarget<FtpDirStartTarget> {
* @param dirPath 任务组保存文件夹路径
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDirStartTarget setDirPath(String dirPath) {
public FtpDirBuilderTarget setDirPath(String dirPath) {
return mConfigHandler.setDirPath(dirPath);
}
@ -64,7 +64,7 @@ public class FtpDirStartTarget extends AbsStartTarget<FtpDirStartTarget> {
* 设置任务组别名
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDirStartTarget setGroupAlias(String alias) {
public FtpDirBuilderTarget setGroupAlias(String alias) {
mConfigHandler.setGroupAlias(alias);
return this;
}
@ -73,7 +73,7 @@ public class FtpDirStartTarget extends AbsStartTarget<FtpDirStartTarget> {
* 设置登陆字符串编码ftps等参数
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpDirStartTarget> option() {
public FtpDelegate<FtpDirBuilderTarget> option() {
return new FtpDelegate<>(this, getTaskWrapper());
}

@ -16,7 +16,7 @@
package com.arialyy.aria.core.download;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
@ -29,10 +29,10 @@ import java.util.List;
* Created by AriaL on 2017/6/29.
* 下载任务组
*/
public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
private HttpGroupConfigHandler<GroupStartTarget> mConfigHandler;
public class GroupBuilderTarget extends AbsBuilderTarget<GroupBuilderTarget> {
private HttpGroupConfigHandler<GroupBuilderTarget> mConfigHandler;
GroupStartTarget(List<String> urls, String targetName) {
GroupBuilderTarget(List<String> urls, String targetName) {
setTargetName(targetName);
mConfigHandler = new HttpGroupConfigHandler<>(this, -1);
getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP);
@ -43,7 +43,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* 设置http请求参数header等信息
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<GroupStartTarget> option() {
public HttpDelegate<GroupBuilderTarget> option() {
return new HttpDelegate<>(this, getTaskWrapper());
}
@ -56,7 +56,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* @param fileSize 任务组总大小
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget setFileSize(long fileSize) {
public GroupBuilderTarget setFileSize(long fileSize) {
if (fileSize <= 0) {
ALog.e(TAG, "文件大小不能小于 0");
return this;
@ -75,7 +75,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* 3由于网络或其它原因的存在这种方式获取的组合任务大小有可能是不准确的
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget unknownSize() {
public GroupBuilderTarget unknownSize() {
((DGTaskWrapper) getTaskWrapper()).setUnknownSize(true);
return this;
}
@ -96,7 +96,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* @deprecated {@link #setSubFileName(List)} 请使用该api
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
@Deprecated public GroupStartTarget setSubTaskFileName(List<String> subTaskFileName) {
@Deprecated public GroupBuilderTarget setSubTaskFileName(List<String> subTaskFileName) {
return setSubFileName(subTaskFileName);
}
@ -104,7 +104,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* 设置任务组别名
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget setGroupAlias(String alias) {
public GroupBuilderTarget setGroupAlias(String alias) {
mConfigHandler.setGroupAlias(alias);
return this;
}
@ -129,7 +129,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* @param dirPath 任务组保存文件夹路径
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget setDirPath(String dirPath) {
public GroupBuilderTarget setDirPath(String dirPath) {
return mConfigHandler.setDirPath(dirPath);
}
@ -137,7 +137,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* 设置子任务文件名该方法必须在{@link #setDirPath(String)}之后调用否则不生效
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget setSubFileName(List<String> subTaskFileName) {
public GroupBuilderTarget setSubFileName(List<String> subTaskFileName) {
return mConfigHandler.setSubFileName(subTaskFileName);
}
@ -145,7 +145,7 @@ public class GroupStartTarget extends AbsStartTarget<GroupStartTarget> {
* 如果你需要使用header中特定的key来设置文件长度或有定制文件长度的需要那么你可以通过该方法自行处理文件长度
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public GroupStartTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
public GroupBuilderTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");

@ -17,24 +17,24 @@ package com.arialyy.aria.core.download;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskWrapper;
public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
private DNormalConfigHandler<HttpStartTarget> mConfigHandler;
private DNormalConfigHandler<HttpBuilderTarget> mConfigHandler;
HttpStartTarget(String url, String targetName) {
HttpBuilderTarget(String url, String targetName) {
mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName);
getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP);
mConfigHandler.setUrl(url);
}
@CheckResult(suggest = Suggest.TASK_CONTROLLER) public M3U8Delegate<HttpStartTarget> asM3U8() {
@CheckResult(suggest = Suggest.TASK_CONTROLLER) public M3U8Delegate<HttpBuilderTarget> asM3U8() {
return new M3U8Delegate<>(this, getTaskWrapper());
}
@ -42,7 +42,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* 设置http请求参数header等信息
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpStartTarget> option() {
public HttpDelegate<HttpBuilderTarget> option() {
return new HttpDelegate<>(this, getTaskWrapper());
}
@ -53,7 +53,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* @param use {@code true} 使用
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpStartTarget useServerFileName(boolean use) {
public HttpBuilderTarget useServerFileName(boolean use) {
getTaskWrapper().asHttp().setUseServerFileName(use);
return this;
}
@ -66,7 +66,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* @param filePath 路径必须为文件路径不能为文件夹路径
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpStartTarget setFilePath(@NonNull String filePath) {
public HttpBuilderTarget setFilePath(@NonNull String filePath) {
mConfigHandler.setTempFilePath(filePath);
return this;
}
@ -80,7 +80,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* @param forceDownload {@code true}强制下载不考虑文件路径是否被占用
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpStartTarget setFilePath(@NonNull String filePath, boolean forceDownload) {
public HttpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) {
mConfigHandler.setTempFilePath(filePath);
mConfigHandler.setForceDownload(forceDownload);
return this;
@ -90,7 +90,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* 如果你需要使用header中特定的key来设置文件长度或有定制文件长度的需要那么你可以通过该方法自行处理文件长度
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpStartTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
public HttpBuilderTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");
}

@ -109,7 +109,7 @@ public class ConnectionHelp {
urlConn = url.openConnection();
}
if (urlConn instanceof HttpsURLConnection) {
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
AriaManager manager = AriaManager.getInstance();
conn = (HttpsURLConnection) urlConn;
SSLContext sslContext =
SSLContextUtil.getSSLContextFromAssets(manager.getDownloadConfig().getCaName(),

@ -22,7 +22,8 @@ import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
/**
* Created by Aria.Lao on 2017/7/25.
@ -37,7 +38,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DTaskWrapper> {
@Override protected void handleFile(String remotePath, FTPFile ftpFile) {
super.handleFile(remotePath, ftpFile);
if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) {
if (!FileUtil.checkSDMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) {
mCallback.onFail(mEntity, new AriaIOException(TAG,
String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getFilePath())),
false);
@ -49,6 +50,7 @@ class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DTaskWrapper> {
}
@Override protected void onPreComplete(int code) {
ALog.i(TAG, "FTP下载预处理完成");
super.onPreComplete(code);
if (mSize != mTaskWrapper.getEntity().getFileSize()) {
mTaskWrapper.setNewTask(true);

@ -105,13 +105,10 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DTaskWrapper> {
if (is != null) {
is.close();
}
if (client != null && client.isConnected()) {
client.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
closeClient(client);
onThreadComplete();
}
return this;

@ -33,6 +33,7 @@ import com.arialyy.aria.exception.TaskException;
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.BufferedReader;
import java.io.File;
@ -66,7 +67,7 @@ public class HttpFileInfoThread implements Runnable {
this.mTaskWrapper = taskWrapper;
mEntity = taskWrapper.getEntity();
mConnectTimeOut =
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
AriaManager.getInstance().getDownloadConfig().getConnectTimeOut();
onFileInfoCallback = callback;
mTaskDelegate = taskWrapper.asHttp();
}
@ -121,7 +122,7 @@ public class HttpFileInfoThread implements Runnable {
}
long len = lenAdapter.handleFileLen(conn.getHeaderFields());
if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) {
if (!FileUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) {
failDownload(new TaskException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl())), false);

@ -87,7 +87,7 @@ class SimpleSchedulers implements ISchedulers {
boolean isNotNetRetry = config.appCfg.isNotNetRetry();
final int reTryNum = num;
if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry)
if ((!NetUtils.isConnected(AriaManager.getInstance().getAPP()) && !isNotNetRetry)
|| loaderUtil.getDownloader() == null // 如果获取不到文件信息,loader为空
|| loaderUtil.getEntity().getFailNum() > reTryNum) {
mQueue.removeTaskFromExecQ(loaderUtil);

@ -19,8 +19,16 @@ import com.arialyy.aria.core.common.AbsFileer;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
public abstract class BaseM3U8Loader extends AbsFileer<DownloadEntity, DTaskWrapper> {
@ -50,4 +58,62 @@ public abstract class BaseM3U8Loader extends AbsFileer<DownloadEntity, DTaskWrap
}
return cacheDir;
}
/**
* 创建索引文件
*/
boolean generateIndexFile() {
File tempFile = new File(M3U8InfoThread.M3U8_INDEX_FORMAT, getEntity().getFilePath());
if (!tempFile.exists()) {
ALog.e(TAG, "源索引文件不存在");
return false;
}
FileInputStream fis = null;
FileOutputStream fos = null;
try {
String cacheDir = getCacheDir();
fis = new FileInputStream(tempFile);
fos = new FileOutputStream(getEntity().getFilePath());
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line;
int i = 0;
while ((line = reader.readLine()) != null) {
byte[] bytes;
if (line.startsWith("EXTINF")) {
String tsPath = getTsFilePath(cacheDir, mRecord.threadRecords.get(i).threadId);
bytes = tsPath.concat("\r\n").getBytes(Charset.forName("UTF-8"));
i++;
} else if (line.startsWith("EXT-X-KEY")) {
M3U8Entity m3U8Entity = getEntity().getM3U8Entity();
String keyInfo = String.format("#EXT-X-KEY:METHOD=%s,URI=%s,IV=%s\r\n", m3U8Entity.method,
m3U8Entity.keyPath, m3U8Entity.iv);
bytes = keyInfo.getBytes(Charset.forName("UTF-8"));
} else {
bytes = line.getBytes(Charset.forName("UTF-8"));
}
fos.write(bytes, 0, bytes.length);
}
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
if (tempFile.exists()) {
FileUtil.deleteFile(tempFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
}

@ -82,7 +82,7 @@ final class M3U8InfoThread implements Runnable {
this.mTaskWrapper = taskWrapper;
mEntity = taskWrapper.getEntity();
mConnectTimeOut =
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
AriaManager.getInstance().getDownloadConfig().getConnectTimeOut();
onFileInfoCallback = callback;
mTaskDelegate = taskWrapper.asHttp();
mEntity.getM3U8Entity().setLive(mTaskWrapper.getRequestType() == AbsTaskWrapper.M3U8_LIVE);

@ -153,6 +153,9 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
* @return {@code true} 合并成功{@code false}合并失败
*/
public boolean mergeFile() {
if (getEntity().getM3U8Entity().isGenerateIndexFile()) {
return generateIndexFile();
}
ITsMergeHandler mergeHandler = mTaskWrapper.asM3U8().getMergeHandler();
String cacheDir = getCacheDir();
List<String> partPath = new ArrayList<>();

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download.m3u8;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.List;
@ -31,7 +32,7 @@ public class M3U8TaskConfig {
/**
* #EXTINF 标签信息处理器
*/
private WeakReference<IVodTsUrlConverter> vodUrlConverter;
private SoftReference<IVodTsUrlConverter> vodUrlConverter;
/**
* 缓存目录
@ -199,7 +200,7 @@ public class M3U8TaskConfig {
}
public void setVodUrlConverter(IVodTsUrlConverter vodUrlConverter) {
this.vodUrlConverter = new WeakReference<>(vodUrlConverter);
this.vodUrlConverter = new SoftReference<>(vodUrlConverter);
}
public List<String> getUrls() {

@ -110,6 +110,6 @@ public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARG
return;
}
EventMsgUtil.getDefault().post(new PeerIndexEvent(index));
EventMsgUtil.getDefault().post(new PeerIndexEvent(mTaskWrapper.getKey(), index));
}
}

@ -36,14 +36,7 @@ import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
@ -202,7 +195,8 @@ public class M3U8VodLoader extends BaseM3U8Loader {
private void initData() {
mCacheDir = getCacheDir();
if (mTaskWrapper.asM3U8().getJumpIndex() != 0) {
mCurrentEvent = new PeerIndexEvent(mTaskWrapper.asM3U8().getJumpIndex());
mCurrentEvent =
new PeerIndexEvent(mTaskWrapper.getKey(), mTaskWrapper.asM3U8().getJumpIndex());
resumeTask();
return;
}
@ -295,6 +289,9 @@ public class M3U8VodLoader extends BaseM3U8Loader {
*/
@Event
public synchronized void jumpPeer(PeerIndexEvent event) {
if (!event.key.equals(mTaskWrapper.getKey())) {
return;
}
if (isBreak()) {
ALog.e(TAG, "任务已停止,发送跳转事件失败");
return;
@ -655,61 +652,6 @@ public class M3U8VodLoader extends BaseM3U8Loader {
}
}
/**
* 创建索引文件
*/
private boolean generateIndexFile() {
File tempFile = new File(M3U8InfoThread.M3U8_INDEX_FORMAT, getEntity().getFilePath());
if (!tempFile.exists()) {
ALog.e(TAG, "源索引文件不存在");
return false;
}
FileInputStream fis = null;
FileOutputStream fos = null;
try {
String cacheDir = getCacheDir();
fis = new FileInputStream(tempFile);
fos = new FileOutputStream(getEntity().getFilePath());
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line;
int i = 0;
while ((line = reader.readLine()) != null) {
byte[] bytes;
if (line.startsWith("EXTINF")) {
String tsPath = getTsFilePath(cacheDir, mRecord.threadRecords.get(i).threadId);
bytes = tsPath.concat("\r\n").getBytes(Charset.forName("UTF-8"));
i++;
} else if (line.startsWith("EXT-X-KEY")) {
M3U8Entity m3U8Entity = getEntity().getM3U8Entity();
String keyInfo = String.format("#EXT-X-KEY:METHOD=%s,URI=%s,IV=%s\r\n", m3U8Entity.method,
m3U8Entity.keyPath, m3U8Entity.iv);
bytes = keyInfo.getBytes(Charset.forName("UTF-8"));
} else {
bytes = line.getBytes(Charset.forName("UTF-8"));
}
fos.write(bytes, 0, bytes.length);
}
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
private static class TempFlag {
AbsThreadTask threadTask;
int threadId;

@ -19,9 +19,11 @@ public class PeerIndexEvent {
public int peerIndex;
public long createTime;
public String key;
public PeerIndexEvent(int peerIndex) {
public PeerIndexEvent(String key, int peerIndex) {
this.peerIndex = peerIndex;
this.key = key;
createTime = System.currentTimeMillis();
}
}

@ -19,7 +19,7 @@ import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.controller.NormalController;
import com.arialyy.aria.core.common.controller.StartController;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -84,7 +84,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget> {
/**
* 重置状态将任务状态设置为未开始状态
* 注意如果在后续方法调用链中没有调用 {@link NormalController#stop()}{@link NormalController#cancel()}
* {@link NormalController#resume()}{@link StartController#create()}{@link StartController#add()}
* {@link NormalController#resume()}{@link BuilderController#create()}{@link BuilderController#add()}
* 等操作任务的方法那么你需要调用{@link NormalController#save()}才能将修改保存到数据库
*/
@CheckResult(suggest = "after use #create()、#stop()、#cancel()、#resume()、#save()?")

@ -52,6 +52,32 @@ public class ThreadTaskManager {
mExePool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
}
/**
* 删除所有线程任务
*/
public void removeAllThreadTask() {
if (mThreadTasks.isEmpty()) {
return;
}
try {
LOCK.tryLock(2, TimeUnit.SECONDS);
for (Set<FutureContainer> threads : mThreadTasks.values()) {
for (FutureContainer container : threads) {
if (container.future.isDone() || container.future.isCancelled()) {
continue;
}
container.threadTask.destroy();
}
threads.clear();
}
mThreadTasks.clear();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
LOCK.unlock();
}
}
/**
* 启动线程任务
*

@ -112,7 +112,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
}
}
ThreadTaskManager.getInstance().removeAllThreadTask();
mCachePool.clear();
}

@ -19,7 +19,7 @@ package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.util.ALog;
/**
@ -48,7 +48,7 @@ public class DownloadGroupTaskQueue
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().getMaxTaskNum();
return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum();
}
@Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) {
@ -56,7 +56,7 @@ public class DownloadGroupTaskQueue
DownloadGroupTask task = null;
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (DownloadGroupTask) TaskFactory.getInstance()
.createTask(wrapper, DownloadGroupSchedulers.getInstance());
.createTask(wrapper, TaskSchedulers.getInstance());
addTask(task);
} else {
ALog.w(TAG, "任务已存在");
@ -65,6 +65,6 @@ public class DownloadGroupTaskQueue
}
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().oldMaxTaskNum;
return AriaManager.getInstance().getDGroupConfig().oldMaxTaskNum;
}
}

@ -20,7 +20,7 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.util.ALog;
import java.util.LinkedHashSet;
import java.util.Map;
@ -51,7 +51,7 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
}
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
return AriaManager.getInstance().getDownloadConfig().oldMaxTaskNum;
}
/**
@ -72,7 +72,7 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
}
}
}
int maxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
int maxSize = AriaManager.getInstance().getDownloadConfig().getMaxTaskNum();
int currentSize = mExecutePool.size();
if (currentSize == 0 || currentSize < maxSize) {
startTask(task);
@ -102,7 +102,7 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
DownloadTask task = null;
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (DownloadTask) TaskFactory.getInstance()
.createTask(wrapper, DownloadSchedulers.getInstance());
.createTask(wrapper, TaskSchedulers.getInstance());
addTask(task);
} else {
ALog.w(TAG, "任务已存在");
@ -117,6 +117,6 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
return AriaManager.getInstance().getDownloadConfig().getMaxTaskNum();
}
}

@ -22,9 +22,7 @@ import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadTask;
@ -56,7 +54,6 @@ class TaskFactory {
* @param schedulers 对应的任务调度器
* @param <TASK_ENTITY> {@link DTaskWrapper}{@link UTaskWrapper}{@link
* DGTaskWrapper}
* @param <SCHEDULER> {@link DownloadSchedulers}{@link UploadSchedulers}
* @return {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
<TASK_ENTITY extends AbsTaskWrapper, SCHEDULER extends ISchedulers> ITask createTask(

@ -17,7 +17,7 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
@ -46,11 +46,11 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
}
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
return AriaManager.getInstance().getUploadConfig().oldMaxTaskNum;
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
return AriaManager.getInstance().getUploadConfig().getMaxTaskNum();
}
@Override public UploadTask createTask(UTaskWrapper wrapper) {
@ -58,7 +58,7 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
UploadTask task = null;
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (UploadTask) TaskFactory.getInstance()
.createTask(wrapper, UploadSchedulers.getInstance());
.createTask(wrapper, TaskSchedulers.getInstance());
addTask(task);
} else {
ALog.w(TAG, "任务已存在");

@ -26,6 +26,6 @@ class DGLoadExecutePool<TASK extends AbsTask> extends DLoadExecutePool<TASK> {
private final String TAG = "DGLoadExecutePool";
@Override protected int getMaxSize() {
return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().getMaxTaskNum();
return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum();
}
}

@ -30,7 +30,7 @@ class DLoadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
private final String TAG = "DownloadExecutePool";
@Override protected int getMaxSize() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
return AriaManager.getInstance().getDownloadConfig().getMaxTaskNum();
}
@Override public boolean putTask(TASK task) {

@ -23,6 +23,6 @@ import com.arialyy.aria.core.inf.AbsTask;
*/
public class UploadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
@Override protected int getMaxSize() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
return AriaManager.getInstance().getUploadConfig().getMaxTaskNum();
}
}

@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
/**
* Created by AriaL on 2017/7/2.
* 任务组调度器
*/
public class DownloadGroupSchedulers extends
AbsSchedulers<DGTaskWrapper, DownloadGroupTask, DownloadGroupTaskQueue> {
private final String TAG = "DownloadGroupSchedulers";
private static volatile DownloadGroupSchedulers INSTANCE = null;
private DownloadGroupSchedulers() {
super();
mQueue = DownloadGroupTaskQueue.getInstance();
}
public static DownloadGroupSchedulers getInstance() {
if (INSTANCE == null) {
synchronized (DownloadGroupSchedulers.class) {
INSTANCE = new DownloadGroupSchedulers();
}
}
return INSTANCE;
}
}

@ -1,46 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
/**
* Created by lyy on 2016/8/16.
* 任务下载器提供抽象的方法供具体的实现类操作
*/
public class DownloadSchedulers
extends AbsSchedulers<DTaskWrapper, DownloadTask, DownloadTaskQueue> {
private final String TAG = "DownloadSchedulers";
private static volatile DownloadSchedulers INSTANCE = null;
private DownloadSchedulers() {
super();
mQueue = DownloadTaskQueue.getInstance();
}
public static DownloadSchedulers getInstance() {
if (INSTANCE == null) {
synchronized (DownloadSchedulers.class) {
INSTANCE = new DownloadSchedulers();
}
}
return INSTANCE;
}
}

@ -0,0 +1,124 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/**
* 处理失败的任务
*/
class FailureTaskHandler<TASK extends ITask> {
private final String TAG = CommonUtil.getClassName(getClass());
private static volatile FailureTaskHandler INSTANCE;
private final int MAX_EXE_NUM = 5; // 同时处理的失败任务数量
private ArrayBlockingQueue<TASK> mQueue = new ArrayBlockingQueue<>(100);
private List<TASK> mExeQueue = new ArrayList<>(MAX_EXE_NUM);
private List<Integer> mHashList = new ArrayList<>();
private TaskSchedulers mSchedulers;
private final ReentrantLock LOCK = new ReentrantLock();
private Condition mCondition = LOCK.newCondition();
private AriaManager mAriaManager;
static FailureTaskHandler init(TaskSchedulers schedulers) {
if (INSTANCE == null) {
synchronized (FailureTaskHandler.class) {
if (INSTANCE == null) {
INSTANCE = new FailureTaskHandler(schedulers);
}
}
}
return INSTANCE;
}
private FailureTaskHandler(TaskSchedulers schedulers) {
mSchedulers = schedulers;
mAriaManager = AriaManager.getInstance();
new Thread(new Runnable() {
@Override public void run() {
while (true) {
try {
TASK task = mQueue.take();
if (mExeQueue.size() >= MAX_EXE_NUM) {
try {
LOCK.lock();
mCondition.await();
} finally {
LOCK.unlock();
}
} else {
retryTask(task);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
private void retryTask(final TASK task) {
long interval = task.getTaskWrapper().getConfig().getReTryInterval();
final int num = task.getTaskWrapper().getConfig().getReTryNum();
final ITaskQueue queue = mSchedulers.getQueue(task);
mAriaManager.getAriaHandler().postDelayed(new Runnable() {
@Override public void run() {
AbsEntity entity = task.getTaskWrapper().getEntity();
if (entity.getFailNum() <= num) {
ALog.d(TAG, String.format("任务【%s】开始重试", task.getTaskName()));
queue.reTryStart(task);
} else {
queue.removeTaskFormQueue(task.getKey());
mSchedulers.startNextTask(queue, task.getSchedulerType());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getTaskWrapper());
}
mExeQueue.remove(task);
int index = mHashList.indexOf(task.hashCode());
if (index != -1) {
mHashList.remove(index);
}
if (LOCK.isLocked()) {
try {
LOCK.lock();
mCondition.signalAll();
} finally {
LOCK.unlock();
}
}
}
}, interval);
}
void offer(TASK task) {
int hashCode = task.hashCode();
if (mHashList.contains(hashCode)) {
return;
}
mQueue.offer(task);
mHashList.add(hashCode);
}
}

@ -25,13 +25,15 @@ import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.NetUtils;
@ -39,23 +41,52 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Created by lyy on 2017/6/4. 事件调度器用于处理任务状态的调度
*/
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends ITask,
QUEUE extends ITaskQueue<TASK, TASK_ENTITY>> implements ISchedulers {
public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
private final String TAG = "AbsSchedulers";
protected QUEUE mQueue;
private static volatile TaskSchedulers INSTANCE;
private static FailureTaskHandler mFailureTaskHandler;
private Map<String, Map<TaskEnum, ISchedulerListener>> mObservers = new ConcurrentHashMap<>();
private AriaManager manager;
private AriaManager mAriaManager;
AbsSchedulers() {
manager = AriaManager.getInstance(AriaManager.APP);
private TaskSchedulers() {
mAriaManager = AriaManager.getInstance();
}
public static TaskSchedulers getInstance() {
if (INSTANCE == null) {
synchronized (TaskSchedulers.class) {
if (INSTANCE == null) {
INSTANCE = new TaskSchedulers();
mFailureTaskHandler = FailureTaskHandler.init(INSTANCE);
}
}
}
return INSTANCE;
}
/**
* 通过任务类型获取任务队列
*
* @param curTask 当前接收到的的任务
*/
ITaskQueue getQueue(TASK curTask) {
int taskType = curTask.getTaskType();
if (taskType == ITask.DOWNLOAD) {
return DownloadTaskQueue.getInstance();
}
if (taskType == ITask.DOWNLOAD_GROUP) {
return DownloadGroupTaskQueue.getInstance();
}
if (taskType == ITask.UPLOAD) {
return UploadTaskQueue.getInstance();
}
throw new NullPointerException("任务类型错误,type = " + taskType);
}
/**
@ -194,11 +225,11 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
}
}
boolean canSend = manager.getAppConfig().isUseBroadcast();
boolean canSend = mAriaManager.getAppConfig().isUseBroadcast();
if (canSend) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
intent.putExtras(data);
AriaManager.APP.sendBroadcast(intent);
mAriaManager.getAPP().sendBroadcast(intent);
}
return true;
@ -248,9 +279,9 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
}
}
boolean canSend = manager.getAppConfig().isUseBroadcast();
boolean canSend = mAriaManager.getAppConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
mAriaManager.getAPP().sendBroadcast(
createData(msg.what, ITask.DOWNLOAD_GROUP_SUB, params.entity));
}
@ -261,38 +292,39 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
* 处理普通任务和任务组的事件
*/
private void handleNormalEvent(TASK task, int what, int arg1) {
ITaskQueue queue = getQueue(task);
switch (what) {
case STOP:
if (task.getState() == IEntity.STATE_WAIT) {
break;
}
mQueue.removeTaskFormQueue(task.getKey());
if (mQueue.getCurrentExePoolNum() < mQueue.getMaxTaskNum()) {
queue.removeTaskFormQueue(task.getKey());
if (queue.getCurrentExePoolNum() < queue.getMaxTaskNum()) {
ALog.d(TAG, String.format("停止任务【%s】成功,尝试开始下一任务", task.getTaskName()));
startNextTask(task.getSchedulerType());
startNextTask(queue, task.getSchedulerType());
} else {
ALog.d(TAG, String.format("停止任务【%s】成功", task.getTaskName()));
}
break;
case CANCEL:
mQueue.removeTaskFormQueue(task.getKey());
if (mQueue.getCurrentExePoolNum() < mQueue.getMaxTaskNum()) {
queue.removeTaskFormQueue(task.getKey());
if (queue.getCurrentExePoolNum() < queue.getMaxTaskNum()) {
ALog.d(TAG, String.format("删除任务【%s】成功,尝试开始下一任务", task.getTaskName()));
startNextTask(task.getSchedulerType());
startNextTask(queue, task.getSchedulerType());
} else {
ALog.d(TAG, String.format("删除任务【%s】成功", task.getTaskName()));
}
break;
case COMPLETE:
mQueue.removeTaskFormQueue(task.getKey());
queue.removeTaskFormQueue(task.getKey());
ALog.d(TAG, String.format("任务【%s】处理完成", task.getTaskName()));
startNextTask(task.getSchedulerType());
startNextTask(queue, task.getSchedulerType());
break;
case FAIL:
handleFailTask(task);
handleFailTask(queue, task);
break;
case CHECK_FAIL:
handlePreFailTask(arg1);
handlePreFailTask(queue, arg1);
break;
}
@ -310,17 +342,17 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
normalTaskCallback(what, task);
}
private void handlePreFailTask(int taskType) {
startNextTask(TaskSchedulerType.TYPE_DEFAULT);
private void handlePreFailTask(ITaskQueue queue, int taskType) {
startNextTask(queue, TaskSchedulerType.TYPE_DEFAULT);
// 发送广播
boolean canSend = manager.getAppConfig().isUseBroadcast();
boolean canSend = mAriaManager.getAppConfig().isUseBroadcast();
if (canSend) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
Bundle b = new Bundle();
b.putInt(ISchedulers.TASK_TYPE, taskType);
b.putInt(ISchedulers.TASK_STATE, ISchedulers.FAIL);
AriaManager.APP.sendBroadcast(intent);
mAriaManager.getAPP().sendBroadcast(intent);
}
// 处理回调
@ -431,16 +463,16 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
* 发送普通任务的广播
*/
private void sendNormalBroadcast(int state, TASK task) {
boolean canSend = manager.getAppConfig().isUseBroadcast();
boolean canSend = mAriaManager.getAppConfig().isUseBroadcast();
if (!canSend) {
return;
}
int type = task.getTaskType();
if (type == ITask.DOWNLOAD || type == ITask.DOWNLOAD_GROUP) {
AriaManager.APP.sendBroadcast(
mAriaManager.getAPP().sendBroadcast(
createData(state, type, task.getTaskWrapper().getEntity()));
} else if (type == ITask.UPLOAD) {
AriaManager.APP.sendBroadcast(
mAriaManager.getAPP().sendBroadcast(
createData(state, type, task.getTaskWrapper().getEntity()));
} else {
ALog.w(TAG, "发送广播失败,没有对应的任务");
@ -471,61 +503,45 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends IT
*
* @param task 下载任务
*/
private void handleFailTask(final TASK task) {
private void handleFailTask(final ITaskQueue queue, final TASK task) {
if (!task.isNeedRetry() || task.isStop() || task.isCancel()) {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task.getSchedulerType());
queue.removeTaskFormQueue(task.getKey());
startNextTask(queue, task.getSchedulerType());
normalTaskCallback(FAIL, task);
return;
}
long interval = task.getTaskWrapper().getConfig().getReTryInterval();
int num = task.getTaskWrapper().getConfig().getReTryNum();
boolean isNotNetRetry = manager.getAppConfig().isNotNetRetry();
boolean isNotNetRetry = mAriaManager.getAppConfig().isNotNetRetry();
final int reTryNum = num;
if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry)
|| task.getTaskWrapper().getEntity().getFailNum() > reTryNum) {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task.getSchedulerType());
if ((!NetUtils.isConnected(mAriaManager.getAPP()) && !isNotNetRetry)
|| task.getTaskWrapper().getEntity().getFailNum() > num) {
queue.removeTaskFormQueue(task.getKey());
startNextTask(queue, task.getSchedulerType());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getTaskWrapper());
normalTaskCallback(FAIL, task);
return;
}
final ScheduledThreadPoolExecutor timer = new ScheduledThreadPoolExecutor(1);
timer.schedule(new Runnable() {
@Override public void run() {
AbsEntity entity = task.getTaskWrapper().getEntity();
if (entity.getFailNum() <= reTryNum) {
ALog.d(TAG, String.format("任务【%s】开始重试", task.getTaskName()));
TASK task = mQueue.getTask(entity.getKey());
mQueue.reTryStart(task);
} else {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task.getSchedulerType());
TaskWrapperManager.getInstance().removeTaskWrapper(task.getTaskWrapper());
}
}
}, interval, TimeUnit.MILLISECONDS);
mFailureTaskHandler.offer(task);
}
/**
* 启动下一个任务条件任务停止取消下载任务完成
*/
private void startNextTask(int schedulerType) {
void startNextTask(final ITaskQueue queue, int schedulerType) {
if (schedulerType == TaskSchedulerType.TYPE_STOP_NOT_NEXT) {
return;
}
TASK newTask = mQueue.getNextTask();
TASK newTask = (TASK) queue.getNextTask();
if (newTask == null) {
if (mQueue.getCurrentExePoolNum() == 0) {
if (queue.getCurrentExePoolNum() == 0) {
ALog.i(TAG, "没有等待中的任务");
}
return;
}
if (newTask.getState() == IEntity.STATE_WAIT) {
mQueue.startTask(newTask);
queue.startTask(newTask);
}
}
}

@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadTask;
/**
* Created by lyy on 2017/2/27.
* 上传任务调度器
*/
public class UploadSchedulers extends AbsSchedulers<UTaskWrapper, UploadTask, UploadTaskQueue> {
private static final String TAG = "UploadSchedulers";
private static volatile UploadSchedulers INSTANCE = null;
private UploadSchedulers() {
super();
mQueue = UploadTaskQueue.getInstance();
}
public static UploadSchedulers getInstance() {
if (INSTANCE == null) {
synchronized (UploadSchedulers.class) {
INSTANCE = new UploadSchedulers();
}
}
return INSTANCE;
}
}

@ -47,16 +47,6 @@ public class CheckUEntityUtil implements ICheckEntityUtil {
if (b) {
mEntity.save();
}
if (mWrapper.asFtp().getUrlEntity() != null && mWrapper.asFtp().getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
ALog.e(TAG, "证书路径为空");
return false;
}
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().keyAlias)) {
ALog.e(TAG, "证书别名为空");
return false;
}
}
return b;
}
@ -102,17 +92,14 @@ public class CheckUEntityUtil implements ICheckEntityUtil {
}
private boolean checkFtps() {
if (mWrapper.getRequestType() == ITaskWrapper.U_FTP && mWrapper.asFtp()
.getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
ALog.e(TAG, "证书路径为空");
return false;
}
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().keyAlias)) {
ALog.e(TAG, "证书别名为空");
return false;
}
}
//if (mWrapper.getRequestType() == ITaskWrapper.U_FTP && mWrapper.asFtp()
// .getUrlEntity().isFtps) {
// String ftpUrl = mEntity.getUrl();
// if (!ftpUrl.startsWith("ftps") && !ftpUrl.startsWith("sftp")) {
// ALog.e(TAG, String.format("地址【%s】错误,ftps地址开头必须是:ftps或sftp", ftpUrl));
// return false;
// }
//}
return true;
}
}

@ -17,7 +17,7 @@ package com.arialyy.aria.core.upload;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor;
@ -27,10 +27,10 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
* Created by Aria.Lao on 2017/7/27.
* ftp单任务上传
*/
public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
private UNormalConfigHandler<FtpStartTarget> mConfigHandler;
public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
private UNormalConfigHandler<FtpBuilderTarget> mConfigHandler;
FtpStartTarget(String filePath, String targetName) {
FtpBuilderTarget(String filePath, String targetName) {
mConfigHandler = new UNormalConfigHandler<>(this, -1, targetName);
mConfigHandler.setFilePath(filePath);
getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP);
@ -42,7 +42,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* @param tempUrl 上传路径
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpStartTarget setUploadUrl(String tempUrl) {
public FtpBuilderTarget setUploadUrl(String tempUrl) {
mConfigHandler.setTempUrl(tempUrl);
return this;
}
@ -51,7 +51,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* FTP文件上传拦截器如果远端已有同名文件可使用该拦截器控制覆盖文件或修改该文件上传到服务器端端的文件名
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpStartTarget setUploadInterceptor(@NonNull IFtpUploadInterceptor uploadInterceptor) {
public FtpBuilderTarget setUploadInterceptor(@NonNull IFtpUploadInterceptor uploadInterceptor) {
return mConfigHandler.setUploadInterceptor(uploadInterceptor);
}
@ -59,7 +59,7 @@ public class FtpStartTarget extends AbsStartTarget<FtpStartTarget> {
* 设置登陆字符串编码ftps等参数
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpStartTarget> option() {
public FtpDelegate<FtpBuilderTarget> option() {
return new FtpDelegate<>(this, getTaskWrapper());
}
}

@ -16,7 +16,7 @@
package com.arialyy.aria.core.upload;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
@ -25,10 +25,10 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
* Created by lyy on 2017/2/28.
* http 单文件上传
*/
public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
private UNormalConfigHandler<HttpStartTarget> mConfigHandler;
public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
private UNormalConfigHandler<HttpBuilderTarget> mConfigHandler;
HttpStartTarget(String filePath, String targetName) {
HttpBuilderTarget(String filePath, String targetName) {
mConfigHandler = new UNormalConfigHandler<>(this, -1, targetName);
mConfigHandler.setFilePath(filePath);
@ -43,7 +43,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* @param tempUrl 上传路径
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpStartTarget setUploadUrl(String tempUrl) {
public HttpBuilderTarget setUploadUrl(String tempUrl) {
mConfigHandler.setTempUrl(tempUrl);
return this;
}
@ -52,7 +52,7 @@ public class HttpStartTarget extends AbsStartTarget<HttpStartTarget> {
* 设置http请求参数header等信息
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpStartTarget> option() {
public HttpDelegate<HttpBuilderTarget> option() {
return new HttpDelegate<>(this, getTaskWrapper());
}
}

@ -22,14 +22,14 @@ import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CancelAllCmd;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.common.AbsStartTarget;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
@ -52,7 +52,7 @@ public class UploadReceiver extends AbsReceiver {
*/
@Deprecated
public UploadReceiver setMaxSpeed(int maxSpeed) {
AriaManager.getInstance(AriaManager.APP).getUploadConfig().setMaxSpeed(maxSpeed);
AriaManager.getInstance().getUploadConfig().setMaxSpeed(maxSpeed);
return this;
}
@ -62,15 +62,15 @@ public class UploadReceiver extends AbsReceiver {
* @param filePath 文件路径
*/
@CheckResult
public HttpStartTarget load(@NonNull String filePath) {
public HttpBuilderTarget load(@NonNull String filePath) {
CheckUtil.checkUploadPath(filePath);
return new HttpStartTarget(filePath, targetName);
return new HttpBuilderTarget(filePath, targetName);
}
/**
* 用于任务停止删除等操作
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -85,15 +85,15 @@ public class UploadReceiver extends AbsReceiver {
* @param filePath 文件路径
*/
@CheckResult
public FtpStartTarget loadFtp(@NonNull String filePath) {
public FtpBuilderTarget loadFtp(@NonNull String filePath) {
CheckUtil.checkUploadPath(filePath);
return new FtpStartTarget(filePath, targetName);
return new FtpBuilderTarget(filePath, targetName);
}
/**
* 加载FTP单文件上传任务用于任务第一次上传如果需要控制任务停止或删除等操作请使用{@link #load(long)}
*
* @param taskId 任务id可从{@link AbsStartTarget#create()}{@link AbsStartTarget#add()}{@link
* @param taskId 任务id可从{@link AbsBuilderTarget#create()}{@link AbsBuilderTarget#add()}{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@ -226,7 +226,7 @@ public class UploadReceiver extends AbsReceiver {
* 如果文件已经上传完成只删除上传记录
*/
public void removeAllTask(boolean removeFile) {
final AriaManager am = AriaManager.getInstance(AriaManager.APP);
final AriaManager am = AriaManager.getInstance();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.UPLOAD);
@ -256,7 +256,7 @@ public class UploadReceiver extends AbsReceiver {
if (set != null && !set.isEmpty()) {
for (Integer type : set) {
if (type == ProxyHelper.PROXY_TYPE_UPLOAD) {
UploadSchedulers.getInstance().register(obj, TaskEnum.UPLOAD);
TaskSchedulers.getInstance().register(obj, TaskEnum.UPLOAD);
}
}
} else {
@ -272,7 +272,7 @@ public class UploadReceiver extends AbsReceiver {
if (needRmListener) {
unRegisterListener();
}
AriaManager.getInstance(AriaManager.APP).removeReceiver(OBJ_MAP.get(getKey()));
AriaManager.getInstance().removeReceiver(OBJ_MAP.get(getKey()));
}
@Override public String getType() {
@ -294,7 +294,7 @@ public class UploadReceiver extends AbsReceiver {
if (set != null) {
for (Integer integer : set) {
if (integer == ProxyHelper.PROXY_TYPE_UPLOAD) {
UploadSchedulers.getInstance().unRegister(obj);
TaskSchedulers.getInstance().unRegister(obj);
}
}
}

@ -101,12 +101,10 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> {
if (file != null) {
file.close();
}
if (client != null && client.isConnected()) {
client.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
closeClient(client);
onThreadComplete();
}
return this;

@ -25,6 +25,7 @@ import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -36,6 +37,7 @@ import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -65,8 +67,9 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UTaskWrapper> {
}
URL url;
try {
url = new URL(getEntity().getUrl());
HttpTaskConfig taskDelegate = getTaskWrapper().asHttp();
url = new URL(CommonUtil.convertUrl(getConfig().url));
mHttpConn = (HttpURLConnection) url.openConnection();
mHttpConn.setRequestMethod(taskDelegate.getRequestEnum().name);
mHttpConn.setUseCaches(false);
@ -90,11 +93,20 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UTaskWrapper> {
mOutputStream = mHttpConn.getOutputStream();
PrintWriter writer =
new PrintWriter(new OutputStreamWriter(mOutputStream, taskDelegate.getCharSet()), true);
// 添加参数
Map<String, String> params = taskDelegate.getParams();
if (params != null && !params.isEmpty()) {
for (String key : params.keySet()) {
addFormField(writer, key, params.get(key));
}
}
//添加文件上传表单字段
keys = taskDelegate.getFormFields().keySet();
for (String key : keys) {
addFormField(writer, key, taskDelegate.getFormFields().get(key));
}
uploadFile(writer, taskDelegate.getAttachment(), uploadFile);
getEntity().setResponseStr(finish(writer));
sendCompleteMsg();

@ -37,7 +37,7 @@ class Uploader extends NormalFileer<UploadEntity, UTaskWrapper> {
super(listener, taskEntity);
mTempFile = new File(mEntity.getFilePath());
setUpdateInterval(
AriaManager.getInstance(AriaManager.APP).getUploadConfig().getUpdateInterval());
AriaManager.getInstance().getUploadConfig().getUpdateInterval());
}
@Override protected boolean handleNewTask() {

@ -326,7 +326,13 @@ class DelegateFind extends AbsDelegate {
String sql = String.format("SELECT rowid, * FROM %s WHERE %s", CommonUtil.getClassName(clazz),
expression[0]);
String[] params = new String[expression.length - 1];
try {
// 处理系统出现的问题:https://github.com/AriaLyy/Aria/issues/450
System.arraycopy(expression, 1, params, 0, params.length);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return exeNormalDataSql(db, clazz, sql, params);
}
@ -348,7 +354,13 @@ class DelegateFind extends AbsDelegate {
expression[0], (page - 1) * num, num);
String[] params = new String[expression.length - 1];
try {
// 处理系统出现的问题:https://github.com/AriaLyy/Aria/issues/450
System.arraycopy(expression, 1, params, 0, params.length);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return exeNormalDataSql(db, clazz, sql, params);
}

@ -77,6 +77,7 @@ public class CommonUtil {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
if (0 < timeD && timeD < 500) {
ALog.i(TAG, "操作太频繁了,缓一下吧~");
return true;
}
lastClickTime = time;
@ -95,54 +96,6 @@ public class CommonUtil {
return new String(str.getBytes(charSet), SERVER_CHARSET);
}
/**
* 检查SD内存空间是否充足
*
* @param filePath 文件保存路径
* @param fileSize 文件大小
* @return {@code false} 内存空间不足{@code true}内存空间足够
*/
public static boolean checkSDMemorySpace(String filePath, long fileSize) {
List<String> dirs = FileUtil.getSDPathList(AriaManager.APP);
if (dirs == null || dirs.isEmpty()) {
return true;
}
for (String path : dirs) {
if (filePath.contains(path)) {
if (fileSize > 0 && fileSize > getAvailableExternalMemorySize(path)) {
return false;
}
}
}
return true;
}
/**
* sdcard 可用大小
*
* @param sdcardPath sdcard 根路径
* @return 单位为byte
*/
public static long getAvailableExternalMemorySize(String sdcardPath) {
StatFs stat = new StatFs(sdcardPath);
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
/**
* sdcard 总大小
*
* @param sdcardPath sdcard 根路径
* @return 单位为byte
*/
public static long getTotalExternalMemorySize(String sdcardPath) {
StatFs stat = new StatFs(sdcardPath);
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return totalBlocks * blockSize;
}
/**
* 获取某包下所有类
*
@ -818,7 +771,8 @@ public class CommonUtil {
* @param fileName 文件名
*/
public static String getFileConfigPath(boolean isDownload, String fileName) {
return AriaManager.APP.getFilesDir().getPath() + (isDownload ? AriaManager.DOWNLOAD_TEMP_DIR
return AriaManager.getInstance().getAPP().getFilesDir().getPath() + (isDownload
? AriaManager.DOWNLOAD_TEMP_DIR
: AriaManager.UPLOAD_TEMP_DIR) + fileName + ".properties";
}
}

@ -46,7 +46,8 @@ public class ErrorHelp {
* @return "/mnt/sdcard/Android/data/{package_name}/files/log/*"
*/
private static String getLogPath() {
String path = String.format("%slog/AriaCrash_%s.log", CommonUtil.getAppPath(AriaManager.APP),
String path = String.format("%slog/AriaCrash_%s.log",
CommonUtil.getAppPath(AriaManager.getInstance().getAPP()),
getData("yyyy-MM-dd_HH_mm_ss"));
File log = new File(path);

@ -21,7 +21,11 @@ import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -34,13 +38,11 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.SequenceInputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
@ -149,7 +151,16 @@ public class FileUtil {
ALog.e(TAG, "删除文件失败,路径为空");
return false;
}
File file = new File(path);
return deleteFile(new File(path));
}
/**
* 删除文件
*
* @param file 文件路径
* @return {@code true}删除成功{@code false}删除失败
*/
public static boolean deleteFile(File file) {
if (file.exists()) {
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
if (file.renameTo(to)) {
@ -345,6 +356,54 @@ public class FileUtil {
}
}
/**
* 检查SD内存空间是否充足
*
* @param filePath 文件保存路径
* @param fileSize 文件大小
* @return {@code false} 内存空间不足{@code true}内存空间足够
*/
public static boolean checkSDMemorySpace(String filePath, long fileSize) {
List<String> dirs = FileUtil.getSDPathList(AriaManager.getInstance().getAPP());
if (dirs == null || dirs.isEmpty()) {
return true;
}
for (String path : dirs) {
if (filePath.contains(path)) {
if (fileSize > 0 && fileSize > getAvailableExternalMemorySize(path)) {
return false;
}
}
}
return true;
}
/**
* sdcard 可用大小
*
* @param sdcardPath sdcard 根路径
* @return 单位为byte
*/
public static long getAvailableExternalMemorySize(String sdcardPath) {
StatFs stat = new StatFs(sdcardPath);
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
/**
* sdcard 总大小
*
* @param sdcardPath sdcard 根路径
* @return 单位为byte
*/
public static long getTotalExternalMemorySize(String sdcardPath) {
StatFs stat = new StatFs(sdcardPath);
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return totalBlocks * blockSize;
}
/**
* 获取SD卡目录列表
*/
@ -352,11 +411,6 @@ public class FileUtil {
List<String> paths;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
paths = getVolumeList(context);
if (paths == null || paths.isEmpty()) {
paths = getStorageDirectories();
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
paths = getVolumeList(context);
} else {
List<String> mounts = readMountsFile();
List<String> volds = readVoldFile();
@ -417,17 +471,22 @@ public class FileUtil {
* getSDPathList
*/
private static List<String> getVolumeList(final Context context) {
List<String> pathList = null;
try {
android.os.storage.StorageManager manager =
(android.os.storage.StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
Method method = manager.getClass().getMethod("getVolumePaths");
String[] paths = (String[]) method.invoke(manager);
pathList = Arrays.asList(paths);
} catch (Exception e) {
e.printStackTrace();
List<String> pathList = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StorageManager manager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
List<StorageVolume> volumes = manager.getStorageVolumes();
for (StorageVolume volume : volumes) {
String state = volume.getState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
pathList.add(volume.toString());
}
}
if (pathList == null || pathList.isEmpty()) {
} else {
pathList.addAll(getStorageDirectories());
}
if (pathList.isEmpty()) {
pathList = new ArrayList<>();
pathList.add(EXTERNAL_STORAGE_PATH);
}
@ -588,7 +647,7 @@ public class FileUtil {
private static List<String> readVoldFile() {
// read /etc/vold.conf or /etc/vold.fstab (it depends on version what
// config file is present)
// clientConfig file is present)
List<String> vold = null;
Scanner scanner = null;
try {

@ -62,7 +62,7 @@ public class NetUtils {
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return AriaManager.getInstance(context).isConnectedNet();
return AriaManager.getInstance().isConnectedNet();
}
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

@ -67,7 +67,7 @@ public class SSLContextUtil {
if (sslContext != null) {
return sslContext;
}
InputStream caInput = AriaManager.APP.getAssets().open(caPath);
InputStream caInput = AriaManager.getInstance().getAPP().getAssets().open(caPath);
Certificate ca = loadCert(caInput);
return createContext(caAlias, ca, protocol, cacheKey);
} catch (IOException | CertificateException e) {

@ -1,8 +1,16 @@
## 开发日志
+ v_3.7
- fix bug https://github.com/AriaLyy/Aria/issues/450
- fix bug https://github.com/AriaLyy/Aria/issues/466
- fix bug https://github.com/AriaLyy/Aria/issues/454
- 移除隐藏api的反射 https://github.com/AriaLyy/Aria/issues/456
- 新增ftp免证书登陆功能h ttps://github.com/AriaLyy/Aria/issues/455
- 适配androidX
- 修复组合任务,恢复下载,会出现进度显示为0的问题
+ v_3.6.6
- m3u8点播下载新增创建ts索引功能
- 修复多任务的m3u8点播下载时,一个任务调用`jumpIndex`,其它m3u8任务也会自动调用`jumpIndex`的问题
- 添加权限检查
+ v_3.6.6 (2019/8/7)
- fix bug https://github.com/AriaLyy/Aria/issues/426
- fix bug https://github.com/AriaLyy/Aria/issues/429
- fix bug https://github.com/AriaLyy/Aria/issues/428

@ -47,8 +47,8 @@ Aria有以下特点:
[![Compiler](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java
compile 'com.arialyy.aria:aria-core:3.6.5'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.5'
compile 'com.arialyy.aria:aria-core:3.6.6'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.6'
```
如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为
```
@ -67,6 +67,7 @@ __⚠注意:3.5.4以下版本升级时,需要更新[配置文件](https:/
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
```
@ -127,25 +128,15 @@ protected void onCreate(Bundle savedInstanceState) {
### 版本日志
+ v_3.6.5
- fix bug https://github.com/AriaLyy/Aria/issues/403
- fix bug https://github.com/AriaLyy/Aria/issues/414
- fix bug https://github.com/AriaLyy/Aria/issues/406
- fix bug https://github.com/AriaLyy/Aria/issues/407
- fix bug https://github.com/AriaLyy/Aria/issues/416
- fix bug https://github.com/AriaLyy/Aria/issues/420
- fix bug https://github.com/AriaLyy/Aria/issues/422
- 新增ftp上传拦截器 https://github.com/AriaLyy/Aria/issues/402
- 重构线程任务模块
- 新增m3u8协议的文件下载
- 修复拦截器可能出现的空指针问题
- 移除`DownloadGroupEntity`字段`groupHash`的主键约束,`DownloadEntity`字段`groupHash`的外键约束,`TaskRecord`字段`dGroupHash`的外键约束
- 优化关联查询的性能
- 修复任务记录删除失败的问题
- 优化网络连接状态获取的逻辑
- 修复配置文件的某些配置失效的问题
- 新增m3u8切片状态注解`@M3U8.onPeerStart`,`@M3U8.onPeerComplete`,`@M3U8.onPeerFail`
- 新增动态指定m3u8协议视频的下载功能(边下边播下载支持),[详情](https://aria.laoyuyu.me/aria_doc/download/m3u8_vod.html)
+ v_3.6.6
- fix bug https://github.com/AriaLyy/Aria/issues/426
- fix bug https://github.com/AriaLyy/Aria/issues/429
- fix bug https://github.com/AriaLyy/Aria/issues/428
- fix bug https://github.com/AriaLyy/Aria/issues/427
- fix bug https://github.com/AriaLyy/Aria/issues/431
- fix bug https://github.com/AriaLyy/Aria/issues/441
- 修复普通下载任务、组合任务共享执行队列、缓存池的问题
- 修复组合任务启动失败时,`DownloadGroupEntity`的状态变为执行中的问题
[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
@ -32,9 +33,9 @@
<activity android:name=".core.download.DownloadActivity"/>
<activity android:name=".core.download.SingleTaskActivity"/>
<activity android:name=".core.download.multi_download.MultiTaskActivity"/>
<activity android:name=".core.download.fragment_download.FragmentActivity"/>
<activity android:name=".core.download.multi_download.MultiDownloadActivity"/>
<activity android:name=".core.download.mutil.MultiTaskActivity"/>
<activity android:name=".core.download.fragment.FragmentActivity"/>
<activity android:name=".core.download.mutil.MultiDownloadActivity"/>
<activity android:name=".core.download.HighestPriorityActivity"/>
<activity android:name=".core.download.group.DownloadGroupActivity"/>
<activity android:name=".core.download.FtpDownloadActivity"/>
@ -42,6 +43,7 @@
<activity android:name=".core.upload.HttpUploadActivity"/>
<activity android:name=".core.upload.FtpUploadActivity"/>
<activity android:name=".core.download.KotlinDownloadActivity"/>
<activity android:name=".core.download.ComponentActivity"/>
<activity
android:name=".core.FullScreenCodeActivity"
android:screenOrientation="landscape"
@ -50,7 +52,7 @@
<activity android:name=".core.download.m3u8.M3U8VodDLoadActivity"/>
<activity android:name=".core.download.m3u8.M3U8LiveDLoadActivity"/>
<service android:name=".core.download.service_download.DownloadService"/>
<service android:name=".core.download.service.DownloadService"/>
<provider
android:name="androidx.core.content.FileProvider"

@ -21,6 +21,7 @@ import android.os.StrictMode;
import com.arialyy.aria.core.Aria;
import com.arialyy.frame.core.AbsFrame;
import com.arialyy.simple.BuildConfig;
import com.squareup.leakcanary.LeakCanary;
/**
* Created by Lyy on 2016/9/27.
@ -41,12 +42,12 @@ public class BaseApplication extends Application {
// .build());
//StrictMode.setThreadPolicy(
// new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
//if (LeakCanary.isInAnalyzerProcess(this)) {//1
// //This process is dedicated to LeakCanary for heap analysis.
// //You should not init your app in this process.
// return;
//}
//LeakCanary.install(this);
if (LeakCanary.isInAnalyzerProcess(this)) {//1
//This process is dedicated to LeakCanary for heap analysis.
//You should not init your app in this process.
return;
}
LeakCanary.install(this);
}
//registerReceiver(new ConnectionChangeReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

@ -0,0 +1,45 @@
package com.arialyy.simple.common;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;
import com.arialyy.simple.R;
import com.arialyy.simple.base.adapter.AbsHolder;
import com.arialyy.simple.base.adapter.AbsRVAdapter;
import com.arialyy.simple.to.NormalTo;
import java.util.List;
/**
* normalto实体对应的简单适配器
*/
public class NormalToAdapter extends AbsRVAdapter<NormalTo, NormalToAdapter.Holder> {
public NormalToAdapter(Context context, List<NormalTo> data) {
super(context, data);
}
@Override protected NormalToAdapter.Holder getViewHolder(View convertView, int viewType) {
return new NormalToAdapter.Holder(convertView);
}
@Override protected int setLayoutId(int type) {
return R.layout.item_download;
}
@Override protected void bindData(NormalToAdapter.Holder holder, int position, NormalTo item) {
holder.text.setText(item.title);
holder.image.setImageResource(item.icon);
}
class Holder extends AbsHolder {
TextView text;
AppCompatImageView image;
Holder(View itemView) {
super(itemView);
text = findViewById(R.id.title);
image = findViewById(R.id.image);
}
}
}

@ -0,0 +1,78 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.core.download;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.arialyy.simple.MainActivity;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.base.adapter.RvItemClickSupport;
import com.arialyy.simple.common.NormalToAdapter;
import com.arialyy.simple.core.download.fragment.FragmentActivity;
import com.arialyy.simple.databinding.ActivityComponentBinding;
import com.arialyy.simple.modlue.CommonModule;
import com.arialyy.simple.to.NormalTo;
import java.util.ArrayList;
import java.util.List;
public class ComponentActivity extends BaseActivity<ActivityComponentBinding> {
@Override protected int setLayoutId() {
return R.layout.activity_component;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
NormalTo to = getIntent().getParcelableExtra(MainActivity.KEY_MAIN_DATA);
setTitle(to.title);
final List<NormalTo> data = new ArrayList<>();
getBinding().list.setLayoutManager(new GridLayoutManager(this, 2));
final NormalToAdapter adapter = new NormalToAdapter(this, data);
getBinding().list.setAdapter(adapter);
final CommonModule module = ViewModelProviders.of(this).get(CommonModule.class);
module.getComponentData(this).observe(this,
new Observer<List<NormalTo>>() {
@Override public void onChanged(@Nullable List<NormalTo> normalTos) {
if (normalTos != null) {
data.addAll(normalTos);
adapter.notifyDataSetChanged();
}
}
});
RvItemClickSupport.addTo(getBinding().list).setOnItemClickListener(
new RvItemClickSupport.OnItemClickListener() {
@Override public void onItemClicked(RecyclerView recyclerView, int position, View v) {
switch (position) {
case 0:
module.startNextActivity(ComponentActivity.this, data.get(position),
FragmentActivity.class);
break;
case 1:
DownloadDialog dialog = new DownloadDialog(ComponentActivity.this);
dialog.show();
break;
}
}
});
}
}

@ -16,12 +16,9 @@
package com.arialyy.simple.core.download;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.GridLayoutManager;
@ -29,10 +26,9 @@ import androidx.recyclerview.widget.RecyclerView;
import com.arialyy.simple.MainActivity;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.base.adapter.AbsHolder;
import com.arialyy.simple.base.adapter.AbsRVAdapter;
import com.arialyy.simple.base.adapter.RvItemClickSupport;
import com.arialyy.simple.core.download.multi_download.MultiTaskActivity;
import com.arialyy.simple.common.NormalToAdapter;
import com.arialyy.simple.core.download.mutil.MultiTaskActivity;
import com.arialyy.simple.databinding.ActivityDownloadMeanBinding;
import com.arialyy.simple.modlue.CommonModule;
import com.arialyy.simple.to.NormalTo;
@ -56,7 +52,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
final List<NormalTo> data = new ArrayList<>();
getBinding().list.setLayoutManager(new GridLayoutManager(this, 2));
final Adapter adapter = new Adapter(this, data);
final NormalToAdapter adapter = new NormalToAdapter(this, data);
getBinding().list.setAdapter(adapter);
final CommonModule module = ViewModelProviders.of(this).get(CommonModule.class);
@ -91,40 +87,15 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
KotlinDownloadActivity.class);
break;
case 4:
// 服务中
break;
case 5:
// 组件中使用
module.startNextActivity(DownloadActivity.this, data.get(position),
ComponentActivity.class);
break;
}
}
});
}
private static class Adapter extends AbsRVAdapter<NormalTo, Adapter.Holder> {
Adapter(Context context, List<NormalTo> data) {
super(context, data);
}
@Override protected Adapter.Holder getViewHolder(View convertView, int viewType) {
return new Adapter.Holder(convertView);
}
@Override protected int setLayoutId(int type) {
return R.layout.item_download;
}
@Override protected void bindData(Adapter.Holder holder, int position, NormalTo item) {
holder.text.setText(item.title);
holder.image.setImageResource(item.icon);
}
private static class Holder extends AbsHolder {
TextView text;
AppCompatImageView image;
Holder(View itemView) {
super(itemView);
text = findViewById(R.id.title);
image = findViewById(R.id.image);
}
}
}
}

@ -42,7 +42,7 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
private long mTaskId = -1;
private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/4b/d7/e04b308d9cd7f0ad4cac18d1a514544c.apk";
"http://sdkdown.muzhiwan.com/openfile/2019/07/12/com.nswj.acing.mzw_5d283abee9a3c.apk";
public DownloadDialog(Context context) {
super(context);
@ -82,7 +82,7 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
if (mTaskId == -1) {
mTaskId = Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/女神危机.apk")
.create();
mStart.setText(getContext().getString(R.string.stop));
break;

@ -23,7 +23,7 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseModule;
import com.arialyy.simple.core.download.multi_download.FileListEntity;
import com.arialyy.simple.core.download.mutil.FileListEntity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;

@ -94,8 +94,9 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
mTaskId = Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath, true)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER)
.login("lao", "123456")
.asFtps()
.controller(ControllerType.CREATE_CONTROLLER)
.create();
getBinding().setStateStr(getString(R.string.stop));
break;
@ -107,8 +108,9 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
Aria.download(this)
.loadFtp(mTaskId)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.NORMAL_CONTROLLER)
.login("lao", "123456")
.asFtps()
.controller(ControllerType.TASK_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop));
}

@ -33,7 +33,7 @@ public class FtpDownloadModule extends BaseViewModule {
private final String FTP_URL_KEY = "FTP_URL_KEY";
private final String FTP_PATH_KEY = "FTP_PATH_KEY";
private final String ftpDefUrl = "ftp://9.9.9.205:2121/Cyberduck-6.9.4.30164.zip";
private final String ftpDefUrl = "ftp://9.9.9.50:2121/Cyberduck-6.9.4.30164.zip";
private final String ftpDefPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();

@ -32,7 +32,7 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.core.download.multi_download.DownloadAdapter;
import com.arialyy.simple.core.download.mutil.DownloadAdapter;
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;

@ -33,7 +33,7 @@ public class HttpDownloadModule extends BaseViewModule {
private final String HTTP_PATH_KEY = "HTTP_PATH_KEY";
private final String defUrl =
"http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk";
"http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk1";
//"http://9.9.9.205:5000/download/Cyberduck-6.9.4.30164.zip";
//"http://202.98.201.103:7000/vrs/TPK/ZTC440402001Z.tpk";
private final String defFilePath =

@ -93,7 +93,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
.get(HttpDownloadModule::class.java)
mModule!!.getHttpDownloadInfo(this)
.observe(this, Observer { entity ->
if (entity == null) {
if (entity == null || entity.id < 0) {
return@Observer
}
if (entity.state == IEntity.STATE_STOP) {

@ -305,7 +305,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
})
.option()
.addHeader("1", "@")
.controller(ControllerType.START_CONTROLLER)
.controller(ControllerType.CREATE_CONTROLLER)
.create();
}

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.fragment_download;
package com.arialyy.simple.core.download.fragment;
import android.os.Bundle;
import android.os.Environment;
@ -41,6 +41,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding>
private static final String DOWNLOAD_URL =
"https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
private static final String FILE_NAME = "王者军团";
@Override protected void init(Bundle savedInstanceState) {
mStart = mRootView.findViewById(R.id.start);
@ -51,7 +52,6 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding>
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
if (entity != null) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
int state = entity.getState();
getBinding().setProgress(entity.getPercent());
if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop));
@ -62,6 +62,8 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding>
} else {
getBinding().setStateStr(getString(R.string.start));
}
getBinding().setUrl(DOWNLOAD_URL);
getBinding().setFileName(FILE_NAME);
Aria.download(this).register();
}
@ -71,7 +73,9 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding>
if (mTaskId == -1) {
mTaskId = Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
.setFilePath(
Environment.getExternalStorageDirectory().getPath() + String.format("%s.apk",
FILE_NAME))
.create();
getBinding().setStateStr(getString(R.string.stop));
break;

@ -14,13 +14,15 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.fragment_download;
package com.arialyy.simple.core.download.fragment;
import android.os.Bundle;
import com.arialyy.aria.core.Aria;
import com.arialyy.simple.MainActivity;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.FragmentDownloadBinding;
import com.arialyy.simple.to.NormalTo;
/**
* Created by lyy on 2017/1/4.
@ -33,7 +35,9 @@ public class FragmentActivity extends BaseActivity<FragmentDownloadBinding> {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTile("Fragment 中使用");
final NormalTo to = getIntent().getParcelableExtra(MainActivity.KEY_MAIN_DATA);
setTitle(to.title);
Aria.download(this).register();
}
}

@ -79,7 +79,7 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
.setGroupAlias("ftp文件夹下载")
.option()
.login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER)
.controller(ControllerType.CREATE_CONTROLLER)
.create();
getBinding().setStateStr(getString(R.string.stop));
break;
@ -92,7 +92,7 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
.loadFtpDir(mTaskId)
.option()
.login("8L8e", "8guD")
.controller(ControllerType.NORMAL_CONTROLLER)
.controller(ControllerType.TASK_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop));
}

@ -250,7 +250,7 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
return parentUrl + tsUrl;
}
})
.controller(ControllerType.START_CONTROLLER)
.controller(ControllerType.CREATE_CONTROLLER)
//.setLiveTsUrlConvert(new IVodTsUrlConverter() {
// @Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
// int peerIndex = m3u8Url.lastIndexOf("/");

@ -30,7 +30,7 @@ import com.arialyy.annotations.Download;
import com.arialyy.annotations.M3U8;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.common.controller.StartController;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.m3u8.IBandWidthUrlConverter;
@ -299,7 +299,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
return newUrls;
}
})
.controller(ControllerType.NORMAL_CONTROLLER)
.controller(ControllerType.TASK_CONTROLLER)
.resume();
}
break;
@ -341,11 +341,11 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
}
})
.generateIndexFile()
.controller(ControllerType.START_CONTROLLER)
.controller(ControllerType.CREATE_CONTROLLER)
.create();
}
private Class<StartController> c = StartController.class;
private Class<BuilderController> c = BuilderController.class;
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);

@ -59,7 +59,7 @@ public class VideoPlayerFragment extends BaseFragment<FragmentVideoPlayerBinding
getBinding().surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override public void surfaceCreated(SurfaceHolder holder) {
mSurfaceHolder = holder;
//startNewPlayer(mPlayers.valueAt(0));
startNewPlayer(mPlayers.valueAt(0));
}
@Override

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.annotation.SuppressLint;
import android.content.Context;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.annotation.SuppressLint;
import android.os.Bundle;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.content.Context;
import android.view.View;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
/**
* Created by AriaL on 2017/1/6.

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.os.Bundle;
import android.util.Log;

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.content.Context;
import com.arialyy.simple.base.BaseModule;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.multi_download;
package com.arialyy.simple.core.download.mutil;
import android.content.Intent;
import android.os.Bundle;

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.arialyy.simple.core.download.service_download;
package com.arialyy.simple.core.download.service;
import android.app.NotificationManager;
import android.content.Context;

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.core.download.service_download;
package com.arialyy.simple.core.download.service;
import android.app.Service;
import android.content.Intent;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save