diff --git a/Aria/jcenter.gradle b/Aria/jcenter.gradle
index 5d0a7f24..138833d6 100644
--- a/Aria/jcenter.gradle
+++ b/Aria/jcenter.gradle
@@ -5,7 +5,7 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
//输入:gradlew bintray 执行
-//############################## jar、sources、doc 打包 start #######################################
+//############################## jar、sources、doc 打包 create #######################################
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
@@ -73,7 +73,7 @@ artifacts {
}
//############################## jar、sources、doc 打包 end #######################################
-//################################# jcenter 上传配置 start #########################################
+//################################# jcenter 上传配置 create #########################################
bintray {
// user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
// groupHash = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
index d18f76a0..576133c6 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -43,7 +43,7 @@ import com.arialyy.aria.util.ALog;
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- * .start();
+ * .create();
*
*
* //上传
@@ -51,7 +51,7 @@ import com.arialyy.aria.util.ALog;
* .load(filePath) //文件路径,必填
* .setTempUrl(uploadUrl) //上传路径,必填
* .setAttachment(fileKey) //服务器读取文件的key,必填
- * .start();
+ * .create();
*
*
*
@@ -67,7 +67,7 @@ import com.arialyy.aria.util.ALog;
* .load(URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- * .start();
+ * .create();
*
*
*
@@ -113,7 +113,7 @@ import com.arialyy.aria.util.ALog;
if (context == null) {
throw new NullPointerException(
"context 无效,在非【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】,"
- + "请参考【https://aria.laoyuyu.me/aria_doc/start/any_java.html】,参数请使用 download(this) 或 upload(this);"
+ + "请参考【https://aria.laoyuyu.me/aria_doc/create/any_java.html】,参数请使用 download(this) 或 upload(this);"
+ "不要使用 download(getContext()) 或 upload(getContext())");
}
return AriaManager.getInstance(context);
diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsStartTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsStartTarget.java
index 7437434a..65614b6d 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsStartTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsStartTarget.java
@@ -50,8 +50,8 @@ public abstract class AbsStartTarget extends AbsT
* @return 正常启动,返回任务id,否则返回-1
*/
@Override
- public long start() {
- return getController().start();
+ public long create() {
+ return getController().create();
}
/**
diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
index ecb14c21..aa65249a 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
@@ -34,8 +34,8 @@ import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
-import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
+import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.NetUtils;
import java.io.File;
import java.util.UUID;
@@ -201,10 +201,12 @@ public abstract class AbsThreadTask START_CONTROLLER = StartController.class;
/**
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 e2efa207..d981e340 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
@@ -62,7 +62,7 @@ public abstract class FeatureController {
}
if (wrapper.getEntity().getId() != -1 && clazz != ControllerType.NORMAL_CONTROLLER) {
throw new IllegalArgumentException(
- "对于已存在的任务,只能使用\" ControllerType.NORMAL_CONTROLLER\",请检查是否重复调用#start()方法");
+ "对于已存在的任务,只能使用\" ControllerType.NORMAL_CONTROLLER\",请检查是否重复调用#create()方法");
}
Class[] paramTypes = { AbsTaskWrapper.class };
diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/IStartFeature.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/IStartFeature.java
index c84d5059..208f75a5 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/IStartFeature.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/IStartFeature.java
@@ -28,11 +28,11 @@ public interface IStartFeature {
long add();
/**
- * 开始任务
+ * 创建并开始任务
*
* @return 正常启动,返回任务id,否则返回-1
*/
- long start();
+ long create();
/**
* 将任务设置为最高优先级任务,最高优先级任务有以下特点:
diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/StartController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/StartController.java
index 66c486aa..a4149954 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/StartController.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/StartController.java
@@ -49,7 +49,7 @@ public final class StartController extends FeatureController implements IStartFe
*
* @return 正常启动,返回任务id,否则返回-1
*/
- public long start() {
+ public long create() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START,
diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java
index 0248f22b..1feddc7d 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java
@@ -36,7 +36,7 @@ import java.util.List;
* return builder.build();
* }
* })
- * .start();
+ * .create();
*
*
*
diff --git a/Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java b/Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java
index 2fe767b0..3d9ae123 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java
@@ -3,7 +3,7 @@ package com.arialyy.aria.core.config;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.util.ALog;
-import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.aria.util.FileUtil;
import java.io.Serializable;
abstract class BaseConfig implements Serializable {
@@ -42,8 +42,8 @@ abstract class BaseConfig implements Serializable {
}
if (!TextUtils.isEmpty(path)) {
String tempPath = String.format("%s%s", basePath, path);
- CommonUtil.deleteFile(tempPath);
- CommonUtil.writeObjToFile(tempPath, this);
+ FileUtil.deleteFile(tempPath);
+ FileUtil.writeObjToFile(tempPath, this);
} else {
ALog.e(TAG, String.format("保存配置失败,配置类型:%s,原因:路径错误", getType()));
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java b/Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java
index 8be65061..b0faf0c1 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java
@@ -16,7 +16,7 @@
package com.arialyy.aria.core.config;
import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.aria.util.FileUtil;
import java.io.File;
/**
@@ -45,28 +45,28 @@ public final class Configuration {
File dgCfg = new File(String.format("%s%s", basePath, DGROUP_CONFIG_FILE));
// 加载下载配置
if (newDCfg.exists()) {
- downloadCfg = (DownloadConfig) CommonUtil.readObjFromFile(newDCfg.getPath());
+ downloadCfg = (DownloadConfig) FileUtil.readObjFromFile(newDCfg.getPath());
}
if (downloadCfg == null) {
downloadCfg = new DownloadConfig();
}
// 加载上传配置
if (newUCfg.exists()) {
- uploadCfg = (UploadConfig) CommonUtil.readObjFromFile(newUCfg.getPath());
+ uploadCfg = (UploadConfig) FileUtil.readObjFromFile(newUCfg.getPath());
}
if (uploadCfg == null) {
uploadCfg = new UploadConfig();
}
// 加载app配置
if (newACfg.exists()) {
- appCfg = (AppConfig) CommonUtil.readObjFromFile(newACfg.getPath());
+ appCfg = (AppConfig) FileUtil.readObjFromFile(newACfg.getPath());
}
if (appCfg == null) {
appCfg = new AppConfig();
}
// 加载下载类型组合任务的配置
if (dgCfg.exists()) {
- dGroupCfg = (DGroupConfig) CommonUtil.readObjFromFile(dgCfg.getPath());
+ dGroupCfg = (DGroupConfig) FileUtil.readObjFromFile(dgCfg.getPath());
}
if (dGroupCfg == null) {
dGroupCfg = new DGroupConfig();
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 af37bde0..1d686979 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
@@ -74,7 +74,11 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
m3U8Entity.setFilePath(mEntity.getFilePath());
m3U8Entity.setPeerIndex(0);
m3U8Entity.setCacheDir(cacheDir);
+ m3U8Entity.setGenerateIndexFile(mWrapper.asM3U8().isGenerateIndexFileTemp());
m3U8Entity.insert();
+ } else {
+ m3U8Entity.setGenerateIndexFile(mWrapper.asM3U8().isGenerateIndexFileTemp());
+ m3U8Entity.update();
}
if (mWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
if (mEntity.getFileSize() == 0) {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
index cac8a9f1..e8ebfeaa 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
@@ -59,6 +59,11 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
@Ignore
private M3U8Entity m3U8Entity;
+ /**
+ * 获取m3u8数据信息
+ *
+ * @return 如果m3u8信息为空,则返回null
+ */
public M3U8Entity getM3U8Entity() {
if (TextUtils.isEmpty(downloadPath)) {
ALog.e("DownloadEntity", "文件保存路径为空,获取m3u8实体之前需要设置文件保存路径");
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 15659cf7..63fdcc90 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
@@ -73,7 +73,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 用于任务停止、删除等操作
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@@ -96,7 +96,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 加载组合任务,用于任务停止、删除等操作
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* * AbsEntity#getId()}读取任务id
*/
@CheckResult
@@ -117,7 +117,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 用于任务停止、删除等操作
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@@ -138,7 +138,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 加载ftp文件夹下载地址,用于任务停止、删除等操作
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
index 39591639..ad28bb41 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
@@ -90,9 +90,9 @@ public class SimpleDownloadUtil implements IUtil {
// || mTaskWrapper.isRefreshInfo()
// || mTaskWrapper.getRequestType() == AbsTaskWrapper.D_FTP
// || mTaskWrapper.getState() == IEntity.STATE_FAIL) {
- // new Thread(createInfoThread()).start();
+ // new Thread(createInfoThread()).create();
//} else {
- // mDownloader.start();
+ // mDownloader.create();
//}
new Thread(createInfoThread()).start();
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
index e97d89ef..a0335b02 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
@@ -207,12 +207,18 @@ public abstract class AbsGroupUtil implements IUtil {
closeTimer();
return;
}
- onPreStart();
- startRunningFlow();
+ if (onPreStart()) {
+ startRunningFlow();
+ }
}
- protected void onPreStart() {
-
+ /**
+ * 处理启动前的检查:获取组合任务大小
+ *
+ * @return {@code false} 将不再走后续流程,任务介绍
+ */
+ protected boolean onPreStart() {
+ return false;
}
synchronized void closeTimer() {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java
index 3595fde2..272583ef 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java
@@ -68,7 +68,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
return false;
}
- @Override protected void onPreStart() {
+ @Override protected boolean onPreStart() {
super.onPreStart();
initState();
if (mState.getCompleteNum() == mState.getSubSize()) {
@@ -85,6 +85,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
} catch (InterruptedException e) {
e.printStackTrace();
}
+ return getLenComplete;
} else {
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
if (wrapper.getState() != IEntity.STATE_COMPLETE) {
@@ -93,6 +94,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
}
}
}
+ return true;
}
/**
@@ -138,6 +140,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
*/
private void checkGetSizeComplete(int count, int failCount) {
if (failCount == mGTWrapper.getSubTaskWrapper().size()) {
+ mState.isRunning = false;
mListener.onFail(false, new AriaIOException(TAG, "获取子任务长度失败"));
notifyLock();
return;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java
index 8fdf2892..4716675b 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java
@@ -45,8 +45,9 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
return FTP_DIR;
}
- @Override protected void onPreStart() {
+ @Override protected boolean onPreStart() {
super.onPreStart();
+
if (mGTWrapper.getEntity().getFileSize() > 1) {
startDownload(true);
} else {
@@ -71,6 +72,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
LOCK.unlock();
}
}
+ return true;
}
/**
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java
index c1a9d76e..3cd54b50 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java
@@ -19,7 +19,7 @@ import com.arialyy.aria.core.common.AbsFileer;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEventListener;
-import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.aria.util.FileUtil;
import java.io.File;
public abstract class BaseM3U8Loader extends AbsFileer {
@@ -46,7 +46,7 @@ public abstract class BaseM3U8Loader extends AbsFileer tsPath);
+ boolean merge(@Nullable M3U8Entity m3U8Entity, List tsPath);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
index 5f6c70bd..beea90f8 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
@@ -35,11 +35,12 @@ public class M3U8Delegate extends BaseDelegate
}
/**
- * 生成m3u8索引文件,只有{@link #merge(boolean)}设置为false才会有效
+ * 生成m3u8索引文件
+ * 注意:创建索引文件,{@link #merge(boolean)}方法设置与否都不再合并文件
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
- public M3U8Delegate genetateIndexFile() {
- mTaskWrapper.asM3U8().setGenerateIndexFile(true);
+ public M3U8Delegate generateIndexFile() {
+ mTaskWrapper.asM3U8().setGenerateIndexFileTemp(true);
return this;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java
index 1ab5a94c..715d62df 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java
@@ -58,6 +58,71 @@ public class M3U8Entity extends DbEntity implements Parcelable {
*/
private String cacheDir;
+ /**
+ * 生成索引
+ */
+ private boolean generateIndexFile;
+
+ /**
+ * 加密key保存地址
+ */
+ public String keyPath;
+
+ /**
+ * 加密key的下载地址
+ */
+ public String keyUrl;
+
+ /**
+ * 加密算法
+ */
+ public String method;
+
+ /**
+ * key的iv值
+ */
+ public String iv;
+
+ public String getKeyPath() {
+ return keyPath;
+ }
+
+ public void setKeyPath(String keyPath) {
+ this.keyPath = keyPath;
+ }
+
+ public String getKeyUrl() {
+ return keyUrl;
+ }
+
+ public void setKeyUrl(String keyUrl) {
+ this.keyUrl = keyUrl;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ public String getIv() {
+ return iv;
+ }
+
+ public void setIv(String iv) {
+ this.iv = iv;
+ }
+
+ public boolean isGenerateIndexFile() {
+ return generateIndexFile;
+ }
+
+ public void setGenerateIndexFile(boolean generateIndexFile) {
+ this.generateIndexFile = generateIndexFile;
+ }
+
public boolean isLive() {
return isLive;
}
@@ -163,6 +228,16 @@ public class M3U8Entity extends DbEntity implements Parcelable {
public M3U8Entity() {
}
+ public static class PeerInfo {
+ public PeerInfo(int peerId, String peerPath) {
+ this.peerId = peerId;
+ this.peerPath = peerPath;
+ }
+
+ public int peerId;
+ public String peerPath;
+ }
+
@Override public int describeContents() {
return 0;
}
@@ -173,6 +248,11 @@ public class M3U8Entity extends DbEntity implements Parcelable {
dest.writeInt(this.peerNum);
dest.writeByte(this.isLive ? (byte) 1 : (byte) 0);
dest.writeString(this.cacheDir);
+ dest.writeByte(this.generateIndexFile ? (byte) 1 : (byte) 0);
+ dest.writeString(this.keyPath);
+ dest.writeString(this.keyUrl);
+ dest.writeString(this.method);
+ dest.writeString(this.iv);
}
protected M3U8Entity(Parcel in) {
@@ -181,6 +261,11 @@ public class M3U8Entity extends DbEntity implements Parcelable {
this.peerNum = in.readInt();
this.isLive = in.readByte() != 0;
this.cacheDir = in.readString();
+ this.generateIndexFile = in.readByte() != 0;
+ this.keyPath = in.readString();
+ this.keyUrl = in.readString();
+ this.method = in.readString();
+ this.iv = in.readString();
}
public static final Creator CREATOR = new Creator() {
@@ -192,14 +277,4 @@ public class M3U8Entity extends DbEntity implements Parcelable {
return new M3U8Entity[size];
}
};
-
- public static class PeerInfo {
- public PeerInfo(int peerId, String peerPath) {
- this.peerId = peerId;
- this.peerPath = peerPath;
- }
-
- public int peerId;
- public String peerPath;
- }
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
index aa1fd357..e0f50500 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java
@@ -16,6 +16,7 @@
package com.arialyy.aria.core.download.m3u8;
import android.net.TrafficStats;
+import android.net.Uri;
import android.os.Process;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
@@ -32,15 +33,18 @@ import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.Regular;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -53,6 +57,7 @@ import java.util.regex.Pattern;
* https://blog.csdn.net/Guofengpu/article/details/54922865
*/
final class M3U8InfoThread implements Runnable {
+ public static final String M3U8_INDEX_FORMAT = "%s.index";
private final String TAG = "M3U8InfoThread";
private DownloadEntity mEntity;
private DTaskWrapper mTaskWrapper;
@@ -64,6 +69,10 @@ final class M3U8InfoThread implements Runnable {
* 是否停止获取切片信息,{@code true}停止获取切片信息
*/
private boolean isStop = false;
+ /**
+ * m3u8文件信息
+ */
+ private List mInfos = new ArrayList<>();
interface OnGetLivePeerCallback {
void onGetPeer(String url);
@@ -110,16 +119,24 @@ final class M3U8InfoThread implements Runnable {
}
List extInf = new ArrayList<>();
boolean isLive = mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE;
+ boolean isGenerateIndexFile = mTaskWrapper.getEntity().getM3U8Entity().isGenerateIndexFile();
+ if (isGenerateIndexFile) {
+ mInfos.add(line);
+ }
while ((line = reader.readLine()) != null) {
if (isStop) {
break;
}
+ if (isGenerateIndexFile) {
+ mInfos.add(line);
+ }
if (line.startsWith("#EXT-X-ENDLIST")) {
break;
}
- ALog.d(TAG, line);
+ //ALog.d(TAG, line);
if (line.startsWith("#EXTINF")) {
String info = reader.readLine();
+ mInfos.add(info);
if (isLive) {
if (onGetPeerCallback != null) {
onGetPeerCallback.onGetPeer(info);
@@ -130,6 +147,10 @@ final class M3U8InfoThread implements Runnable {
} else if (line.startsWith("#EXT-X-STREAM-INF")) {
int setBand = mTaskWrapper.asM3U8().getBandWidth();
int bandWidth = getBandWidth(line);
+ // 多码率的m3u8配置文件,清空信息
+ if (isGenerateIndexFile && mInfos != null) {
+ mInfos.clear();
+ }
if (setBand == 0) {
handleBandWidth(conn, reader.readLine());
} else if (bandWidth == setBand) {
@@ -153,6 +174,7 @@ final class M3U8InfoThread implements Runnable {
}
CompleteInfo info = new CompleteInfo();
info.obj = extInf;
+ generateIndexFile();
onFileInfoCallback.onComplete(mEntity.getKey(), info);
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|| code == HttpURLConnection.HTTP_MOVED_PERM
@@ -167,6 +189,43 @@ final class M3U8InfoThread implements Runnable {
}
}
+ /**
+ * 创建索引文件
+ */
+ private void generateIndexFile() {
+ if (mTaskWrapper.getEntity().getM3U8Entity().isGenerateIndexFile()) {
+
+ String indexPath = String.format(M3U8_INDEX_FORMAT, mEntity.getFilePath());
+ File indexFile = new File(indexPath);
+ if (indexFile.exists()) {
+ FileUtil.deleteFile(indexPath);
+ }
+ FileUtil.createFile(indexPath);
+
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(indexFile);
+ for (String str : mInfos) {
+ byte[] by = str.concat("\r\n").getBytes(Charset.forName("UTF-8"));
+ fos.write(by, 0, by.length);
+ }
+ fos.flush();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
/**
* 是否停止获取切片信息,{@code true}停止获取切片信息
*/
@@ -187,20 +246,19 @@ final class M3U8InfoThread implements Runnable {
private void getKeyInfo(String line) {
String temp = line.substring(line.indexOf(":") + 1);
String[] params = temp.split(",");
- M3U8KeyInfo keyInfo = new M3U8KeyInfo();
+ M3U8Entity m3U8Entity = mEntity.getM3U8Entity();
for (String param : params) {
if (param.startsWith("METHOD")) {
- keyInfo.method = param.split("=")[1];
+ m3U8Entity.method = param.split("=")[1];
} else if (param.startsWith("URI")) {
- keyInfo.keyUrl = param.split("=")[1].replaceAll("\"", "");
- keyInfo.keyPath = new File(mEntity.getFilePath()).getParent() + "/" + CommonUtil.getStrMd5(
- keyInfo.keyUrl) + ".key";
+ m3U8Entity.keyUrl = param.split("=")[1].replaceAll("\"", "");
+ m3U8Entity.keyPath = new File(mEntity.getFilePath()).getParent() + "/" + CommonUtil.getStrMd5(
+ m3U8Entity.keyUrl) + ".key";
} else if (param.startsWith("IV")) {
- keyInfo.iv = param.split("=")[1];
+ m3U8Entity.iv = param.split("=")[1];
}
}
- mTaskWrapper.asM3U8().setKeyInfo(keyInfo);
- DownloadKey(keyInfo);
+ downloadKey(m3U8Entity);
}
/**
@@ -220,13 +278,18 @@ final class M3U8InfoThread implements Runnable {
*/
private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOException {
ALog.d(TAG, "30x跳转,新url为【" + newUrl + "】");
- if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith(
- "http")) {
+ if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
if (onFileInfoCallback != null) {
onFileInfoCallback.onFail(mEntity, new TaskException(TAG, "获取重定向链接失败"), false);
}
return;
}
+
+ if (newUrl.startsWith("/")) {
+ Uri uri = Uri.parse(mEntity.getUrl());
+ newUrl = uri.getHost() + newUrl;
+ }
+
if (!CheckUtil.checkUrlNotThrow(newUrl)) {
failDownload("下载失败,重定向url错误", false);
return;
@@ -281,14 +344,14 @@ final class M3U8InfoThread implements Runnable {
/**
* 密钥不存在,下载密钥
*/
- private void DownloadKey(M3U8KeyInfo info) {
+ private void downloadKey(M3U8Entity info) {
HttpURLConnection conn = null;
FileOutputStream fos = null;
try {
File keyF = new File(info.keyPath);
if (!keyF.exists()) {
ALog.d(TAG, "密钥不存在,下载密钥");
- CommonUtil.createFile(keyF.getPath());
+ FileUtil.createFile(keyF.getPath());
} else {
return;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8KeyInfo.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8KeyInfo.java
deleted file mode 100644
index a1013758..00000000
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8KeyInfo.java
+++ /dev/null
@@ -1,77 +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.download.m3u8;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * m3u8加密密钥信息
- */
-public class M3U8KeyInfo implements Parcelable {
-
- /**
- * 加密key保存地址
- */
- public String keyPath;
-
- /**
- * 加密key的下载地址
- */
- public String keyUrl;
-
- /**
- * 加密算法
- */
- public String method;
-
- /**
- * key的iv值
- */
- public String iv;
-
- @Override public int describeContents() {
- return 0;
- }
-
- @Override public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(this.keyPath);
- dest.writeString(this.keyUrl);
- dest.writeString(this.method);
- dest.writeString(this.iv);
- }
-
- public M3U8KeyInfo() {
- }
-
- protected M3U8KeyInfo(Parcel in) {
- this.keyPath = in.readString();
- this.keyUrl = in.readString();
- this.method = in.readString();
- this.iv = in.readString();
- }
-
- public static final Parcelable.Creator CREATOR =
- new Parcelable.Creator() {
- @Override public M3U8KeyInfo createFromParcel(Parcel source) {
- return new M3U8KeyInfo(source);
- }
-
- @Override public M3U8KeyInfo[] newArray(int size) {
- return new M3U8KeyInfo[size];
- }
- };
-}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
index e31ea849..4cc6eb57 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java
@@ -26,7 +26,6 @@ import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.util.ALog;
-import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.IdGenerator;
import java.io.File;
@@ -143,7 +142,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
config.stateHandler = mStateHandler;
if (!config.tempFile.exists()) {
- CommonUtil.createFile(config.tempFile.getPath());
+ FileUtil.createFile(config.tempFile.getPath());
}
return new M3U8ThreadTask(config);
}
@@ -168,7 +167,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
boolean isSuccess;
if (mergeHandler != null) {
- isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath);
+ isSuccess = mergeHandler.merge(getEntity().getM3U8Entity(), partPath);
} else {
isSuccess = FileUtil.mergeFile(mEntity.getFilePath(), partPath);
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java
index 7699c923..8be1e550 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java
@@ -73,11 +73,6 @@ public class M3U8TaskConfig {
*/
private String bandWidthUrl;
- /**
- * ts密钥信息
- */
- private M3U8KeyInfo keyInfo;
-
/**
* 直播下载,ts url转换器
*/
@@ -99,16 +94,16 @@ public class M3U8TaskConfig {
private int jumpIndex;
/**
- * 生成索引
+ * 生成索引占位字段
*/
- private boolean generateIndexFile;
+ private boolean generateIndexFileTemp;
- public boolean isGenerateIndexFile() {
- return generateIndexFile;
+ public boolean isGenerateIndexFileTemp() {
+ return generateIndexFileTemp;
}
- public void setGenerateIndexFile(boolean generateIndexFile) {
- this.generateIndexFile = generateIndexFile;
+ public void setGenerateIndexFileTemp(boolean generateIndexFileTemp) {
+ this.generateIndexFileTemp = generateIndexFileTemp;
}
public int getJumpIndex() {
@@ -143,14 +138,6 @@ public class M3U8TaskConfig {
this.liveTsUrlConverter = new WeakReference<>(liveTsUrlConverter);
}
- public M3U8KeyInfo getKeyInfo() {
- return keyInfo;
- }
-
- public void setKeyInfo(M3U8KeyInfo keyInfo) {
- this.keyInfo = keyInfo;
- }
-
public String getBandWidthUrl() {
return bandWidthUrl;
}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java
index a4ecced1..b620df05 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java
@@ -35,9 +35,15 @@ import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
-import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
@@ -422,7 +428,7 @@ public class M3U8VodLoader extends BaseM3U8Loader {
config.stateHandler = mStateHandler;
config.peerIndex = index;
if (!config.tempFile.exists()) {
- CommonUtil.createFile(config.tempFile.getPath());
+ FileUtil.createFile(config.tempFile.getPath());
}
return new M3U8ThreadTask(config);
}
@@ -610,6 +616,9 @@ public class M3U8VodLoader extends BaseM3U8Loader {
* @return {@code true} 合并成功,{@code false}合并失败
*/
private boolean mergeFile() {
+ if (getEntity().getM3U8Entity().isGenerateIndexFile()) {
+ return generateIndexFile();
+ }
ITsMergeHandler mergeHandler = mTaskWrapper.asM3U8().getMergeHandler();
String cacheDir = getCacheDir();
List partPath = new ArrayList<>();
@@ -618,7 +627,7 @@ public class M3U8VodLoader extends BaseM3U8Loader {
}
boolean isSuccess;
if (mergeHandler != null) {
- isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath);
+ isSuccess = mergeHandler.merge(getEntity().getM3U8Entity(), partPath);
if (mergeHandler.getClass().isAnonymousClass()) {
mTaskWrapper.asM3U8().setMergeHandler(null);
@@ -646,6 +655,61 @@ public class M3U8VodLoader extends BaseM3U8Loader {
}
}
+ /**
+ * 创建索引文件
+ */
+ private boolean generateIndexFile() {
+ File tempFile = new File(M3U8InfoThread.M3U8_INDEX_FORMAT, getEntity().getFilePath());
+ if (!tempFile.exists()) {
+ ALog.e(TAG, "源索引文件不存在");
+ return false;
+ }
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+ try {
+ String cacheDir = getCacheDir();
+ fis = new FileInputStream(tempFile);
+ fos = new FileOutputStream(getEntity().getFilePath());
+ BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
+ String line;
+ int i = 0;
+ while ((line = reader.readLine()) != null) {
+ byte[] bytes;
+ if (line.startsWith("EXTINF")) {
+ String tsPath = getTsFilePath(cacheDir, mRecord.threadRecords.get(i).threadId);
+ bytes = tsPath.concat("\r\n").getBytes(Charset.forName("UTF-8"));
+ i++;
+ } else if (line.startsWith("EXT-X-KEY")) {
+ M3U8Entity m3U8Entity = getEntity().getM3U8Entity();
+ String keyInfo = String.format("#EXT-X-KEY:METHOD=%s,URI=%s,IV=%s\r\n", m3U8Entity.method,
+ m3U8Entity.keyPath, m3U8Entity.iv);
+ bytes = keyInfo.getBytes(Charset.forName("UTF-8"));
+ } else {
+ bytes = line.getBytes(Charset.forName("UTF-8"));
+ }
+ fos.write(bytes, 0, bytes.length);
+ }
+ fos.flush();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fis != null) {
+ fis.close();
+ }
+ if (fos != null) {
+ fos.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return false;
+ }
+
private static class TempFlag {
AbsThreadTask threadTask;
int threadId;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java
index c5b6b29d..6bb06896 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java
@@ -24,7 +24,7 @@ import com.arialyy.aria.core.download.M3U8Listener;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.M3U8Exception;
-import com.arialyy.aria.util.ALog;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -83,7 +83,15 @@ public class M3U8VodUtil implements IUtil {
return;
}
mListener.onPre();
- getVodInfo();
+ // peer数量小于0,
+ M3U8Entity m3U8Entity = mWrapper.getEntity().getM3U8Entity();
+ if (m3U8Entity.getPeerNum() <= 0 || (m3U8Entity.isGenerateIndexFile() && !new File(
+ String.format(M3U8InfoThread.M3U8_INDEX_FORMAT,
+ mWrapper.getEntity().getFilePath())).exists())) {
+ getVodInfo();
+ } else {
+ mLoader.start();
+ }
}
/**
diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
index 56729989..c6480ce3 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
@@ -84,10 +84,10 @@ public abstract class AbsTarget {
/**
* 重置状态,将任务状态设置为未开始状态
* 注意:如果在后续方法调用链中没有调用 {@link NormalController#stop()}、{@link NormalController#cancel()}、
- * {@link NormalController#resume()}、{@link StartController#start()}、{@link StartController#add()}
+ * {@link NormalController#resume()}、{@link StartController#create()}、{@link StartController#add()}
* 等操作任务的方法,那么你需要调用{@link NormalController#save()}才能将修改保存到数据库
*/
- @CheckResult(suggest = "after use #start()、#stop()、#cancel()、#resume()、#save()?")
+ @CheckResult(suggest = "after use #create()、#stop()、#cancel()、#resume()、#save()?")
public TARGET resetState() {
getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT);
getTaskWrapper().setRefreshInfo(true);
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
index 91a1963a..f932d019 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
@@ -26,7 +26,8 @@ import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
-import com.arialyy.aria.core.queue.pool.DownloadSharePool;
+import com.arialyy.aria.core.queue.pool.DGLoadSharePool;
+import com.arialyy.aria.core.queue.pool.DLoadSharePool;
import com.arialyy.aria.core.queue.pool.UploadSharePool;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
@@ -47,9 +48,12 @@ public abstract class AbsTaskQueue extends DLoadExecutePool {
+ private final String TAG = "DGLoadExecutePool";
+
+ @Override protected int getMaxSize() {
+ return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().getMaxTaskNum();
+ }
+}
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadSharePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadSharePool.java
similarity index 72%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadSharePool.java
rename to Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadSharePool.java
index 4c07a16e..869612dc 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadSharePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadSharePool.java
@@ -19,21 +19,21 @@ package com.arialyy.aria.core.queue.pool;
* Created by Aria.Lao on 2017/7/17.
* 下载任务池,该池子为简单任务和任务组共用
*/
-public class DownloadSharePool {
- private static volatile DownloadSharePool INSTANCE;
+public class DGLoadSharePool {
+ private static volatile DGLoadSharePool INSTANCE;
- public DownloadExecutePool executePool;
+ public DGLoadExecutePool executePool;
public BaseCachePool cachePool;
- private DownloadSharePool() {
- executePool = new DownloadExecutePool<>();
+ private DGLoadSharePool() {
+ executePool = new DGLoadExecutePool<>();
cachePool = new BaseCachePool<>();
}
- public static DownloadSharePool getInstance() {
+ public static DGLoadSharePool getInstance() {
if (INSTANCE == null) {
- synchronized (DownloadSharePool.class) {
- INSTANCE = new DownloadSharePool();
+ synchronized (DGLoadSharePool.class) {
+ INSTANCE = new DGLoadSharePool();
}
}
return INSTANCE;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
similarity index 95%
rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java
rename to Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
index 25fcbcb0..81e5f340 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
@@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
* Created by AriaL on 2017/6/29.
* 单个下载任务的执行池
*/
-class DownloadExecutePool extends BaseExecutePool {
+class DLoadExecutePool extends BaseExecutePool {
private final String TAG = "DownloadExecutePool";
@Override protected int getMaxSize() {
@@ -34,7 +34,7 @@ class DownloadExecutePool extends BaseExecutePool {
}
@Override public boolean putTask(TASK task) {
- synchronized (DownloadExecutePool.class) {
+ synchronized (DLoadExecutePool.class) {
if (task == null) {
ALog.e(TAG, "任务不能为空!!");
return false;
diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadSharePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadSharePool.java
new file mode 100644
index 00000000..2ab96c9d
--- /dev/null
+++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadSharePool.java
@@ -0,0 +1,41 @@
+/*
+ * 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.queue.pool;
+
+/**
+ * Created by Aria.Lao on 2017/7/17.
+ * 下载任务池,该池子为简单任务和任务组共用
+ */
+public class DLoadSharePool {
+ private static volatile DLoadSharePool INSTANCE;
+
+ public DLoadExecutePool executePool;
+ public BaseCachePool cachePool;
+
+ private DLoadSharePool() {
+ executePool = new DLoadExecutePool<>();
+ cachePool = new BaseCachePool<>();
+ }
+
+ public static DLoadSharePool getInstance() {
+ if (INSTANCE == null) {
+ synchronized (DLoadSharePool.class) {
+ INSTANCE = new DLoadSharePool();
+ }
+ }
+ return INSTANCE;
+ }
+}
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 fe2c4ebf..aea9fca2 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
@@ -70,7 +70,7 @@ public class UploadReceiver extends AbsReceiver {
/**
* 用于任务停止、删除等操作
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
@@ -93,7 +93,7 @@ public class UploadReceiver extends AbsReceiver {
/**
* 加载FTP单文件上传任务,用于任务第一次上传,如果需要控制任务停止或删除等操作,请使用{@link #load(long)}
*
- * @param taskId 任务id,可从{@link AbsStartTarget#start()}、{@link AbsStartTarget#add()}、{@link
+ * @param taskId 任务id,可从{@link AbsStartTarget#create()}、{@link AbsStartTarget#add()}、{@link
* AbsEntity#getId()}读取任务id
*/
@CheckResult
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
index e50113e7..fae9bb31 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
@@ -38,7 +38,7 @@ class DBConfig {
static boolean DEBUG = false;
static Map mapping = new LinkedHashMap<>();
static String DB_NAME;
- static int VERSION = 52;
+ static int VERSION = 55;
/**
* 是否将数据库保存在Sd卡,{@code true} 是
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
index b1e8c319..3408a8af 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
@@ -106,7 +106,9 @@ class DelegateCommon extends AbsDelegate {
*/
boolean checkDataExist(SQLiteDatabase db, Class clazz, String... expression) {
db = checkDb(db);
- CheckUtil.checkSqlExpression(expression);
+ if (!CheckUtil.checkSqlExpression(expression)) {
+ return false;
+ }
String sql = String.format("SELECT rowid, * FROM %s WHERE %s ", CommonUtil.getClassName(clazz),
expression[0]);
sql = sql.replace("?", "%s");
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
index fad82460..0bb8dff0 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
@@ -198,7 +198,9 @@ class DelegateFind extends AbsDelegate {
.append(cTableName.concat(".").concat(m.entityColumn()));
String sql;
if (expression != null && expression.length > 0) {
- CheckUtil.checkSqlExpression(expression);
+ if (!CheckUtil.checkSqlExpression(expression)) {
+ return null;
+ }
sb.append(" WHERE ").append(expression[0]).append(" ");
sql = sb.toString();
sql = sql.replace("?", "%s");
@@ -318,7 +320,9 @@ class DelegateFind extends AbsDelegate {
*/
List findData(SQLiteDatabase db, Class clazz, String... expression) {
db = checkDb(db);
- CheckUtil.checkSqlExpression(expression);
+ if (!CheckUtil.checkSqlExpression(expression)) {
+ return null;
+ }
String sql = String.format("SELECT rowid, * FROM %s WHERE %s", CommonUtil.getClassName(clazz),
expression[0]);
String[] params = new String[expression.length - 1];
@@ -336,7 +340,9 @@ class DelegateFind extends AbsDelegate {
return null;
}
db = checkDb(db);
- CheckUtil.checkSqlExpression(expression);
+ if (!CheckUtil.checkSqlExpression(expression)) {
+ return null;
+ }
String sql = String.format("SELECT rowid, * FROM %s WHERE %s LIMIT %s,%s",
CommonUtil.getClassName(clazz),
expression[0], (page - 1) * num, num);
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
index ba1085a6..669e0280 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
@@ -34,13 +34,15 @@ class DelegateUpdate extends AbsDelegate {
private DelegateUpdate() {
}
- /**
+ /**
* 删除某条数据
*/
synchronized void delData(SQLiteDatabase db, Class clazz,
String... expression) {
db = checkDb(db);
- CheckUtil.checkSqlExpression(expression);
+ if (!CheckUtil.checkSqlExpression(expression)) {
+ return;
+ }
String sql = "DELETE FROM " + CommonUtil.getClassName(clazz) + " WHERE " + expression[0] + " ";
sql = sql.replace("?", "%s");
@@ -60,7 +62,7 @@ class DelegateUpdate extends AbsDelegate {
ContentValues values = createValues(dbEntity);
if (values != null) {
db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?",
- new String[] {String.valueOf(dbEntity.rowID)});
+ new String[] { String.valueOf(dbEntity.rowID) });
} else {
ALog.e(TAG, "更新记录失败,记录没有属性字段");
}
@@ -69,7 +71,7 @@ class DelegateUpdate extends AbsDelegate {
/**
* 更新多条记录
*/
- synchronized void updateManyData(SQLiteDatabase db, List dbEntities) {
+ synchronized void updateManyData(SQLiteDatabase db, List dbEntities) {
db = checkDb(db);
db.beginTransaction();
try {
@@ -84,7 +86,7 @@ class DelegateUpdate extends AbsDelegate {
if (value == null) {
ALog.e(TAG, "更新记录失败,记录没有属性字段");
} else {
- db.update(table, value, "rowid=?", new String[] {String.valueOf(entity.rowID)});
+ db.update(table, value, "rowid=?", new String[] { String.valueOf(entity.rowID) });
}
}
db.setTransactionSuccessful();
diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
index 1795cb79..4b2683db 100644
--- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
+++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
@@ -100,7 +100,7 @@ final class SqlHelper extends SQLiteOpenHelper {
handle360AriaUpdate(db);
} else if (oldVersion < 51) {
handle365Update(db);
- } else if (oldVersion < 52) {
+ } else if (oldVersion < 53) {
handle366Update(db);
} else {
handleDbUpdate(db, null, null);
@@ -240,12 +240,9 @@ final class SqlHelper extends SQLiteOpenHelper {
* 删除重复的repeat数据
*/
private void delRepeatThreadRecord(SQLiteDatabase db) {
- String repeatSql =
- "DELETE FROM ThreadRecord WHERE (taskKey, threadId, endLocation) "
- + "IN (SELECT taskKey, threadId, endLocation FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
- + "HAVING COUNT(*) > 1) AND rowid "
- + "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation "
- + "HAVING COUNT(*)> 1)";
+ String repeatSql = "DELETE FROM ThreadRecord WHERE (rowid) "
+ + "IN (SELECT rowid FROM ThreadRecord GROUP BY taskKey, threadId, endLocation HAVING COUNT(*) > 1) "
+ + "AND rowid NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY taskKey, threadId, endLocation HAVING COUNT(*)> 1)";
ALog.d(TAG, repeatSql);
db.execSQL(repeatSql);
}
@@ -262,6 +259,7 @@ final class SqlHelper extends SQLiteOpenHelper {
// 执行升级操作
handleDbUpdate(db, modifyMap, null);
+ delRepeatThreadRecord(db);
}
/**
diff --git a/Aria/src/main/java/com/arialyy/aria/util/BufferedRandomAccessFile.java b/Aria/src/main/java/com/arialyy/aria/util/BufferedRandomAccessFile.java
index 0e681d7c..1e7ba7b9 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/BufferedRandomAccessFile.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/BufferedRandomAccessFile.java
@@ -208,7 +208,7 @@ public final class BufferedRandomAccessFile extends RandomAccessFile {
if (pos >= this.hi_ || pos < this.lo_) {
// seeking outside of current buffer -- flush and read
this.flushBuffer();
- this.lo_ = pos & BuffMask_; // start at BuffSz boundary
+ this.lo_ = pos & BuffMask_; // create at BuffSz boundary
this.maxHi_ = this.lo_ + (long) this.buff_.length;
if (this.diskPos_ != this.lo_) {
super.seek(this.lo_);
diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
index 7a7c6be2..ef291be5 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.ParamException;
import java.io.File;
+import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -68,17 +69,22 @@ public class CheckUtil {
/**
* 检查sql的expression是否合法
+ *
+ * @return false 不合法
*/
- public static void checkSqlExpression(String... expression) {
+ public static boolean checkSqlExpression(String... expression) {
if (expression.length == 0) {
- throw new IllegalArgumentException("sql语句表达式不能为null");
+ ALog.e(TAG, "sql语句表达式不能为null");
+ return false;
}
if (expression.length == 1) {
- throw new IllegalArgumentException("表达式需要写入参数");
+ ALog.e(TAG, String.format("表达式需要写入参数,参数信息:%s", Arrays.toString(expression)));
+ return false;
}
String where = expression[0];
if (!where.contains("?")) {
- throw new IllegalArgumentException("请在where语句的'='后编写?");
+ ALog.e(TAG, String.format("请在where语句的'='后编写?,参数信息:%s", Arrays.toString(expression)));
+ return false;
}
Pattern pattern = Pattern.compile("\\?");
Matcher matcher = pattern.matcher(where);
@@ -87,11 +93,14 @@ public class CheckUtil {
count++;
}
if (count < expression.length - 1) {
- throw new IllegalArgumentException("条件语句的?个数不能小于参数个数");
+ ALog.e(TAG, String.format("条件语句的?个数不能小于参数个数,参数信息:%s", Arrays.toString(expression)));
+ return false;
}
if (count > expression.length - 1) {
- throw new IllegalArgumentException("条件语句的?个数不能大于参数个数");
+ ALog.e(TAG, String.format("条件语句的?个数不能大于参数个数, 参数信息:%s", Arrays.toString(expression)));
+ return false;
}
+ return true;
}
/**
diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
index 35482002..7973ca0e 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
@@ -29,10 +29,10 @@ import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.command.AbsGroupCmd;
import com.arialyy.aria.core.command.AbsNormalCmd;
import com.arialyy.aria.core.command.GroupCmdFactory;
-import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
+import com.arialyy.aria.core.inf.ITask;
import dalvik.system.DexFile;
import java.io.File;
import java.io.FileFilter;
@@ -41,9 +41,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
@@ -59,7 +56,6 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -99,102 +95,6 @@ public class CommonUtil {
return new String(str.getBytes(charSet), SERVER_CHARSET);
}
- /**
- * 删除文件
- *
- * @param path 文件路径
- * @return {@code true}删除成功、{@code false}删除失败
- */
- public static boolean deleteFile(String path) {
- if (TextUtils.isEmpty(path)) {
- ALog.e(TAG, "删除文件失败,路径为空");
- return false;
- }
- File file = new File(path);
- if (file.exists()) {
- final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
- if (file.renameTo(to)) {
- return to.delete();
- } else {
- return file.delete();
- }
- }
- return false;
- }
-
- /**
- * 将对象写入文件
- *
- * @param filePath 文件路径
- * @param data data数据必须实现{@link Serializable}接口
- */
- public static void writeObjToFile(String filePath, Object data) {
- if (!(data instanceof Serializable)) {
- ALog.e(TAG, "对象写入文件失败,data数据必须实现Serializable接口");
- return;
- }
- FileOutputStream ops = null;
- try {
- if (!createFile(filePath)) {
- return;
- }
- ops = new FileOutputStream(filePath);
- ObjectOutputStream oops = new ObjectOutputStream(ops);
- oops.writeObject(data);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (ops != null) {
- try {
- ops.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- /**
- * 从文件中读取对象
- *
- * @param filePath 文件路径
- * @return 如果读取成功,返回相应的Obj对象,读取失败,返回null
- */
- public static Object readObjFromFile(String filePath) {
- if (TextUtils.isEmpty(filePath)) {
- ALog.e(TAG, "文件路径为空");
- return null;
- }
- File file = new File(filePath);
- if (!file.exists()) {
- ALog.e(TAG, String.format("文件【%s】不存在", filePath));
- return null;
- }
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(filePath);
- ObjectInputStream oois = new ObjectInputStream(fis);
- return oois.readObject();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return null;
- }
-
/**
* 检查SD内存空间是否充足
*
@@ -409,32 +309,6 @@ public class CommonUtil {
return null;
}
- /**
- * 创建文件名,如果url链接有后缀名,则使用url中的后缀名
- *
- * @return url 的 hashKey
- */
- public static String createFileName(String url) {
- int end = url.indexOf("?");
- String tempUrl, fileName = "";
- if (end > 0) {
- tempUrl = url.substring(0, end);
- int tempEnd = tempUrl.lastIndexOf("/");
- if (tempEnd > 0) {
- fileName = tempUrl.substring(tempEnd + 1);
- }
- } else {
- int tempEnd = url.lastIndexOf("/");
- if (tempEnd > 0) {
- fileName = url.substring(tempEnd + 1);
- }
- }
- if (TextUtils.isEmpty(fileName)) {
- fileName = CommonUtil.keyToHashKey(url);
- }
- return fileName;
- }
-
/**
* 分割获取url,协议,ip/域名,端口,内容
*
@@ -720,8 +594,7 @@ public class CommonUtil {
/**
* 创建任务命令
*
- * @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}、{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}、{@link
- * ICmd#TASK_TYPE_UPLOAD}
+ * @param taskType {@link ITask#DOWNLOAD}、{@link ITask#DOWNLOAD_GROUP}、{@link ITask#UPLOAD}
*/
public static AbsNormalCmd createNormalCmd(T entity, int cmd,
int taskType) {
@@ -939,59 +812,6 @@ public class CommonUtil {
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "tb";
}
- /**
- * 创建目录 当目录不存在的时候创建文件,否则返回false
- */
- public static boolean createDir(String path) {
- File file = new File(path);
- if (!file.exists()) {
- if (!file.mkdirs()) {
- ALog.d(TAG, "创建失败,请检查路径和是否配置文件权限!");
- return false;
- }
- return true;
- }
- return false;
- }
-
- /**
- * 创建文件 当文件不存在的时候就创建一个文件。 如果文件存在,先删除原文件,然后重新创建一个新文件
- *
- * @return {@code true} 创建成功、{@code false} 创建失败
- */
- public static boolean createFile(String path) {
- if (TextUtils.isEmpty(path)) {
- ALog.e(TAG, "文件路径不能为null");
- return false;
- }
- File file = new File(path);
- if (file.getParentFile() == null || !file.getParentFile().exists()) {
- ALog.d(TAG, "目标文件所在路径不存在,准备创建……");
- if (!createDir(file.getParent())) {
- ALog.d(TAG, "创建目录文件所在的目录失败!文件路径【" + path + "】");
- }
- }
- // 创建目标文件
- if (file.exists()) {
- final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
- if (file.renameTo(to)) {
- to.delete();
- } else {
- file.delete();
- }
- }
- try {
- if (file.createNewFile()) {
- //ALog.d(TAG, "创建文件成功:" + file.getAbsolutePath());
- return true;
- }
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- return false;
- }
-
/**
* 通过文件名获取下载配置文件路径
*
@@ -1001,52 +821,4 @@ public class CommonUtil {
return AriaManager.APP.getFilesDir().getPath() + (isDownload ? AriaManager.DOWNLOAD_TEMP_DIR
: AriaManager.UPLOAD_TEMP_DIR) + fileName + ".properties";
}
-
- /**
- * 读取下载配置文件
- */
- public static Properties loadConfig(File file) {
- Properties properties = new Properties();
- FileInputStream fis = null;
- if (!file.exists()) {
- createFile(file.getPath());
- }
- try {
- fis = new FileInputStream(file);
- properties.load(fis);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (fis != null) {
- fis.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return properties;
- }
-
- /**
- * 保存配置文件
- */
- public static void saveConfig(File file, Properties properties) {
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(file, false);
- properties.store(fos, null);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (fos != null) {
- fos.flush();
- fos.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
}
\ No newline at end of file
diff --git a/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java b/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
index 5f96c59c..16d3e4f4 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
@@ -77,8 +77,8 @@ public class ErrorHelp {
PrintWriter writer = null;
try {
File file = new File(getLogPath());
- if(!file.exists()){
- CommonUtil.createFile(file.getPath());
+ if (!file.exists()) {
+ FileUtil.createFile(file.getPath());
}
writer = new PrintWriter(new FileWriter(file.getPath(), true));
writer.append(stringBuffer);
diff --git a/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java b/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
index 8fc0a22e..fcfe3efd 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
@@ -30,7 +30,10 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.SequenceInputStream;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
@@ -43,6 +46,7 @@ import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Properties;
import java.util.Scanner;
import java.util.regex.Pattern;
@@ -55,6 +59,181 @@ public class FileUtil {
private static final String EXTERNAL_STORAGE_PATH =
Environment.getExternalStorageDirectory().getPath();
+ /**
+ * 创建目录 当目录不存在的时候创建文件,否则返回false
+ */
+ public static boolean createDir(String path) {
+ File file = new File(path);
+ if (!file.exists()) {
+ if (!file.mkdirs()) {
+ ALog.d(TAG, "创建失败,请检查路径和是否配置文件权限!");
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 创建文件 当文件不存在的时候就创建一个文件。 如果文件存在,先删除原文件,然后重新创建一个新文件
+ *
+ * @return {@code true} 创建成功、{@code false} 创建失败
+ */
+ public static boolean createFile(String path) {
+ if (TextUtils.isEmpty(path)) {
+ ALog.e(TAG, "文件路径不能为null");
+ return false;
+ }
+ File file = new File(path);
+ if (file.getParentFile() == null || !file.getParentFile().exists()) {
+ ALog.d(TAG, "目标文件所在路径不存在,准备创建……");
+ if (!createDir(file.getParent())) {
+ ALog.d(TAG, "创建目录文件所在的目录失败!文件路径【" + path + "】");
+ }
+ }
+ // 创建目标文件
+ if (file.exists()) {
+ final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
+ if (file.renameTo(to)) {
+ to.delete();
+ } else {
+ file.delete();
+ }
+ }
+ try {
+ if (file.createNewFile()) {
+ //ALog.d(TAG, "创建文件成功:" + file.getAbsolutePath());
+ return true;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * 创建文件名,如果url链接有后缀名,则使用url中的后缀名
+ *
+ * @return url 的 hashKey
+ */
+ public static String createFileName(String url) {
+ int end = url.indexOf("?");
+ String tempUrl, fileName = "";
+ if (end > 0) {
+ tempUrl = url.substring(0, end);
+ int tempEnd = tempUrl.lastIndexOf("/");
+ if (tempEnd > 0) {
+ fileName = tempUrl.substring(tempEnd + 1);
+ }
+ } else {
+ int tempEnd = url.lastIndexOf("/");
+ if (tempEnd > 0) {
+ fileName = url.substring(tempEnd + 1);
+ }
+ }
+ if (TextUtils.isEmpty(fileName)) {
+ fileName = CommonUtil.keyToHashKey(url);
+ }
+ return fileName;
+ }
+
+ /**
+ * 删除文件
+ *
+ * @param path 文件路径
+ * @return {@code true}删除成功、{@code false}删除失败
+ */
+ public static boolean deleteFile(String path) {
+ if (TextUtils.isEmpty(path)) {
+ ALog.e(TAG, "删除文件失败,路径为空");
+ return false;
+ }
+ File file = new File(path);
+ if (file.exists()) {
+ final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
+ if (file.renameTo(to)) {
+ return to.delete();
+ } else {
+ return file.delete();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 将对象写入文件
+ *
+ * @param filePath 文件路径
+ * @param data data数据必须实现{@link Serializable}接口
+ */
+ public static void writeObjToFile(String filePath, Object data) {
+ if (!(data instanceof Serializable)) {
+ ALog.e(TAG, "对象写入文件失败,data数据必须实现Serializable接口");
+ return;
+ }
+ FileOutputStream ops = null;
+ try {
+ if (!createFile(filePath)) {
+ return;
+ }
+ ops = new FileOutputStream(filePath);
+ ObjectOutputStream oops = new ObjectOutputStream(ops);
+ oops.writeObject(data);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (ops != null) {
+ try {
+ ops.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * 从文件中读取对象
+ *
+ * @param filePath 文件路径
+ * @return 如果读取成功,返回相应的Obj对象,读取失败,返回null
+ */
+ public static Object readObjFromFile(String filePath) {
+ if (TextUtils.isEmpty(filePath)) {
+ ALog.e(TAG, "文件路径为空");
+ return null;
+ }
+ File file = new File(filePath);
+ if (!file.exists()) {
+ ALog.e(TAG, String.format("文件【%s】不存在", filePath));
+ return null;
+ }
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(filePath);
+ ObjectInputStream oois = new ObjectInputStream(fis);
+ return oois.readObject();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+
/**
* 合并文件
*
@@ -186,6 +365,54 @@ public class FileUtil {
return paths;
}
+ /**
+ * 读取下载配置文件
+ */
+ public static Properties loadConfig(File file) {
+ Properties properties = new Properties();
+ FileInputStream fis = null;
+ if (!file.exists()) {
+ createFile(file.getPath());
+ }
+ try {
+ fis = new FileInputStream(file);
+ properties.load(fis);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fis != null) {
+ fis.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return properties;
+ }
+
+ /**
+ * 保存配置文件
+ */
+ public static void saveConfig(File file, Properties properties) {
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(file, false);
+ properties.store(fos, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fos != null) {
+ fos.flush();
+ fos.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
/**
* getSDPathList
*/
@@ -258,8 +485,10 @@ public class FileUtil {
}
/**
- * Raturns all available SD-Cards in the system (include emulated) Warning: Hack! Based on Android source code of version 4.3
- * (API 18) Because there is no standard way to get it. TODO: Test on future Android versions 4.2+
+ * Raturns all available SD-Cards in the system (include emulated) Warning: Hack! Based on Android
+ * source code of version 4.3
+ * (API 18) Because there is no standard way to get it. TODO: Test on future Android versions
+ * 4.2+
*
* @return paths to all available SD-Cards in the system (include emulated)
*/
@@ -322,9 +551,11 @@ public class FileUtil {
}
/**
- * Scan the /proc/mounts file and look for lines like this: /dev/block/vold/179:1 /mnt/sdcard vfat
+ * Scan the /proc/mounts file and look for lines like this: /dev/block/vold/179:1 /mnt/sdcard
+ * vfat
* rw,dirsync,nosuid,nodev,noexec ,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,
- * codepage=cp437,iocharset= iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0 When one is found, split it into its
+ * codepage=cp437,iocharset= iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0 When one is
+ * found, split it into its
* elements and then pull out the path to the that mount point and add it to the arraylist
*/
private static List readMountsFile() {
diff --git a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
index c5d5b522..5f83d08c 100644
--- a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
+++ b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java
@@ -22,6 +22,7 @@ import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.common.ThreadRecord;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
+import com.arialyy.aria.core.download.m3u8.M3U8Entity;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.upload.UploadEntity;
@@ -237,6 +238,8 @@ public class RecordUtil {
ALog.i(TAG, "删除任务记录");
DbEntity.deleteData(ThreadRecord.class, "taskKey=?", filePath);
DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath);
+ // 处理m3u8实体的删除
+ DbEntity.deleteData(M3U8Entity.class, "filePath=?", filePath);
}
/**
diff --git a/DEV_LOG.md b/DEV_LOG.md
index 6da61d7d..b08873fc 100644
--- a/DEV_LOG.md
+++ b/DEV_LOG.md
@@ -2,7 +2,16 @@
+ v_3.7
- 适配androidX
- 修复组合任务,恢复下载,会出现进度显示为0的问题
- + v_3.6.5
+ + v_3.6.6
+ - fix bug https://github.com/AriaLyy/Aria/issues/426
+ - fix bug https://github.com/AriaLyy/Aria/issues/429
+ - fix bug https://github.com/AriaLyy/Aria/issues/428
+ - fix bug https://github.com/AriaLyy/Aria/issues/427
+ - fix bug https://github.com/AriaLyy/Aria/issues/431
+ - fix bug https://github.com/AriaLyy/Aria/issues/441
+ - 修复普通下载任务、组合任务共享执行队列、缓存池的问题
+ - 修复组合任务启动失败时,`DownloadGroupEntity`的状态变为执行中的问题
+ + v_3.6.5 (2019/7/17)
- fix bug https://github.com/AriaLyy/Aria/issues/403
- fix bug https://github.com/AriaLyy/Aria/issues/414
- fix bug https://github.com/AriaLyy/Aria/issues/406
diff --git a/README.md b/README.md
index 99598aee..1849c8fd 100644
--- a/README.md
+++ b/README.md
@@ -72,12 +72,21 @@ __⚠️注意:3.5.4以下版本升级时,需要更新[配置文件](https:/
## 使用Aria
### 基本使用
-例子为单任务下载,只需要很简单的代码,便可以实现下载功能
+例子为单任务下载,只需要很简单的代码,便可以实现下载功能。
+* 创建任务
```java
- Aria.download(this)
+ long taskId = Aria.download(this)
.load(DOWNLOAD_URL) //读取下载地址
.setFilePath(DOWNLOAD_PATH) //设置文件保存的完整路径
- .start(); //启动下载
+ .create(); //创建并启动下载
+ ```
+* 停止\恢复任务
+ ```java
+ Aria.download(this)
+ .load(taskId) //读取任务id
+ .stop(); // 停止任务
+ //.resume(); // 恢复任务
+
```
### 任务状态的获取
diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml
index 4956bd53..af36efe6 100644
--- a/app/src/main/assets/aria_config.xml
+++ b/app/src/main/assets/aria_config.xml
@@ -113,7 +113,7 @@
-
+
@@ -131,7 +131,7 @@
-
+
diff --git a/app/src/main/assets/help_code/HttpDownload.java b/app/src/main/assets/help_code/HttpDownload.java
index 61d82669..6482e9ff 100644
--- a/app/src/main/assets/help_code/HttpDownload.java
+++ b/app/src/main/assets/help_code/HttpDownload.java
@@ -22,16 +22,11 @@ import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
-import com.arialyy.aria.core.common.ftp.FtpInterceptHandler;
-import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor;
import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.upload.UploadEntity;
-import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import java.io.File;
-import java.util.List;
/**
* Created by lyy on 2017/7/28. HTTP 文件下载demo
@@ -64,7 +59,7 @@ public class FtpUpload extends Activity {
//.addHeader(key, value) // 添加头
//.asPost() //或 asGet()
//.setParam() // 设置参数
- .start();
+ .create();
}
break;
case R.id.cancel:
diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java
index 210ee1fb..831988fb 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialog.java
@@ -28,7 +28,6 @@ import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
import com.arialyy.simple.R;
-import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
/**
@@ -40,7 +39,7 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
private Button mCancel;
private TextView mSize;
private TextView mSpeed;
- private DownloadEntity mEntity;
+ private long mTaskId = -1;
private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/4b/d7/e04b308d9cd7f0ad4cac18d1a514544c.apk";
@@ -61,13 +60,14 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
mCancel = findViewById(R.id.cancel);
mSize = findViewById(R.id.size);
mSpeed = findViewById(R.id.speed);
- mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
- if (mEntity != null) {
- mSize.setText(CommonUtil.formatFileSize(mEntity.getFileSize()));
- int p = (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize());
+ DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
+ if (entity != null) {
+ mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
+ int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
mPb.setProgress(p);
- int state = mEntity.getState();
+ int state = entity.getState();
setBtState(state != DownloadEntity.STATE_RUNNING);
+ mTaskId = entity.getId();
} else {
setBtState(true);
}
@@ -79,28 +79,27 @@ public class DownloadDialog extends AbsDialog implements View.OnClickListener {
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
- if (!AppUtil.chekEntityValid(mEntity)) {
- Aria.download(this)
+ if (mTaskId == -1) {
+ mTaskId = Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
- .start();
+ .create();
mStart.setText(getContext().getString(R.string.stop));
break;
}
- if (Aria.download(this).load(mEntity.getId()).isRunning()) {
- Aria.download(this).load(mEntity.getId()).stop();
+ if (Aria.download(this).load(mTaskId).isRunning()) {
+ Aria.download(this).load(mTaskId).stop();
mStart.setText(getContext().getString(R.string.resume));
} else {
- Aria.download(this).load(mEntity.getId()).resume();
+ Aria.download(this).load(mTaskId).resume();
mStart.setText(getContext().getString(R.string.stop));
}
break;
case R.id.cancel:
- if (AppUtil.chekEntityValid(mEntity)) {
- Aria.download(this).load(mEntity.getId()).cancel();
- mStart.setText(getContext().getString(R.string.start));
- }
+ Aria.download(this).load(mTaskId).cancel();
+ mTaskId = -1;
+ mStart.setText(getContext().getString(R.string.start));
break;
}
}
diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java
index 89fbc527..b6755c18 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadDialogFragment.java
@@ -106,7 +106,7 @@ import com.arialyy.simple.util.AppUtil;
Aria.download(getContext())
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
- .start();
+ .create();
getBinding().setStateStr(getString(R.string.stop));
break;
}
diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java
index 5342ab59..95e5856d 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadPopupWindow.java
@@ -31,7 +31,6 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsPopupWindow;
import com.arialyy.simple.R;
-import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
/**
@@ -43,7 +42,7 @@ public class DownloadPopupWindow extends AbsPopupWindow implements View.OnClickL
private Button mCancel;
private TextView mSize;
private TextView mSpeed;
- private DownloadEntity mEntity;
+ private long mTaskId = -1;
private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/25/57/2e25bd9d4557ba31e9beebacfaf9e804.apk";
@@ -67,15 +66,16 @@ public class DownloadPopupWindow extends AbsPopupWindow implements View.OnClickL
mStart.setOnClickListener(this);
mCancel.setOnClickListener(this);
- mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
- if (mEntity != null) {
- mPb.setProgress(mEntity.getPercent());
- mSize.setText(CommonUtil.formatFileSize(mEntity.getFileSize()));
- if (mEntity.getState() == IEntity.STATE_RUNNING) {
+ DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
+ if (entity != null) {
+ mPb.setProgress(entity.getPercent());
+ mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
+ if (entity.getState() == IEntity.STATE_RUNNING) {
mStart.setText(getContext().getString(R.string.stop));
} else {
mStart.setText(getContext().getString(R.string.resume));
}
+ mTaskId = entity.getId();
} else {
mStart.setText(getContext().getString(R.string.start));
}
@@ -86,28 +86,28 @@ public class DownloadPopupWindow extends AbsPopupWindow implements View.OnClickL
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
- if (!AppUtil.chekEntityValid(mEntity)) {
+ if (mTaskId != -1) {
Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
- .start();
+ .create();
mStart.setText(getContext().getString(R.string.stop));
break;
}
- if (Aria.download(this).load(mEntity.getId()).isRunning()) {
- Aria.download(this).load(mEntity.getId()).stop();
+ if (Aria.download(this).load(mTaskId).isRunning()) {
+ Aria.download(this).load(mTaskId).stop();
mStart.setText(getContext().getString(R.string.resume));
} else {
- Aria.download(this).load(mEntity.getId()).resume();
+ Aria.download(this).load(mTaskId).resume();
mStart.setText(getContext().getString(R.string.stop));
}
break;
case R.id.cancel:
- if (AppUtil.chekEntityValid(mEntity)) {
- Aria.download(this).load(mEntity.getId()).cancel();
- }
+ Aria.download(this).load(mTaskId).cancel();
+ mStart.setText(getContext().getResources().getString(R.string.start));
+ mTaskId = -1;
break;
}
}
diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
index f2676900..35bb96db 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
@@ -96,7 +96,7 @@ public class FtpDownloadActivity extends BaseActivity() {
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.useServerFileName(true)
.setFilePath(mFilePath!!, true)
- .start()
+ .create()
}
override fun onStop() {
diff --git a/app/src/main/java/com/arialyy/simple/core/download/SimpleNotification.java b/app/src/main/java/com/arialyy/simple/core/download/SimpleNotification.java
index 3dc7b0c2..f3ac70df 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/SimpleNotification.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/SimpleNotification.java
@@ -54,11 +54,11 @@
// Aria.download(this).register();
// }
//
-// public void start() {
+// public void create() {
// Aria.download(this)
// .load(DOWNLOAD_URL)
// .setFilePath(Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
-// .start();
+// .create();
// }
//
// public void stop() {
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 099a3a1c..3db16e1d 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
@@ -306,7 +306,7 @@ public class SingleTaskActivity extends BaseActivity {
.option()
.addHeader("1", "@")
.controller(ControllerType.START_CONTROLLER)
- .start();
+ .create();
}
@Override
diff --git a/app/src/main/java/com/arialyy/simple/core/download/fragment_download/DownloadFragment.java b/app/src/main/java/com/arialyy/simple/core/download/fragment_download/DownloadFragment.java
index 017c53ae..6192db13 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/fragment_download/DownloadFragment.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/fragment_download/DownloadFragment.java
@@ -29,7 +29,6 @@ import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsFragment;
import com.arialyy.simple.R;
import com.arialyy.simple.databinding.FragmentDownloadBinding;
-import com.arialyy.simple.util.AppUtil;
/**
* Created by lyy on 2017/1/4.
@@ -38,7 +37,7 @@ public class DownloadFragment extends AbsFragment
implements View.OnClickListener {
Button mStart;
Button mCancel;
- private DownloadEntity mEntity;
+ private long mTaskId = -1;
private static final String DOWNLOAD_URL =
"https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
@@ -49,16 +48,17 @@ public class DownloadFragment extends AbsFragment
mStart.setOnClickListener(this);
mCancel.setOnClickListener(this);
- mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
- if (mEntity != null) {
- getBinding().setFileSize(CommonUtil.formatFileSize(mEntity.getFileSize()));
- int state = mEntity.getState();
- getBinding().setProgress(mEntity.getPercent());
- if (mEntity.getState() == IEntity.STATE_RUNNING) {
+ DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
+ if (entity != null) {
+ getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
+ int state = entity.getState();
+ getBinding().setProgress(entity.getPercent());
+ if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop));
} else {
getBinding().setStateStr(getString(R.string.resume));
}
+ mTaskId = entity.getId();
} else {
getBinding().setStateStr(getString(R.string.start));
}
@@ -68,27 +68,27 @@ public class DownloadFragment extends AbsFragment
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
- if (!AppUtil.chekEntityValid(mEntity)) {
- Aria.download(this)
+ if (mTaskId == -1) {
+ mTaskId = Aria.download(this)
.load(DOWNLOAD_URL)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
- .start();
+ .create();
getBinding().setStateStr(getString(R.string.stop));
break;
}
- if (Aria.download(this).load(mEntity.getId()).isRunning()) {
- Aria.download(this).load(mEntity.getId()).stop();
+ if (Aria.download(this).load(mTaskId).isRunning()) {
+ Aria.download(this).load(mTaskId).stop();
getBinding().setStateStr(getString(R.string.resume));
} else {
- Aria.download(this).load(mEntity.getId()).resume();
+ Aria.download(this).load(mTaskId).resume();
getBinding().setStateStr(getString(R.string.stop));
}
break;
case R.id.cancel:
- if (AppUtil.chekEntityValid(mEntity)) {
- Aria.download(this).load(mEntity.getId()).cancel();
- }
+ Aria.download(this).load(mTaskId).cancel();
+ getBinding().setStateStr(getString(R.string.start));
+ mTaskId = -1;
break;
}
}
diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
index 70e3b102..db13ddc4 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
@@ -113,7 +113,7 @@ public class DownloadGroupActivity extends BaseActivity
// return newUrls;
// }
//})
- .start();
+ .create();
}
@Override protected void dataCallback(int result, Object data) {
diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
index c807d983..11e503c8 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
@@ -36,7 +36,7 @@ import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.m3u8.IBandWidthUrlConverter;
import com.arialyy.aria.core.download.m3u8.ITsMergeHandler;
import com.arialyy.aria.core.download.m3u8.IVodTsUrlConverter;
-import com.arialyy.aria.core.download.m3u8.M3U8KeyInfo;
+import com.arialyy.aria.core.download.m3u8.M3U8Entity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@@ -169,7 +169,7 @@ public class M3U8VodDLoadActivity extends BaseActivity {
@M3U8.onPeerStart
void onPeerStart(String m3u8Url, String peerPath, int peerIndex) {
- //ALog.d(TAG, "peer start, path: " + peerPath + ", index: " + peerIndex);
+ //ALog.d(TAG, "peer create, path: " + peerPath + ", index: " + peerIndex);
}
@M3U8.onPeerComplete
@@ -335,13 +335,14 @@ public class M3U8VodDLoadActivity extends BaseActivity {
}
})
.setMergeHandler(new ITsMergeHandler() {
- public boolean merge(@Nullable M3U8KeyInfo keyInfo, List tsPath) {
+ public boolean merge(@Nullable M3U8Entity m3U8Entity, List tsPath) {
ALog.d(TAG, "合并TS....");
return false;
}
})
+ .generateIndexFile()
.controller(ControllerType.START_CONTROLLER)
- .start();
+ .create();
}
private Class c = StartController.class;
diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
index 221f704a..c31137ad 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/VideoPlayerFragment.java
@@ -41,7 +41,11 @@ public class VideoPlayerFragment extends BaseFragment peerInfos = entity.getM3U8Entity().getCompletedPeer();
+ M3U8Entity m3U8Entity = entity.getM3U8Entity();
+ if (m3U8Entity == null) {
+ return;
+ }
+ List peerInfos = m3U8Entity.getCompletedPeer();
if (peerInfos != null) {
for (M3U8Entity.PeerInfo info : peerInfos) {
mPlayers.put(info.peerId, info.peerPath);
@@ -72,7 +76,9 @@ public class VideoPlayerFragment extends BaseFragment {
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
- //module.start(URL);
+ //module.create(URL);
module.startFtp(URL);
break;
case R.id.stop:
@@ -62,7 +62,7 @@ public class AnyRunActivity extends BaseActivity {
// .updateUrl(newUrl)
// .login("lao", "123456")
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/")
- // .start();
+ // .create();
break;
}
}
diff --git a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
index e0d9d6f6..9bc8d84c 100644
--- a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
@@ -132,7 +132,7 @@ public class FtpUploadActivity extends BaseActivity {
.option()
.login("8L8e", "8guD")
.controller(ControllerType.START_CONTROLLER)
- .start();
+ .create();
getBinding().setStateStr(getString(R.string.stop));
break;
}
diff --git a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
index a4e37d5b..4d1b288c 100644
--- a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
@@ -76,7 +76,7 @@ public class HttpUploadActivity extends BaseActivity {
"http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}")
//.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file")
//.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933")
- .start();
+ .create();
}
void stop() {
@@ -95,7 +95,7 @@ public class HttpUploadActivity extends BaseActivity {
}
@Upload.onTaskStart public void taskStart(UploadTask task) {
- L.d(TAG, "upload start,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath())));
+ L.d(TAG, "upload create,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath())));
getBinding().setFileSize(task.getConvertFileSize());
}
diff --git a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java
index f7e91123..4e1d7406 100644
--- a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java
+++ b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java
@@ -92,7 +92,7 @@ public class AnyRunnModule {
.load(url)
.setFilePath(path)
.resetState()
- .start();
+ .create();
} else {
Aria.download(this).load(mEntity.getId()).resume();
}
@@ -114,7 +114,7 @@ public class AnyRunnModule {
.setAlias("www.laoyuyu.me")
.setStorePass("123456")
.controller(ControllerType.START_CONTROLLER)
- .start();
+ .create();
} else {
Aria.download(this).load(mEntity.getId()).resume();
}
diff --git a/app/src/main/java/com/arialyy/simple/util/AppUtil.java b/app/src/main/java/com/arialyy/simple/util/AppUtil.java
index 52fde5a6..e22e75c7 100644
--- a/app/src/main/java/com/arialyy/simple/util/AppUtil.java
+++ b/app/src/main/java/com/arialyy/simple/util/AppUtil.java
@@ -22,11 +22,12 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
-import androidx.core.content.FileProvider;
import android.text.TextUtils;
+import androidx.core.content.FileProvider;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
+import com.arialyy.aria.util.FileUtil;
import com.arialyy.simple.BuildConfig;
import java.io.File;
import java.io.IOException;
@@ -51,7 +52,7 @@ public class AppUtil {
String path = String.format("%s/code/%s", context.getFilesDir().getPath(), fileName);
File ftpCode = new File(path);
if (!ftpCode.exists()) {
- CommonUtil.createFile(path);
+ FileUtil.createFile(path);
CommonUtil.createFileFormInputStream(context.getAssets()
.open(String.format("help_code/%s", fileName)),
path);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2e4adb69..397f0771 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -106,16 +106,13 @@
-
-
-
- - http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk
-
+ - https://downs.muzhiwan.com/2019/06/19/com.and.games505.TerrariaPaid5d0a074e451c0.gpk
+ - https://downs.muzhiwan.com/2017/03/28/com.xyzstudio_58da07426e959.apk
- http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk
- - https://atom-installer.github.com/v1.13.0/AtomSetup.exe1
+
- http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk
@@ -125,8 +122,8 @@
- - http://apk500.bce.baidu-mgame.com/game/883000/883227/20170828102306_oem_5502845.apk?r=1
- - http://static.gaoshouyou.com/d/92/12/5592a647b8126755647abbe8074fde39.apk
+ - https://downs.muzhiwan.com/2019/07/23/com.amazid.me_5d36bade614d9.apk
+ - https://downs.muzhiwan.com/2019/07/30/com.counter.terrorist.attack.fps.sniper.fight_5d3fe8f0a7edf.apk
@@ -135,8 +132,8 @@
- - 王者荣耀.apk
- - 战斗吧剑灵.apk
+ - 泰拉瑞亚.apk
+ - 疯狂屁股.apk
@@ -151,8 +148,8 @@
- - 部落冲突.apk
- - 城堡争霸.apk
+ - 神奇的绳索英雄.apk
+ - 自由火力反击.apk
diff --git a/build.gradle b/build.gradle
index 813d3bac..b0fe1385 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,7 +43,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
- publishVersion = '3.6.6_beta_2'
+ publishVersion = '3.6.6_beta_3'
// publishVersion = '1.0.4' //FTP插件
repoName='maven'
desc = 'android 下载框架'