From 669aa6981c56f47fa38e402b095818f5c6c1ce9d Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 2 Dec 2019 19:31:39 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20https://github.com/AriaLyy/Aria/iss?= =?UTF-8?q?ues/543#issuecomment-559733124=20fix=20bug=20https://github.com?= =?UTF-8?q?/AriaLyy/Aria/issues/542=20fix=20bug=20https://github.com/AriaL?= =?UTF-8?q?yy/Aria/issues/547=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=EF=BC=8C=E4=B8=AD=E6=96=AD=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BF=BD=E7=95=A5=E6=9D=83=E9=99=90=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=9A=84api=EF=BC=8C`ignoreCheckPermissions()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 10 -- .../aria/core/command/HighestPriorityCmd.java | 3 +- .../aria/core/command/ResumeAllCmd.java | 4 +- .../arialyy/aria/core/command/StartCmd.java | 15 +-- .../aria/core/common/AbsBuilderTarget.java | 10 +- .../aria/core/common/AbsNormalTarget.java | 8 ++ .../common/controller/FeatureController.java | 29 ++++-- .../aria/core/download/CheckDEntityUtil.java | 4 +- .../aria/core/download/DownloadReceiver.java | 5 +- .../aria/core/queue/DGroupTaskQueue.java | 8 +- .../arialyy/aria/core/queue/DTaskQueue.java | 10 +- .../arialyy/aria/core/queue/UTaskQueue.java | 5 +- .../core/queue/pool/DGLoadExecutePool.java | 3 +- .../core/queue/pool/DLoadExecutePool.java | 4 +- .../core/queue/pool/UploadExecutePool.java | 4 +- .../core/scheduler/FailureTaskHandler.java | 67 +++++++------ .../aria/core/scheduler/TaskSchedulers.java | 28 +++--- .../aria/core/upload/UploadReceiver.java | 3 +- DEV_LOG.md | 6 ++ .../ftp/upload/FtpUThreadTaskAdapter.java | 10 +- .../com/arialyy/aria/m3u8/BaseM3U8Loader.java | 4 + .../arialyy/aria/m3u8/M3U8RecordAdapter.java | 3 +- .../com/arialyy/aria/core/AriaConfig.java | 10 ++ .../aria/core/listener/UploadListener.java | 55 ----------- .../aria/core/loader/ThreadStateManager.java | 2 +- .../arialyy/aria/core/task/ThreadTask.java | 17 ++-- .../java/com/arialyy/aria/orm/DBConfig.java | 4 +- .../com/arialyy/aria/orm/DelegateCommon.java | 18 ++++ .../java/com/arialyy/aria/orm/SqlHelper.java | 91 ++++++++++-------- .../java/com/arialyy/aria/util/CheckUtil.java | 2 +- .../java/com/arialyy/aria/util/FileUtil.java | 45 ++++++++- .../core/download/HttpDownloadModule.java | 11 ++- .../core/download/SingleTaskActivity.java | 8 +- .../simple/core/upload/UploadModule.java | 4 +- build.gradle | 4 +- py/.vscode/launch.json | 15 --- py/.vscode/settings.json | 6 -- test/347/AndroidAria.db | Bin 0 -> 73728 bytes 38 files changed, 294 insertions(+), 241 deletions(-) delete mode 100644 PublicComponent/src/main/java/com/arialyy/aria/core/listener/UploadListener.java delete mode 100644 py/.vscode/launch.json delete mode 100644 py/.vscode/settings.json create mode 100644 test/347/AndroidAria.db diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 8a883124..0d0c2f4a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -23,8 +23,6 @@ import android.app.Dialog; import android.content.Context; import android.os.Build; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; import android.widget.PopupWindow; import com.arialyy.aria.core.command.CommandManager; import com.arialyy.aria.core.common.QueueMod; @@ -76,7 +74,6 @@ import java.util.concurrent.ConcurrentHashMap; */ private Map> mSubClass = new ConcurrentHashMap<>(); private static Context APP; - private Handler mAriaHandler; private DelegateWrapper mDbWrapper; private AriaConfig mConfig; @@ -168,13 +165,6 @@ import java.util.concurrent.ConcurrentHashMap; } } - public synchronized Handler getAriaHandler() { - if (mAriaHandler == null) { - mAriaHandler = new Handler(Looper.getMainLooper()); - } - return mAriaHandler; - } - public Map getReceiver() { return mReceivers; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java index 692d083c..d2d8b228 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.command; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; @@ -41,7 +42,7 @@ final class HighestPriorityCmd extends AbsNormalCmd @Override public void executeCmd() { if (!canExeCmd) return; - if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())){ + if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())){ ALog.e(TAG, "启动任务失败,网络未连接"); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java index 71b07041..4e81b18a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java @@ -15,7 +15,7 @@ */ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.ALog; @@ -36,7 +36,7 @@ final class ResumeAllCmd extends AbsNormalCmd { } @Override public void executeCmd() { - if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) { + if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())) { ALog.w(TAG, "恢复任务失败,网络未连接"); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java index 4e0e3661..f6b7cc2c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java @@ -16,7 +16,7 @@ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.task.AbsTask; @@ -37,6 +37,7 @@ final public class StartCmd extends AbsNormalCmd { /** * 立即执行任务 + * * @param newStart true 立即执行任务,无论执行队列是否满了 */ public void setNewStart(boolean newStart) { @@ -45,17 +46,17 @@ final public class StartCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; - if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) { + if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP())) { ALog.e(TAG, "启动任务失败,网络未连接"); return; } String mod; int maxTaskNum = mQueue.getMaxTaskNum(); - AriaManager manager = AriaManager.getInstance(); + AriaConfig config = AriaConfig.getInstance(); if (isDownloadCmd) { - mod = manager.getDownloadConfig().getQueueMod(); + mod = config.getDConfig().getQueueMod(); } else { - mod = manager.getUploadConfig().getQueueMod(); + mod = config.getUConfig().getQueueMod(); } AbsTask task = getTask(); @@ -81,9 +82,9 @@ final public class StartCmd extends AbsNormalCmd { startTask(); } } else { - if (newStart){ + if (newStart) { startTask(); - }else { + } else { sendWaitState(task); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java index c130894b..4ce228e3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java @@ -15,8 +15,8 @@ */ package com.arialyy.aria.core.common; -import com.arialyy.aria.core.common.controller.IStartFeature; import com.arialyy.aria.core.common.controller.BuilderController; +import com.arialyy.aria.core.common.controller.IStartFeature; import com.arialyy.aria.core.inf.AbsTarget; /** @@ -34,6 +34,14 @@ public abstract class AbsBuilderTarget extends return mStartController; } + /** + * 是否忽略权限检查 + */ + public TARGET ignoreCheckPermissions() { + getController().ignoreCheckPermissions(); + return (TARGET) this; + } + /** * 添加任务 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java index b8572a54..71a6c789 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java @@ -31,6 +31,14 @@ import com.arialyy.aria.util.RecordUtil; public abstract class AbsNormalTarget extends AbsTarget implements INormalFeature { + /** + * 是否忽略权限检查 + */ + public TARGET ignoreCheckPermissions() { + getController().ignoreCheckPermissions(); + return (TARGET) this; + } + /** * 任务是否在执行 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java index d3bbca51..1ceab180 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java @@ -19,21 +19,21 @@ 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.AriaConfig; +import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.download.CheckDEntityUtil; import com.arialyy.aria.core.download.CheckDGEntityUtil; import com.arialyy.aria.core.download.CheckFtpDirEntityUtil; import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper; -import com.arialyy.aria.core.common.AbsEntity; -import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.inf.ICheckEntityUtil; -import com.arialyy.aria.core.task.ITask; -import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.scheduler.TaskSchedulers; +import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.upload.CheckUEntityUtil; import com.arialyy.aria.core.upload.UTaskWrapper; +import com.arialyy.aria.core.wrapper.AbsTaskWrapper; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.Constructor; @@ -46,6 +46,10 @@ public abstract class FeatureController { private final String TAG; private AbsTaskWrapper mTaskWrapper; + /** + * 是否忽略权限检查 true 忽略权限检查 + */ + private boolean ignoreCheckPermissions = false; FeatureController(AbsTaskWrapper wrapper) { mTaskWrapper = wrapper; @@ -87,6 +91,13 @@ public abstract class FeatureController { return null; } + /** + * 是否忽略权限检查 + */ + public void ignoreCheckPermissions() { + this.ignoreCheckPermissions = true; + } + protected AbsTaskWrapper getTaskWrapper() { return mTaskWrapper; } @@ -111,7 +122,7 @@ public abstract class FeatureController { * 如果检查实体失败,将错误回调 */ boolean checkConfig() { - if (!checkPermission()) { + if (!ignoreCheckPermissions && !checkPermission()) { return false; } boolean b = checkEntity(); @@ -134,21 +145,21 @@ public abstract class FeatureController { */ private boolean checkPermission() { - if (AriaManager.getInstance() + if (AriaConfig.getInstance() .getAPP() .checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.WRITE_EXTERNAL_STORAGE"); return false; } - if (AriaManager.getInstance() + if (AriaConfig.getInstance() .getAPP() .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { ALog.e(TAG, "启动失败,缺少权限:Manifest.permission.INTERNET"); return false; } - if (AriaManager.getInstance() + if (AriaConfig.getInstance() .getAPP() .checkCallingOrSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java index 3f7e149c..c6eb5dcf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java @@ -23,6 +23,7 @@ import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; +import com.arialyy.aria.util.FileUtil; import com.arialyy.aria.util.RecordUtil; import java.io.File; @@ -65,8 +66,7 @@ public class CheckDEntityUtil implements ICheckEntityUtil { File file = new File(mWrapper.getTempFilePath()); Object bw = mWrapper.getM3U8Params().getParam(IOptionConstant.bandWidth); int bandWidth = bw == null ? 0 : (int) bw; - // 缓存文件夹格式:问文件夹/.文件名_码率 - String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(), bandWidth); + String cacheDir = FileUtil.getTsCacheDir(file.getPath(), bandWidth); mWrapper.getM3U8Params().setParams(IOptionConstant.cacheDir, cacheDir); M3U8Entity m3U8Entity = mEntity.getM3U8Entity(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 4f91b0db..cbb6c5e8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core.download; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.annotations.TaskEnum; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.CancelAllCmd; import com.arialyy.aria.core.command.CmdHelper; @@ -64,7 +65,7 @@ public class DownloadReceiver extends AbsReceiver { */ @Deprecated public DownloadReceiver setMaxSpeed(int maxSpeed) { - AriaManager.getInstance().getDownloadConfig().setMaxSpeed(maxSpeed); + AriaConfig.getInstance().getDConfig().setMaxSpeed(maxSpeed); return this; } @@ -287,7 +288,7 @@ public class DownloadReceiver extends AbsReceiver { * @return 如果实体不存在,返回null */ public DownloadGroupEntity getGroupEntity(List urls) { - if (CheckUtil.checkDownloadUrlsIsEmpty(urls)){ + if (CheckUtil.checkDownloadUrlsIsEmpty(urls)) { return null; } return DbDataHelper.getDGEntity(CommonUtil.getMd5Code(urls)); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java index ce59202b..fe2829d7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java @@ -16,13 +16,13 @@ package com.arialyy.aria.core.queue; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.download.DGTaskWrapper; -import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.event.DGMaxNumEvent; import com.arialyy.aria.core.event.Event; import com.arialyy.aria.core.event.EventMsgUtil; import com.arialyy.aria.core.scheduler.TaskSchedulers; +import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.util.ALog; /** @@ -57,7 +57,7 @@ public class DGroupTaskQueue } @Override public int getMaxTaskNum() { - return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getDConfig().getMaxTaskNum(); } @Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) { @@ -74,6 +74,6 @@ public class DGroupTaskQueue } @Override public int getOldMaxNum() { - return AriaManager.getInstance().getDGroupConfig().oldMaxTaskNum; + return AriaConfig.getInstance().getDGConfig().oldMaxTaskNum; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java index eb552fad..ae0ee5bc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java @@ -16,14 +16,14 @@ package com.arialyy.aria.core.queue; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.download.DTaskWrapper; -import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.event.DMaxNumEvent; import com.arialyy.aria.core.event.Event; import com.arialyy.aria.core.event.EventMsgUtil; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.scheduler.TaskSchedulers; +import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.util.ALog; import java.util.LinkedHashSet; import java.util.Map; @@ -60,7 +60,7 @@ public class DTaskQueue extends AbsTaskQueue { } @Override public int getOldMaxNum() { - return AriaManager.getInstance().getDownloadConfig().oldMaxTaskNum; + return AriaConfig.getInstance().getDConfig().oldMaxTaskNum; } /** @@ -81,7 +81,7 @@ public class DTaskQueue extends AbsTaskQueue { } } } - int maxSize = AriaManager.getInstance().getDownloadConfig().getMaxTaskNum(); + int maxSize = AriaConfig.getInstance().getDConfig().getMaxTaskNum(); int currentSize = mExecutePool.size(); if (currentSize == 0 || currentSize < maxSize) { startTask(task); @@ -126,6 +126,6 @@ public class DTaskQueue extends AbsTaskQueue { } @Override public int getMaxTaskNum() { - return AriaManager.getInstance().getDownloadConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getDConfig().getMaxTaskNum(); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java index 026096ec..cbf15f7c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.queue; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.event.Event; import com.arialyy.aria.core.event.EventMsgUtil; @@ -55,11 +56,11 @@ public class UTaskQueue extends AbsTaskQueue { } @Override public int getOldMaxNum() { - return AriaManager.getInstance().getUploadConfig().oldMaxTaskNum; + return AriaConfig.getInstance().getUConfig().oldMaxTaskNum; } @Override public int getMaxTaskNum() { - return AriaManager.getInstance().getUploadConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getUConfig().getMaxTaskNum(); } @Override public UploadTask createTask(UTaskWrapper wrapper) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java index 5a494822..099c1002 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.queue.pool; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.task.AbsTask; @@ -26,6 +27,6 @@ class DGLoadExecutePool extends DLoadExecutePool { private final String TAG = "DGLoadExecutePool"; @Override protected int getMaxSize() { - return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getDGConfig().getMaxTaskNum(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java index be863d4e..d8db105f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java @@ -15,7 +15,7 @@ */ package com.arialyy.aria.core.queue.pool; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.task.AbsTask; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -30,7 +30,7 @@ class DLoadExecutePool extends BaseExecutePool { private final String TAG = "DownloadExecutePool"; @Override protected int getMaxSize() { - return AriaManager.getInstance().getDownloadConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getDConfig().getMaxTaskNum(); } @Override public boolean putTask(TASK task) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java index ae31ef4b..c8af2622 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java @@ -15,7 +15,7 @@ */ package com.arialyy.aria.core.queue.pool; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.task.AbsTask; /** @@ -23,6 +23,6 @@ import com.arialyy.aria.core.task.AbsTask; */ public class UploadExecutePool extends BaseExecutePool { @Override protected int getMaxSize() { - return AriaManager.getInstance().getUploadConfig().getMaxTaskNum(); + return AriaConfig.getInstance().getUConfig().getMaxTaskNum(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java index 1988cba7..a578d951 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java @@ -15,11 +15,11 @@ */ package com.arialyy.aria.core.scheduler; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.common.AbsEntity; -import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.queue.ITaskQueue; +import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.ArrayList; @@ -42,7 +42,6 @@ class FailureTaskHandler { 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) { @@ -57,7 +56,6 @@ class FailureTaskHandler { private FailureTaskHandler(TaskSchedulers schedulers) { mSchedulers = schedulers; - mAriaManager = AriaManager.getInstance(); new Thread(new Runnable() { @Override public void run() { while (true) { @@ -82,35 +80,46 @@ class FailureTaskHandler { } 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.getTaskType()); - 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(); + if (task.isNeedRetry()){ + long interval = task.getTaskWrapper().getConfig().getReTryInterval(); + final int num = task.getTaskWrapper().getConfig().getReTryNum(); + AriaConfig.getInstance().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()); } + next(task); } + }, interval); + }else { + queue.removeTaskFormQueue(task.getKey()); + mSchedulers.startNextTask(queue, task.getSchedulerType()); + TaskWrapperManager.getInstance().removeTaskWrapper(task.getTaskWrapper()); + next(task); + } + } + + private void next(TASK task){ + 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) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java index 7ba7fad0..ad5bdb4c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java @@ -19,7 +19,7 @@ import android.content.Intent; import android.os.Bundle; import android.os.Message; import com.arialyy.annotations.TaskEnum; -import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsNormalEntity; import com.arialyy.aria.core.group.GroupSendParams; @@ -53,10 +53,10 @@ public class TaskSchedulers implements ISchedulers { private static FailureTaskHandler mFailureTaskHandler; private Map> mObservers = new ConcurrentHashMap<>(); - private AriaManager mAriaManager; + private AriaConfig mAriaConfig; private TaskSchedulers() { - mAriaManager = AriaManager.getInstance(); + mAriaConfig = AriaConfig.getInstance(); } public static TaskSchedulers getInstance() { @@ -230,11 +230,11 @@ public class TaskSchedulers implements ISchedulers { } } - boolean canSend = mAriaManager.getAppConfig().isUseBroadcast(); + boolean canSend = mAriaConfig.getAConfig().isUseBroadcast(); if (canSend) { Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION); intent.putExtras(data); - mAriaManager.getAPP().sendBroadcast(intent); + mAriaConfig.getAPP().sendBroadcast(intent); } return true; @@ -284,9 +284,9 @@ public class TaskSchedulers implements ISchedulers { } } - boolean canSend = mAriaManager.getAppConfig().isUseBroadcast(); + boolean canSend = mAriaConfig.getAConfig().isUseBroadcast(); if (canSend) { - mAriaManager.getAPP().sendBroadcast( + mAriaConfig.getAPP().sendBroadcast( createData(msg.what, ITask.DOWNLOAD_GROUP_SUB, params.entity)); } @@ -353,13 +353,13 @@ public class TaskSchedulers implements ISchedulers { startNextTask(getQueue(taskType), TaskSchedulerType.TYPE_DEFAULT); // 发送广播 - boolean canSend = mAriaManager.getAppConfig().isUseBroadcast(); + boolean canSend = mAriaConfig.getAConfig().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); - mAriaManager.getAPP().sendBroadcast(intent); + mAriaConfig.getAPP().sendBroadcast(intent); } // 处理回调 @@ -470,16 +470,16 @@ public class TaskSchedulers implements ISchedulers { * 发送普通任务的广播 */ private void sendNormalBroadcast(int state, TASK task) { - boolean canSend = mAriaManager.getAppConfig().isUseBroadcast(); + boolean canSend = mAriaConfig.getAConfig().isUseBroadcast(); if (!canSend) { return; } int type = task.getTaskType(); if (type == ITask.DOWNLOAD || type == ITask.DOWNLOAD_GROUP) { - mAriaManager.getAPP().sendBroadcast( + mAriaConfig.getAPP().sendBroadcast( createData(state, type, task.getTaskWrapper().getEntity())); } else if (type == ITask.UPLOAD) { - mAriaManager.getAPP().sendBroadcast( + mAriaConfig.getAPP().sendBroadcast( createData(state, type, task.getTaskWrapper().getEntity())); } else { ALog.w(TAG, "发送广播失败,没有对应的任务"); @@ -519,9 +519,9 @@ public class TaskSchedulers implements ISchedulers { } int num = task.getTaskWrapper().getConfig().getReTryNum(); - boolean isNotNetRetry = mAriaManager.getAppConfig().isNotNetRetry(); + boolean isNotNetRetry = mAriaConfig.getAConfig().isNotNetRetry(); - if ((!NetUtils.isConnected(mAriaManager.getAPP()) && !isNotNetRetry) + if ((!NetUtils.isConnected(mAriaConfig.getAPP()) && !isNotNetRetry) || task.getTaskWrapper().getEntity().getFailNum() > num) { queue.removeTaskFormQueue(task.getKey()); startNextTask(queue, task.getSchedulerType()); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index fc119c45..e3f7467f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -19,6 +19,7 @@ import android.text.TextUtils; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.annotations.TaskEnum; +import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.CancelAllCmd; import com.arialyy.aria.core.command.CmdHelper; @@ -58,7 +59,7 @@ public class UploadReceiver extends AbsReceiver { */ @Deprecated public UploadReceiver setMaxSpeed(int maxSpeed) { - AriaManager.getInstance().getUploadConfig().setMaxSpeed(maxSpeed); + AriaConfig.getInstance().getUConfig().setMaxSpeed(maxSpeed); return this; } diff --git a/DEV_LOG.md b/DEV_LOG.md index 8e1e05b5..be51081d 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,10 @@ ## 开发日志 + + v_3.7.10 + - fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124 + - fix bug https://github.com/AriaLyy/Aria/issues/542 + - fix bug https://github.com/AriaLyy/Aria/issues/547 + - 修复下载失败时,中断重试无效的问题 + - 增加忽略权限检查的api,`ignoreCheckPermissions()` + v_3.7.9 (2019/11/28) - fix bug https://github.com/AriaLyy/Aria/issues/537 + v_3.7.8 (2019/11/28) diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java index 1f1a7ce0..891170ac 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java @@ -33,7 +33,6 @@ import java.io.UnsupportedEncodingException; * Created by Aria.Lao on 2017/7/28. D_FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 */ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { - private final String TAG = "FtpThreadTask"; private String dir, remotePath; FtpUThreadTaskAdapter(SubThreadConfig config) { @@ -66,7 +65,8 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { } file = - new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", getTaskConfig().getBuffSize()); + new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", + getTaskConfig().getBuffSize()); if (getThreadRecord().startLocation != 0) { //file.skipBytes((int) getThreadConfig().START_LOCATION); file.seek(getThreadRecord().startLocation); @@ -103,10 +103,8 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { private void initPath() throws UnsupportedEncodingException { dir = CommonUtil.convertFtpChar(charSet, mTaskOption.getUrlEntity().remotePath); - String fileName = - TextUtils.isEmpty(mTaskOption.getNewFileName()) ? CommonUtil.convertFtpChar(charSet, - getEntity().getFileName()) - : CommonUtil.convertFtpChar(charSet, mTaskOption.getNewFileName()); + String fileName = TextUtils.isEmpty(mTaskOption.getNewFileName()) ? getEntity().getFileName() + : mTaskOption.getNewFileName(); remotePath = CommonUtil.convertFtpChar(charSet, diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java index 491b30f4..5fd2acd0 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.m3u8; +import android.text.TextUtils; import com.arialyy.aria.core.common.RecordHandler; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; @@ -59,6 +60,9 @@ public abstract class BaseM3U8Loader extends AbsLoader { protected String getCacheDir() { String cacheDir = mM3U8Option.getCacheDir(); + if (TextUtils.isEmpty(cacheDir)) { + cacheDir = FileUtil.getTsCacheDir(getEntity().getFilePath(), mM3U8Option.getBandWidth()); + } if (!new File(cacheDir).exists()) { FileUtil.createDir(cacheDir); } diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java index 56d4050a..088f5f9d 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java @@ -131,7 +131,8 @@ public class M3U8RecordAdapter extends AbsRecordHandlerAdapter { @Override public int initTaskThreadNum() { if (getWrapper().getRequestType() == ITaskWrapper.M3U8_VOD) { - return mOption.getUrls().size(); + return + mOption.getUrls() == null || mOption.getUrls().isEmpty() ? 1 : mOption.getUrls().size(); } if (getWrapper().getRequestType() == ITaskWrapper.M3U8_LIVE) { return 1; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/AriaConfig.java b/PublicComponent/src/main/java/com/arialyy/aria/core/AriaConfig.java index cfe73566..8698ef0d 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/AriaConfig.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/AriaConfig.java @@ -23,6 +23,8 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkRequest; import android.os.Build; +import android.os.Handler; +import android.os.Looper; import com.arialyy.aria.core.config.AppConfig; import com.arialyy.aria.core.config.Configuration; import com.arialyy.aria.core.config.DGroupConfig; @@ -56,6 +58,7 @@ public class AriaConfig { * 是否已经联网,true 已经联网 */ private static boolean isConnectedNet = true; + private Handler mAriaHandler; private AriaConfig(Context context) { APP = context.getApplicationContext(); @@ -105,6 +108,13 @@ public class AriaConfig { return mDGConfig; } + public synchronized Handler getAriaHandler() { + if (mAriaHandler == null) { + mAriaHandler = new Handler(Looper.getMainLooper()); + } + return mAriaHandler; + } + /** * 注册网络监听,只有配置了检查网络{@link AppConfig#isNetCheck()}才会注册事件 */ diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/UploadListener.java b/PublicComponent/src/main/java/com/arialyy/aria/core/listener/UploadListener.java deleted file mode 100644 index 2cd1f0db..00000000 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/UploadListener.java +++ /dev/null @@ -1,55 +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.listener; - -import com.arialyy.aria.exception.BaseException; - -/** - * Created by lyy on 2017/2/23. - */ -class UploadListener implements IUploadListener { - @Override public void onPre() { - - } - - @Override public void onStart(long startLocation) { - - } - - @Override public void onResume(long resumeLocation) { - - } - - @Override public void onStop(long stopLocation) { - - } - - @Override public void onProgress(long currentLocation) { - - } - - @Override public void onCancel() { - - } - - @Override public void onComplete() { - - } - - @Override public void onFail(boolean needRetry, BaseException e) { - - } -} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/ThreadStateManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/ThreadStateManager.java index 1e6fc16a..c3fd33d8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/ThreadStateManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/ThreadStateManager.java @@ -84,7 +84,7 @@ public class ThreadStateManager implements IThreadState { mFailNum++; if (isFail()) { Bundle b = msg.getData(); - mListener.onFail(b.getBoolean(KEY_RETRY, true), + mListener.onFail(b.getBoolean(KEY_RETRY, false), (BaseException) b.getSerializable(KEY_ERROR_INFO)); quitLooper(); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java index 9a62b7f6..568e2b43 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java @@ -353,7 +353,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { } else { ALog.e(TAG, String.format("任务【%s】执行失败", getFileName())); ErrorHelp.saveError(TAG, "", ALog.getExceptionString(ex)); - sendFailMsg(null); + sendFailMsg(null, needRetry); } } } @@ -365,7 +365,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { boolean isConnected = NetUtils.isConnected(AriaConfig.getInstance().getAPP()); if (!isConnected && !isNotNetRetry) { ALog.w(TAG, String.format("ts切片【%s】重试失败,网络未连接", getFileName())); - sendFailMsg(null); + sendFailMsg(null, false); return; } if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected( @@ -377,7 +377,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { FileUtil.createFile(mConfig.tempFile); ThreadTaskManager.getInstance().retryThread(this); } else { - sendFailMsg(null); + sendFailMsg(null, needRetry); } } @@ -389,7 +389,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { private void retryBlockTask(boolean needRetry) { if (!NetUtils.isConnected(AriaConfig.getInstance().getAPP()) && !isNotNetRetry) { ALog.w(TAG, String.format("分块【%s】重试失败,网络未连接", getFileName())); - sendFailMsg(null); + sendFailMsg(null, false); return; } if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected( @@ -400,7 +400,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { handleBlockRecord(); ThreadTaskManager.getInstance().retryThread(this); } else { - sendFailMsg(null); + sendFailMsg(null, needRetry); } } @@ -448,13 +448,14 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver { /** * 发送失败信息 */ - private void sendFailMsg(@Nullable BaseException e) { + private void sendFailMsg(@Nullable BaseException e,boolean needRetry) { + Bundle b = new Bundle(); + b.putBoolean(IThreadState.KEY_RETRY, needRetry); if (e != null) { - Bundle b = new Bundle(); b.putSerializable(IThreadState.KEY_ERROR_INFO, e); updateState(IThreadState.STATE_FAIL, b); } else { - updateState(IThreadState.STATE_FAIL, null); + updateState(IThreadState.STATE_FAIL, b); } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java index 43d1e03c..7ab0b3bc 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -32,7 +32,7 @@ import java.util.Map; class DBConfig { /*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/ static boolean DEBUG = false; - static Map mapping = new LinkedHashMap<>(); + static Map> mapping = new LinkedHashMap<>(); static String DB_NAME; static int VERSION = 56; @@ -51,8 +51,8 @@ class DBConfig { } static { - mapping.put("DownloadGroupEntity", DownloadGroupEntity.class); mapping.put("DownloadEntity", DownloadEntity.class); + mapping.put("DownloadGroupEntity", DownloadGroupEntity.class); mapping.put("UploadEntity", UploadEntity.class); mapping.put("ThreadRecord", ThreadRecord.class); mapping.put("TaskRecord", TaskRecord.class); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java index 8021eb22..27a01d3f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java @@ -221,4 +221,22 @@ class DelegateCommon extends AbsDelegate { db.execSQL(str); } } + + /** + * 通过class 获取该class的表字段 + * + * @return 表字段列表 + */ + List getColumns(Class clazz) { + List columns = new ArrayList<>(); + List fields = CommonUtil.getAllFields(clazz); + for (Field field : fields) { + field.setAccessible(true); + if (SqlUtil.isIgnore(field)) { + continue; + } + columns.add(field.getName()); + } + return columns; + } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 16ae1bcb..0344b32b 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -100,14 +100,14 @@ final class SqlHelper extends SQLiteOpenHelper { } else if (oldVersion < 53) { handle366Update(db); } else { - handleDbUpdate(db, null, null); + handleDbUpdate(db, null); } } } @Override public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion > newVersion) { - handleDbUpdate(db, null, null); + handleDbUpdate(db, null); } } @@ -145,10 +145,8 @@ final class SqlHelper extends SQLiteOpenHelper { * * @param modifyColumns 需要修改的表字段的映射,key为表名, * value{@code Map}中的Map的key为老字段名称,value为该老字段对应的新字段名称 - * @param delColumns 需要删除的表字段,key为表名,value{@code List}为需要删除的字段列表 */ - private void handleDbUpdate(SQLiteDatabase db, Map> modifyColumns, - Map> delColumns) { + private void handleDbUpdate(SQLiteDatabase db, Map> modifyColumns) { if (db == null) { ALog.e("SqlHelper", "db 为 null"); return; @@ -161,7 +159,7 @@ final class SqlHelper extends SQLiteOpenHelper { db.beginTransaction(); Set tables = DBConfig.mapping.keySet(); for (String tableName : tables) { - Class clazz = DBConfig.mapping.get(tableName); + Class clazz = DBConfig.mapping.get(tableName); if (mDelegate.tableExists(db, clazz)) { //修改表名为中介表名 String alertSql = String.format("ALTER TABLE %s RENAME TO %s_temp", tableName, tableName); @@ -178,46 +176,57 @@ final class SqlHelper extends SQLiteOpenHelper { // 复制数据 if (count > 0) { - // 获取旧表的所有字段名称 Cursor columnC = db.rawQuery(String.format("PRAGMA table_info(%s_temp)", tableName), null); - StringBuilder params = new StringBuilder(); + + // 获取新表的所有字段名称 + List newTabColumns = mDelegate.getColumns(clazz); + // 获取旧表的所有字段名称 + List oldTabColumns = new ArrayList<>(); while (columnC.moveToNext()) { String columnName = columnC.getString(columnC.getColumnIndex("name")); - if (delColumns != null && delColumns.get(tableName) != null) { - List delColumn = delColumns.get(tableName); - if (delColumn != null && !delColumn.isEmpty()) { - if (delColumn.contains(columnName)) { - continue; - } - } - } - - params.append(columnName).append(","); + oldTabColumns.add(columnName); } columnC.close(); + // 旧表需要删除的字段,删除旧表有而新表没的字段 + List diffTab = getDiffColumn(newTabColumns, oldTabColumns); + StringBuilder params = new StringBuilder(); + + // 需要修改的列名映射表 + Map modifyMap = null; + if (modifyColumns != null) { + modifyMap = modifyColumns.get(tableName); + } + + for (String column : oldTabColumns) { + if (!diffTab.isEmpty() && diffTab.contains(column) + && (modifyMap != null && !modifyMap.containsKey(column))) { // 如果旧表字段有修改,忽略这个删除 + continue; + } + params.append(column).append(","); + } + String oldParamStr = params.toString(); oldParamStr = oldParamStr.substring(0, oldParamStr.length() - 1); String newParamStr = oldParamStr; // 处理字段名称改变 - if (modifyColumns != null) { - Map columnMap = modifyColumns.get(tableName); - if (columnMap != null && !columnMap.isEmpty()) { - Set keys = columnMap.keySet(); - for (String key : keys) { - if (newParamStr.contains(key)) { - newParamStr = newParamStr.replace(key, columnMap.get(key)); - } + if (modifyMap != null && !modifyMap.isEmpty()) { + Set keys = modifyMap.keySet(); + for (String key : keys) { + if (newParamStr.contains(key)) { + newParamStr = newParamStr.replace(key, modifyMap.get(key)); } } } + //恢复数据 String insertSql = String.format("INSERT INTO %s (%s) SELECT %s FROM %s_temp", tableName, newParamStr, oldParamStr, tableName); ALog.d(TAG, "insertSql = " + insertSql); + db.execSQL(insertSql); } //删除中介表 @@ -234,6 +243,19 @@ final class SqlHelper extends SQLiteOpenHelper { } } + /** + * 取新表差值(需要删除的字段):旧表有而新表没的字段 + * + * @param newTab 新表字段 + * @param oldTab 旧表字段 + * @return 旧表有而新表没的字段 + */ + private List getDiffColumn(List newTab, List oldTab) { + List temp = new ArrayList<>(oldTab); // 拷贝旧表字段 + temp.removeAll(newTab); + return temp; + } + /** * 删除重复的repeat数据 */ @@ -256,7 +278,7 @@ final class SqlHelper extends SQLiteOpenHelper { modifyMap.put("ThreadRecord", threadRecordModify); // 执行升级操作 - handleDbUpdate(db, modifyMap, null); + handleDbUpdate(db, modifyMap); delRepeatThreadRecord(db); } @@ -273,7 +295,7 @@ final class SqlHelper extends SQLiteOpenHelper { modifyMap.put("ThreadRecord", threadRecordModify); // 执行升级操作 - handleDbUpdate(db, modifyMap, null); + handleDbUpdate(db, modifyMap); delRepeatThreadRecord(db); } @@ -307,7 +329,7 @@ final class SqlHelper extends SQLiteOpenHelper { modifyMap.put("ThreadRecord", threadRecordModify); // 执行升级操作 - handleDbUpdate(db, modifyMap, null); + handleDbUpdate(db, modifyMap); delRepeatThreadRecord(db); } @@ -360,15 +382,6 @@ final class SqlHelper extends SQLiteOpenHelper { dGEntityModifyMap.put("groupName", "groupHash"); modifyMap.put("DownloadGroupEntity", dGEntityModifyMap); - // 删除字段 - Map> delColumnMap = new HashMap<>(); - List dEntityDel = new ArrayList<>(); - dEntityDel.add("taskKey"); - delColumnMap.put("DownloadEntity", dEntityDel); - List dgEntityDel = new ArrayList<>(); - dgEntityDel.add("subtask"); - delColumnMap.put("DownloadGroupEntity", dgEntityDel); - - handleDbUpdate(db, modifyMap, delColumnMap); + handleDbUpdate(db, modifyMap); } } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java index c8874bc1..7ba5a234 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -62,7 +62,7 @@ public class CheckUtil { public static boolean checkUploadPathConflicts(boolean isForceUpload, String filePath) { if (DbEntity.checkDataExist(UploadEntity.class, "filePath=?", filePath)) { if (!isForceUpload) { - ALog.e(TAG, String.format("上传失败,文件路径【%s】已经被其它任务占用,请设置其它保存路径", filePath)); + ALog.e(TAG, String.format("上传失败,文件路径【%s】已经被其它任务占用,请设置其它文件路径", filePath)); return false; } else { ALog.w(TAG, String.format("文件路径【%s】已经被其它任务占用,当前任务将覆盖该路径的文件", filePath)); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java index 4b1593ba..f954c7f9 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -38,6 +38,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.SequenceInputStream; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; @@ -61,6 +63,21 @@ public class FileUtil { private static final String EXTERNAL_STORAGE_PATH = Environment.getExternalStorageDirectory().getPath(); + /** + * 获取m3u8 ts文件的缓存目录。 + * 缓存文件夹格式:父文件夹/.文件名_码率 + * + * @param path m3u8 文件下载路径 + * @return m3u8 ts文件的缓存目录 + */ + public static String getTsCacheDir(String path, int bandWidth) { + if (TextUtils.isEmpty(path)) { + throw new NullPointerException("m3u8文保存路径为空"); + } + File file = new File(path); + return String.format("%s/.%s_%s", file.getParent(), file.getName(), bandWidth); + } + /** * 创建目录 当目录不存在的时候创建文件,否则返回false */ @@ -409,9 +426,19 @@ public class FileUtil { * 获取SD卡目录列表 */ public static List getSDPathList(Context context) { - List paths; + List paths = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - paths = getVolumeList(context); + try { + paths = getVolumeList(context); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } else { List mounts = readMountsFile(); List volds = readVoldFile(); @@ -471,16 +498,26 @@ public class FileUtil { /** * getSDPathList */ - private static List getVolumeList(final Context context) { + private static List getVolumeList(final Context context) + throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException { List pathList = new ArrayList<>(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { StorageManager manager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); List volumes = manager.getStorageVolumes(); + + Class volumeClass = StorageVolume.class; + Method getPath = volumeClass.getDeclaredMethod("getPath"); + //Method isRemovable = volumeClass.getDeclaredMethod("isRemovable"); + getPath.setAccessible(true); + //isRemovable.setAccessible(true); + for (StorageVolume volume : volumes) { String state = volume.getState(); + if (state.equals(Environment.MEDIA_MOUNTED)) { - pathList.add(volume.toString()); + pathList.add((String) getPath.invoke(volume)); } } } else { diff --git a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java index d1839d15..aad5bc82 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java @@ -39,7 +39,7 @@ public class HttpDownloadModule extends BaseViewModule { //"http://202.98.201.103:7000/vrs/TPK/ZTC440402001Z.tpk"; private final String defFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() - + "/tttt.apk"; + + "/update.zip"; private MutableLiveData liveData = new MutableLiveData<>(); private DownloadEntity singDownloadInfo; @@ -51,10 +51,15 @@ public class HttpDownloadModule extends BaseViewModule { //String url = AppUtil.getConfigValue(context, HTTP_URL_KEY, defUrl); //String url = // "http://sdkdown.muzhiwan.com/openfile/2019/05/21/com.netease.tom.mzw_5ce3ef8754d05.apk"; - String url = "http://image.totwoo.com/totwoo-TOTWOO-v3.5.6.apk"; + //String url = "http://image.totwoo.com/totwoo-TOTWOO-v3.5.6.apk"; + //String url = "http://fdfs.speedata.cn:9989/group1/M00/00/05/rBGFrl3fdAKAVJwfMtSa9R18wLU139.zip"; + //String url = "http://9.9.9.28:8088/files/update.zip"; + String url = "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg"; //String url = "https://imtt.dd.qq.com/16891/apk/70BFFDB05AB8686F2A4CF3E07588A377.apk?fsname=com.tencent.tmgp.speedmobile_1.16.0.33877_1160033877.apk&csr=1bbd"; //String url = "https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg"; - String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath); + //String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath); + String filePath = "/mnt/sdcard/gg.png"; + //String filePath = "/mnt/sdcard/update.zip"; singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url); if (singDownloadInfo == null) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index 798cf527..d72aa415 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -39,6 +39,7 @@ import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; +import com.arialyy.aria.util.FileUtil; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; @@ -274,11 +275,13 @@ public class SingleTaskActivity extends BaseActivity { break; } if (Aria.download(this).load(mTaskId).isRunning()) { - Aria.download(this).load(mTaskId).stop(); + Aria.download(this) + .load(mTaskId) + .stop(); } else { mUrl = "http://sdkdown.muzhiwan.com/openfile/2019/07/11/com.netease.syfz.mzw_5d26f8d9cee27.apk"; Aria.download(this).load(mTaskId) - .updateUrl(mUrl) + //.updateUrl(mUrl) .resume(); } break; @@ -297,6 +300,7 @@ public class SingleTaskActivity extends BaseActivity { .load(mUrl) .setFilePath(mFilePath, true) .option(option) + .ignoreCheckPermissions() .create(); } diff --git a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java index 19042e5f..5f5aa6b5 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java @@ -35,9 +35,9 @@ public class UploadModule extends BaseViewModule { * 获取Ftp上传信息 */ LiveData getFtpInfo(Context context) { - String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.50:2121/aa/你好"); + String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.72:2121/aa/你好"); String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, - Environment.getExternalStorageDirectory().getPath() + "/Download/Folx P58.zip"); + Environment.getExternalStorageDirectory().getPath() + "/Download/AndroidAria.db"); UploadEntity entity = Aria.upload(context).getFirstUploadEntity(filePath); if (entity != null) { diff --git a/build.gradle b/build.gradle index 752aad52..2c64b34a 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ task clean(type: Delete) { } ext { - versionCode = 379 - versionName = '3.7.9' + versionCode = 380 + versionName = '3.7.10_pre_3' userOrg = 'arialyy' groupId = 'com.arialyy.aria' publishVersion = versionName diff --git a/py/.vscode/launch.json b/py/.vscode/launch.json deleted file mode 100644 index b80908c1..00000000 --- a/py/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: 当前文件", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file diff --git a/py/.vscode/settings.json b/py/.vscode/settings.json deleted file mode 100644 index 4ca83c7f..00000000 --- a/py/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "python.linting.pylintEnabled": false, - "python.linting.pep8Enabled": true, - "python.linting.enabled": true, - "python.pythonPath": "/usr/local/bin/python3.7" -} \ No newline at end of file diff --git a/test/347/AndroidAria.db b/test/347/AndroidAria.db new file mode 100644 index 0000000000000000000000000000000000000000..ce6690b2a1c390540eff8ef99e7bef1d7947a616 GIT binary patch literal 73728 zcmeI*O>EoN0S9nWl4aSkt+<6jU`8+osZa}31nbMT>aDFT({51P@?@o5x)vTS(lTp_ zR7k2`vUUKSY#p}4&O5XPh7CLKFbu)4p+&bHci3$}fu+Zu*4?(--lHUnlc-MpJ6UCfdKO|&oc}&M4r!(XLq_l-h?^}G@K>R zna=V_FGEan_J#52N6ba`119>L@xMnm$G$oKi_zbW4M*;cn&EdM?+&#>%utg3Aoz!q zB6(`V?@mXDxm1dMUo^#?y1c9%sC7-0Dx$G3sHS4xIvO%rEDME-z*h=OYXX1tbAG0} zC+b_W$-h=87hfrq6ID%;`D+^$VO1z6_GD3#b%U=6->D=NW2@C{YPz|!$uE^kYeHco zq05q@%T@EbUUy>9<(nM=nt#hYW5;GOpz3|Zc;5n-jelqWPL@c%Nt@tcG9Tn zTB~V?bhlA4ihC_}UzVJ86l0aHMJb%Hefd^5eSWiiZM{&w!M`fpNVIy}%5Rh^{KoaQ zwZuxPEL>aNpeyh*PKt59EUXA+VWTK)IeJb?ZS)zEPMj}o@Ygq&DRr^1RV*wEG-O#= z6M7-uH0-}RCiYIGQYUjaMRU(r?D68oF!y?jWfWDCzi-^ElX|=@woJ`l-aeZ3+o_{r z&m4YZe3;8**gNleikQ92-ZJJ2iXL0YTq}@LrZt*%*_0~^&Dd+JB-cqvQ%QE4G{3i$ z+j2Lr64jQj%c{AlYc*XqjPB~Y-Ss+uP6|OMQYXi~CCV_hraL{u)SWcMx*{6R5-G#f z*;%gjm$?4&)28@;lplWJF%tC}vk-%og$ z-JkF?J9VwPzb30)ELoM-w5n(-niF)4m#c;(h@Ecs|BY#H$~DQUrJiciUxaDxYj5@p z%`E>#_ik`>n2X2R_Y0m<=PhvUr7;gew*f--6#xi3)~I%JKW8v zkLEGHcp=P{;)7~aJMLaZYA=u9S%?gCSFf@^zG4@l>rHRZ*uOmLDMtODJ_)^|XqsYm zuOX}Mu3I(9vfascv#whaoh+tb?N$`IE_Hf!R~z6dETliy3pIE2o>I_X_uGW+%y`J! z|I$d9+q!yEzW3+NcB((*!eJ>q%w4|B-c{P|r_&7e8l;FPzkA{QjAU0xPbH;hq%EzH z9--6M^w;Cw_lAC7kD+2L(RSIX)tzrC?KaXCT58Jb@-0G5r+dhbUL-w4^=*xdtH6>OIXcj*XwvcmnzQ`CMxu-K4q zJxxs|--ml&SmN_TVeZw~Njc(H>{gJr{P5uq0>j+mBKxCpPv2^ndYXCd)w&&NUvS8i zS0}9WB(#<%wQ`>N)ZeCg_P5itxq3f8ecF03%!!L9Wt%5~US{+>WF2tWV= z5P$##AOHafKmY;|I9meaWOLZ)zZvqt1OW&@00Izz00bZa0SG_<0uX?}c@Y?A16OYE zZ5KDTue>6vM*H~xVn(Hl>Vm1a_T=YC+}9P3#r*rLc&Hr zW5@#&1Rwwb2tWV=5P$##AOHafKmYgSb(1Y$MOF;&S2~s1Rwwb2tWV=5P$##AOHafK!6C)^Z$W~Uoz3x$P5z% zAOHafKmY;|fB*y_009U<;QuCIr2?btp_(<#O>yj?%h@AqH@+bMdOE3UnpBso;=Y`$ z$)>5OHI4l1X~oP{rF15no0sxCVmeuC?#I$A4b>!bL#m3pMBdc&W~)hFA1WGqtUVoh zZ@&pz&$DEk-?AqCY;*Wv>O-1XLwj3PYsrS9%2i$5HJkEwPD-cc)Ld>hH$OL@6bEgt zpBVbKl%D?&MC(lS9+_c+00bZa0SG_<0uX=z1Rwwb2teSm1=d2=G_nv7sjaa5YuC*o)Njp%DWTSO^ zPdO0PB#Dg#re{-m@-jP5XA5NJHxaVx14f_wxqf@lfcV3Bz`?0eoDySAQ=CjXIX_Qu ze*XJk(?Rn+9N$CdA4MqV7V@3agPD9sGsw!i$xaPTheA^$q#$v`YLT&6Qu0~#FQ5N$ zB%4nzWEwlcOOufh)oFkwHIX(DVPn@hv9$t%)Le!2|&aKmY;|fB*y_009U<00RC6 ztVVE>3ouj6vn|Pxz07v^e1u~-&SI^_zCE||us1t;xq;t-`u=w2q3;}s j`~Uf`*jN(+5P$##AOHafKmY;|fB*!Z4uSJ{|G)nMM^g}` literal 0 HcmV?d00001