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 00000000..ce6690b2 Binary files /dev/null and b/test/347/AndroidAria.db differ