Merge branch 'v_3.0'
This commit is contained in:
@ -7,8 +7,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 101
|
||||
versionName "3.0.2"
|
||||
versionCode 102
|
||||
versionName "3.0.3"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -28,17 +28,14 @@ import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.inf.ICmd;
|
||||
import com.arialyy.aria.core.inf.IReceiver;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadReceiver;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.DbUtil;
|
||||
import com.arialyy.aria.util.CAConfiguration;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import com.arialyy.aria.util.Speed;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -60,6 +57,7 @@ import java.util.Map;
|
||||
private Map<String, IReceiver> mReceivers = new HashMap<>();
|
||||
public static Context APP;
|
||||
private List<ICmd> mCommands = new ArrayList<>();
|
||||
private Configuration mConfig;
|
||||
|
||||
private AriaManager(Context context) {
|
||||
DbUtil.init(context.getApplicationContext());
|
||||
@ -84,7 +82,7 @@ import java.util.Map;
|
||||
* 设置最大下载速度
|
||||
*/
|
||||
public void setMaxSpeed(Speed speed) {
|
||||
Configuration.getInstance().setMaxSpeed(speed);
|
||||
Configuration_1.getInstance().setMaxSpeed(speed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +157,7 @@ import java.util.Map;
|
||||
* 设置下载超时时间
|
||||
*/
|
||||
@Deprecated private AriaManager setTimeOut(int timeOut) {
|
||||
Configuration.getInstance().setTimeOut(timeOut);
|
||||
Configuration_1.getInstance().setTimeOut(timeOut);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -167,7 +165,7 @@ import java.util.Map;
|
||||
* 设置失败重试次数
|
||||
*/
|
||||
public AriaManager setReTryNum(int reTryNum) {
|
||||
Configuration.getInstance().setReTryNum(reTryNum);
|
||||
Configuration_1.getInstance().setReTryNum(reTryNum);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -175,7 +173,7 @@ import java.util.Map;
|
||||
* 设置失败重试间隔
|
||||
*/
|
||||
public AriaManager setReTryInterval(int interval) {
|
||||
Configuration.getInstance().setReTryInterval(interval);
|
||||
Configuration_1.getInstance().setReTryInterval(interval);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -183,7 +181,7 @@ import java.util.Map;
|
||||
* 是否打开下载广播
|
||||
*/
|
||||
public AriaManager openBroadcast(boolean open) {
|
||||
Configuration.getInstance().setOpenBroadcast(open);
|
||||
Configuration_1.getInstance().setOpenBroadcast(open);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
78
Aria/src/main/java/com/arialyy/aria/core/Configuration.java
Normal file
78
Aria/src/main/java/com/arialyy/aria/core/Configuration.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2016/12/8.
|
||||
* 信息配置
|
||||
*/
|
||||
class Configuration {
|
||||
private static final String TAG = "Configuration";
|
||||
private static final String CONFIG_FILE = "/Aria/ADConfig.properties";
|
||||
private static final String CONFIG_KEY = "ARIA_CONFIG";
|
||||
|
||||
/**
|
||||
* 通用配置
|
||||
*/
|
||||
static class BaseConfig {
|
||||
public boolean isOpenBreadCast = false;
|
||||
/**
|
||||
* 任务队列最大任务数, 默认为2
|
||||
*/
|
||||
public int maxQueueNum = 2;
|
||||
/**
|
||||
* 下载失败,重试次数,默认为10
|
||||
*/
|
||||
public int reTryNum = 10;
|
||||
/**
|
||||
* 设置重试间隔,单位为毫秒,默认2000毫秒
|
||||
*/
|
||||
public long reTryInterval = 2000;
|
||||
/**
|
||||
* 设置url连接超时时间,单位为毫秒,默认5000毫秒
|
||||
*/
|
||||
public long connectTimeOut = 5000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载配置
|
||||
*/
|
||||
public static class DownloadConfig extends BaseConfig {
|
||||
/**
|
||||
* 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
|
||||
*/
|
||||
public long readTimeout = 20 * 1000;
|
||||
/**
|
||||
* 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢
|
||||
*/
|
||||
public int buffSize = 8192;
|
||||
/**
|
||||
* 设置https ca 证书信息;path 为assets目录下的CA证书完整路径
|
||||
*/
|
||||
public String caPath;
|
||||
/**
|
||||
* name 为CA证书名
|
||||
*/
|
||||
public String caName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传配置
|
||||
*/
|
||||
public static class UploadConfig extends BaseConfig {
|
||||
|
||||
}
|
||||
}
|
@ -35,12 +35,17 @@ public abstract class AbsCmd<T extends ITaskEntity> implements ICmd {
|
||||
T mEntity;
|
||||
String TAG;
|
||||
String mTargetName;
|
||||
/**
|
||||
* 能否执行命令
|
||||
*/
|
||||
boolean cancelExe = true;
|
||||
|
||||
/**
|
||||
* @param targetName 产生任务的对象名
|
||||
*/
|
||||
AbsCmd(String targetName, T entity) {
|
||||
CheckUtil.checkCmdEntity(entity);
|
||||
cancelExe = CheckUtil.checkCmdEntity(entity,
|
||||
!(this instanceof CancelCmd) || !(this instanceof StopCmd));
|
||||
mTargetName = targetName;
|
||||
mEntity = entity;
|
||||
TAG = CommonUtil.getClassName(this);
|
||||
|
@ -31,6 +31,7 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
mQueue.createTask(mTargetName, mEntity);
|
||||
@ -39,20 +40,4 @@ class AddCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
}
|
||||
|
||||
//AddCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//AddCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// mQueue.createTask(mTargetName, mEntity);
|
||||
// } else {
|
||||
// Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
|
||||
// }
|
||||
//}
|
||||
}
|
@ -29,6 +29,7 @@ class CancelCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
@ -40,25 +41,4 @@ class CancelCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
mQueue.cancelTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
//CancelCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//CancelCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// }
|
||||
// if (task != null) {
|
||||
// if (mTargetName != null) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// }
|
||||
// mQueue.cancelTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -31,6 +31,7 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
task = mQueue.createTask(mTargetName, mEntity);
|
||||
@ -41,22 +42,4 @@ class StartCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
}
|
||||
|
||||
//StartCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//StartCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// }
|
||||
// if (task != null) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// mQueue.startTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -33,6 +33,7 @@ class StopCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
if (!cancelExe) return;
|
||||
ITask task = mQueue.getTask(mEntity.getEntity());
|
||||
if (task == null) {
|
||||
if (mEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
|
||||
@ -48,29 +49,4 @@ class StopCmd<T extends ITaskEntity> extends AbsCmd<T> {
|
||||
mQueue.stopTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
//StopCmd(DownloadTaskEntity entity) {
|
||||
// super(entity);
|
||||
//}
|
||||
//
|
||||
//StopCmd(String targetName, DownloadTaskEntity entity) {
|
||||
// super(targetName, entity);
|
||||
//}
|
||||
//
|
||||
//@Override public void executeCmd() {
|
||||
// DownloadTask task = mQueue.getTask(mEntity.downloadEntity);
|
||||
// if (task == null) {
|
||||
// if (mEntity.downloadEntity.getState() == DownloadEntity.STATE_RUNNING) {
|
||||
// task = mQueue.createTask(mTargetName, mEntity);
|
||||
// mQueue.stopTask(task);
|
||||
// } else {
|
||||
// Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
|
||||
// }
|
||||
// } else {
|
||||
// if (!TextUtils.isEmpty(mTargetName)) {
|
||||
// task.setTargetName(mTargetName);
|
||||
// }
|
||||
// mQueue.stopTask(task);
|
||||
// }
|
||||
//}
|
||||
}
|
@ -43,7 +43,7 @@ class ConnectionHelp {
|
||||
if (urlConn instanceof HttpsURLConnection) {
|
||||
conn = (HttpsURLConnection) urlConn;
|
||||
SSLContext sslContext =
|
||||
SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_ALIAS);
|
||||
SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_PATH);
|
||||
if (sslContext == null) {
|
||||
sslContext = SSLContextUtil.getDefaultSLLContext();
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
/**
|
||||
* 重定向后,新url的key,默认为location
|
||||
*/
|
||||
public void setRedirectUrlKey(String redirectUrlKey) {
|
||||
public DownloadTarget setRedirectUrlKey(String redirectUrlKey) {
|
||||
super._setRedirectUrlKey(redirectUrlKey);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,6 +74,13 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载任务是否存在
|
||||
*/
|
||||
@Override public boolean taskExists(String downloadUrl) {
|
||||
return DownloadTaskQueue.getInstance().getTask(downloadUrl) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求类型
|
||||
*
|
||||
|
@ -22,13 +22,12 @@ import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
@ -138,6 +137,10 @@ public class DownloadTask implements ITask {
|
||||
this.mTargetName = targetName;
|
||||
}
|
||||
|
||||
@Override public void removeRecord() {
|
||||
mEntity.deleteData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止下载
|
||||
*/
|
||||
@ -162,10 +165,7 @@ public class DownloadTask implements ITask {
|
||||
* 取消下载
|
||||
*/
|
||||
@Override public void cancel() {
|
||||
if (mUtil.isDownloading()) {
|
||||
mUtil.cancelDownload();
|
||||
} else {
|
||||
// 如果任务不是下载状态
|
||||
if (!mEntity.isDownloadComplete()) {
|
||||
mUtil.cancelDownload();
|
||||
mUtil.delConfigFile();
|
||||
mUtil.delTempFile();
|
||||
@ -178,6 +178,22 @@ public class DownloadTask implements ITask {
|
||||
intent.putExtra(Aria.ENTITY, mEntity);
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
//if (mEntity.isDownloadComplete()) {
|
||||
// //mUtil.cancelDownload();
|
||||
//} else {
|
||||
// // 如果任务不是下载状态
|
||||
// mUtil.cancelDownload();
|
||||
// mUtil.delConfigFile();
|
||||
// mUtil.delTempFile();
|
||||
// mEntity.deleteData();
|
||||
// if (mOutHandler != null) {
|
||||
// mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
|
||||
// }
|
||||
// //发送取消下载的广播
|
||||
// Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
|
||||
// intent.putExtra(Aria.ENTITY, mEntity);
|
||||
// mContext.sendBroadcast(intent);
|
||||
//}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@ -187,7 +203,8 @@ public class DownloadTask implements ITask {
|
||||
String targetName;
|
||||
|
||||
public Builder(String targetName, DownloadTaskEntity taskEntity) {
|
||||
CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
|
||||
//CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
this.targetName = targetName;
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
@ -349,7 +366,7 @@ public class DownloadTask implements ITask {
|
||||
downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE));
|
||||
downloadEntity.setCurrentProgress(location);
|
||||
downloadEntity.update();
|
||||
if (!Configuration.isOpenBreadCast) return;
|
||||
if (!Configuration_1.isOpenBreadCast) return;
|
||||
Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
|
||||
intent.putExtra(Aria.ENTITY, downloadEntity);
|
||||
if (location != -1) {
|
||||
|
@ -65,7 +65,8 @@ public class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
|
||||
DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener,
|
||||
int threadNum) {
|
||||
CheckUtil.checkDownloadTaskEntity(entity.downloadEntity);
|
||||
//CheckUtil.checkDownloadTaskEntity(entity.downloadEntity);
|
||||
CheckUtil.checkTaskEntity(entity);
|
||||
mDownloadEntity = entity.downloadEntity;
|
||||
mContext = context.getApplicationContext();
|
||||
mDownloadTaskEntity = entity;
|
||||
|
@ -21,7 +21,6 @@ import android.os.Message;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -55,7 +54,7 @@ final class SingleThreadTask implements Runnable {
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
mConfigFPath = downloadInfo.CONFIG_FILE_PATH;
|
||||
}
|
||||
//mBufSize = Configuration.getInstance().getMaxSpeed();
|
||||
//mBufSize = Configuration_1.getInstance().getMaxSpeed();
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
|
@ -23,6 +23,7 @@ import com.arialyy.aria.core.RequestEnum;
|
||||
import com.arialyy.aria.core.command.AbsCmd;
|
||||
import com.arialyy.aria.core.command.CmdFactory;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@ -50,6 +51,17 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
taskEntity.redirectUrlKey = redirectUrlKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
*/
|
||||
public void removeRecord() {
|
||||
if (entity instanceof DownloadEntity) {
|
||||
((DownloadEntity) entity).deleteData();
|
||||
} else if (entity instanceof UploadEntity) {
|
||||
((UploadEntity) entity).deleteData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务文件大小
|
||||
*
|
||||
@ -74,6 +86,13 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载任务是否存在
|
||||
*/
|
||||
public boolean taskExists(String downloadUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前任务进度,如果任务存在,则返回当前进度
|
||||
*
|
||||
|
@ -51,4 +51,6 @@ public interface ITask {
|
||||
public long getCurrentProgress();
|
||||
|
||||
public void setTargetName(String targetName);
|
||||
|
||||
public void removeRecord();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.pool.CachePool;
|
||||
import com.arialyy.aria.core.queue.pool.ExecutePool;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/17.
|
||||
@ -121,7 +121,7 @@ public class DownloadTaskQueue
|
||||
|
||||
@Override public void setDownloadNum(int downloadNum) {
|
||||
//原始长度
|
||||
int size = Configuration.getInstance().getDownloadNum();
|
||||
int size = Configuration_1.getInstance().getDownloadNum();
|
||||
int diff = downloadNum - size;
|
||||
if (size == downloadNum) {
|
||||
Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
|
||||
@ -160,9 +160,13 @@ public class DownloadTaskQueue
|
||||
}
|
||||
|
||||
@Override public DownloadTask getTask(DownloadEntity entity) {
|
||||
DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
|
||||
return getTask(entity.getDownloadUrl());
|
||||
}
|
||||
|
||||
@Override public DownloadTask getTask(String url) {
|
||||
DownloadTask task = mExecutePool.getTask(url);
|
||||
if (task == null) {
|
||||
task = mCachePool.getTask(entity.getDownloadUrl());
|
||||
task = mCachePool.getTask(url);
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
@ -89,6 +89,14 @@ public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
|
||||
*/
|
||||
public TASK getTask(ENTITY entity);
|
||||
|
||||
/**
|
||||
* 通过工作实体缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
|
||||
*
|
||||
* @param url 链接地址,如果是下载,则为下载链接,如果是上传,为文件保存路径
|
||||
* @return {@link DownloadTask}、{@link UploadTask}
|
||||
*/
|
||||
public TASK getTask(String url);
|
||||
|
||||
/**
|
||||
* 通过工作实体删除任务
|
||||
*
|
||||
|
@ -96,9 +96,13 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
|
||||
}
|
||||
|
||||
@Override public UploadTask getTask(UploadEntity entity) {
|
||||
UploadTask task = mExecutePool.getTask(entity.getFilePath());
|
||||
return getTask(entity.getFilePath());
|
||||
}
|
||||
|
||||
@Override public UploadTask getTask(String url) {
|
||||
UploadTask task = mExecutePool.getTask(url);
|
||||
if (task == null) {
|
||||
task = mCachePool.getTask(entity.getFilePath());
|
||||
task = mCachePool.getTask(url);
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
@ -39,7 +39,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
private int mSize;
|
||||
|
||||
public ExecutePool() {
|
||||
mSize = Configuration.getInstance().getDownloadNum();
|
||||
mSize = Configuration_1.getInstance().getDownloadNum();
|
||||
mExecuteQueue = new ArrayBlockingQueue<>(mSize);
|
||||
mExecuteArray = new HashMap<>();
|
||||
}
|
||||
@ -81,7 +81,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
}
|
||||
mExecuteQueue = temp;
|
||||
mSize = downloadNum;
|
||||
Configuration.getInstance().setDownloadNum(mSize);
|
||||
Configuration_1.getInstance().setDownloadNum(mSize);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import android.util.Log;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -86,7 +86,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
||||
case STOP:
|
||||
case CANCEL:
|
||||
mQueue.removeTask(entity);
|
||||
if (mQueue.size() < Configuration.getInstance().getDownloadNum()) {
|
||||
if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) {
|
||||
startNextTask();
|
||||
}
|
||||
break;
|
||||
@ -163,7 +163,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
||||
* @param task 下载任务
|
||||
*/
|
||||
private void handleFailTask(final DownloadTask task) {
|
||||
final Configuration config = Configuration.getInstance();
|
||||
final Configuration_1 config = Configuration_1.getInstance();
|
||||
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
||||
@Override public void onTick(long millisUntilFinished) {
|
||||
|
||||
|
@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -69,7 +69,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
||||
}
|
||||
|
||||
private void handleFailTask(final UploadTask task) {
|
||||
final Configuration config = Configuration.getInstance();
|
||||
final Configuration_1 config = Configuration_1.getInstance();
|
||||
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
||||
@Override public void onTick(long millisUntilFinished) {
|
||||
|
||||
@ -169,7 +169,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
||||
case STOP:
|
||||
case CANCEL:
|
||||
mQueue.removeTask(entity);
|
||||
if (mQueue.size() < Configuration.getInstance().getDownloadNum()) {
|
||||
if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) {
|
||||
startNextTask();
|
||||
}
|
||||
break;
|
||||
|
@ -100,6 +100,13 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载任务是否存在
|
||||
*/
|
||||
@Override public boolean taskExists(String downloadUrl) {
|
||||
return UploadTaskQueue.getInstance().getTask(downloadUrl) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求类型
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Configuration;
|
||||
import com.arialyy.aria.util.Configuration_1;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
@ -55,6 +55,10 @@ public class UploadTask implements ITask {
|
||||
mTargetName = targetName;
|
||||
}
|
||||
|
||||
@Override public void removeRecord() {
|
||||
mUploadEntity.deleteData();
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return mUploadEntity.getFilePath();
|
||||
}
|
||||
@ -87,9 +91,8 @@ public class UploadTask implements ITask {
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
if (mUtil.isRunning()) {
|
||||
mUtil.cancel();
|
||||
} else {
|
||||
|
||||
if (!mUploadEntity.isComplete()) {
|
||||
// 如果任务不是下载状态
|
||||
mUtil.cancel();
|
||||
mUploadEntity.deleteData();
|
||||
@ -101,6 +104,21 @@ public class UploadTask implements ITask {
|
||||
intent.putExtra(Aria.ENTITY, mUploadEntity);
|
||||
AriaManager.APP.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
//if (mUtil.isRunning()) {
|
||||
// mUtil.cancel();
|
||||
//} else {
|
||||
// // 如果任务不是下载状态
|
||||
// mUtil.cancel();
|
||||
// mUploadEntity.deleteData();
|
||||
// if (mOutHandler != null) {
|
||||
// mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
|
||||
// }
|
||||
// //发送取消下载的广播
|
||||
// Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), Aria.ACTION_CANCEL);
|
||||
// intent.putExtra(Aria.ENTITY, mUploadEntity);
|
||||
// AriaManager.APP.sendBroadcast(intent);
|
||||
//}
|
||||
}
|
||||
|
||||
public String getTargetName() {
|
||||
@ -220,7 +238,7 @@ public class UploadTask implements ITask {
|
||||
entity.setComplete(action.equals(Aria.ACTION_COMPLETE));
|
||||
entity.setCurrentProgress(location);
|
||||
entity.update();
|
||||
if (!Configuration.isOpenBreadCast) return;
|
||||
if (!Configuration_1.isOpenBreadCast) return;
|
||||
Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action);
|
||||
intent.putExtra(Aria.ENTITY, entity);
|
||||
if (location != -1) {
|
||||
|
@ -50,7 +50,7 @@ final class UploadUtil implements Runnable {
|
||||
|
||||
UploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) {
|
||||
mTaskEntity = taskEntity;
|
||||
CheckUtil.checkUploadTaskEntity(taskEntity.uploadEntity);
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
mUploadEntity = taskEntity.uploadEntity;
|
||||
if (listener == null) {
|
||||
throw new IllegalArgumentException("上传监听不能为空");
|
||||
|
@ -21,13 +21,9 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -73,7 +69,7 @@ public class DbUtil {
|
||||
*/
|
||||
synchronized <T extends DbEntity> void delData(Class<T> clazz, String... expression) {
|
||||
CheckUtil.checkSqlExpression(expression);
|
||||
mDb = mHelper.getWritableDatabase();
|
||||
checkDb();
|
||||
SqlHelper.delData(mDb, clazz, expression);
|
||||
}
|
||||
|
||||
@ -81,7 +77,7 @@ public class DbUtil {
|
||||
* 修改某行数据
|
||||
*/
|
||||
synchronized void modifyData(DbEntity dbEntity) {
|
||||
mDb = mHelper.getWritableDatabase();
|
||||
checkDb();
|
||||
SqlHelper.modifyData(mDb, dbEntity);
|
||||
}
|
||||
|
||||
@ -89,9 +85,7 @@ public class DbUtil {
|
||||
* 遍历所有数据
|
||||
*/
|
||||
synchronized <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
|
||||
if (mDb == null || !mDb.isOpen()) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
}
|
||||
checkDb();
|
||||
return SqlHelper.findAllData(mDb, clazz);
|
||||
}
|
||||
|
||||
@ -99,7 +93,7 @@ public class DbUtil {
|
||||
* 条件查寻数据
|
||||
*/
|
||||
synchronized <T extends DbEntity> List<T> findData(Class<T> clazz, String... expression) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
checkDb();
|
||||
return SqlHelper.findData(mDb, clazz, expression);
|
||||
}
|
||||
|
||||
@ -108,7 +102,7 @@ public class DbUtil {
|
||||
*/
|
||||
@Deprecated synchronized <T extends DbEntity> List<T> findData(Class<T> clazz,
|
||||
@NonNull String[] wheres, @NonNull String[] values) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
checkDb();
|
||||
return SqlHelper.findData(mDb, clazz, wheres, values);
|
||||
}
|
||||
|
||||
@ -116,9 +110,7 @@ public class DbUtil {
|
||||
* 插入数据
|
||||
*/
|
||||
synchronized void insertData(DbEntity dbEntity) {
|
||||
if (mDb == null || !mDb.isOpen()) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
}
|
||||
checkDb();
|
||||
SqlHelper.insertData(mDb, dbEntity);
|
||||
}
|
||||
|
||||
@ -126,19 +118,21 @@ public class DbUtil {
|
||||
* 查找某张表是否存在
|
||||
*/
|
||||
synchronized boolean tableExists(Class clazz) {
|
||||
if (mDb == null || !mDb.isOpen()) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
}
|
||||
checkDb();
|
||||
return SqlHelper.tableExists(mDb, clazz);
|
||||
}
|
||||
|
||||
synchronized void createTable(Class clazz, String tableName) {
|
||||
if (mDb == null || !mDb.isOpen()) {
|
||||
mDb = mHelper.getWritableDatabase();
|
||||
}
|
||||
checkDb();
|
||||
SqlHelper.createTable(mDb, clazz, tableName);
|
||||
}
|
||||
|
||||
private void checkDb(){
|
||||
if (mDb == null || !mDb.isOpen()) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
*/
|
||||
@ -159,7 +153,7 @@ public class DbUtil {
|
||||
* 获取所在行Id
|
||||
*/
|
||||
synchronized int[] getRowId(Class clazz) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
checkDb();
|
||||
Cursor cursor = mDb.rawQuery("SELECT rowid, * FROM " + CommonUtil.getClassName(clazz), null);
|
||||
int[] ids = new int[cursor.getCount()];
|
||||
int i = 0;
|
||||
@ -176,7 +170,7 @@ public class DbUtil {
|
||||
* 获取行Id
|
||||
*/
|
||||
synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) {
|
||||
mDb = mHelper.getReadableDatabase();
|
||||
checkDb();
|
||||
if (wheres.length <= 0 || values.length <= 0) {
|
||||
Log.e(TAG, "请输入删除条件");
|
||||
return -1;
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||
@ -95,31 +96,39 @@ public class CheckUtil {
|
||||
|
||||
/**
|
||||
* 检查命令实体
|
||||
*
|
||||
* @param checkPath 删除命令不需要检查下载路径和文件名
|
||||
*/
|
||||
public static void checkCmdEntity(ITaskEntity entity) {
|
||||
public static boolean checkCmdEntity(ITaskEntity entity, boolean checkPath) {
|
||||
boolean b = false;
|
||||
if (entity instanceof DownloadTaskEntity) {
|
||||
DownloadEntity entity1 = ((DownloadTaskEntity) entity).downloadEntity;
|
||||
if (entity1 == null) {
|
||||
throw new NullPointerException("下载实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
throw new IllegalArgumentException("下载链接不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
throw new IllegalArgumentException("保存路径不能为空");
|
||||
Log.e(TAG, "下载实体不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadUrl())) {
|
||||
Log.e(TAG, "下载链接不能为空");
|
||||
} else if (checkPath && TextUtils.isEmpty(entity1.getDownloadPath())) {
|
||||
Log.e(TAG, "保存路径不能为空");
|
||||
} else {
|
||||
b = true;
|
||||
}
|
||||
} else if (entity instanceof UploadTaskEntity) {
|
||||
UploadEntity entity1 = ((UploadTaskEntity) entity).uploadEntity;
|
||||
if (entity1 == null) {
|
||||
throw new NullPointerException("上传实体不能为空");
|
||||
Log.e(TAG, "上传实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity1.getFilePath())) {
|
||||
throw new IllegalArgumentException("上传文件路径不能为空");
|
||||
Log.e(TAG, "上传文件路径不能为空");
|
||||
} else {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查上传实体是否合法
|
||||
*/
|
||||
public static void checkUploadTaskEntity(UploadEntity entity) {
|
||||
private static void checkUploadTaskEntity(UploadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("上传实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getFilePath())) {
|
||||
@ -135,7 +144,7 @@ public class CheckUtil {
|
||||
*
|
||||
* @param entity 下载实体
|
||||
*/
|
||||
public static void checkDownloadTaskEntity(DownloadEntity entity) {
|
||||
private static void checkDownloadTaskEntity(DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("下载实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getDownloadUrl())) {
|
||||
|
@ -28,8 +28,8 @@ import java.util.WeakHashMap;
|
||||
* Created by AriaL on 2016/12/8.
|
||||
* 信息配置
|
||||
*/
|
||||
public class Configuration {
|
||||
private static final String TAG = "Configuration";
|
||||
public class Configuration_1 {
|
||||
private static final String TAG = "Configuration_1";
|
||||
private static final String CONFIG_FILE = "/Aria/ADConfig.properties";
|
||||
/**
|
||||
* 当前调度器最大下载数,默认最大下载数为 “2”
|
||||
@ -58,20 +58,20 @@ public class Configuration {
|
||||
|
||||
public static boolean isOpenBreadCast = false;
|
||||
|
||||
private static Configuration INSTANCE = null;
|
||||
private static Configuration_1 INSTANCE = null;
|
||||
private File mConfigFile = null;
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
public static Configuration getInstance() {
|
||||
public static Configuration_1 getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LOCK) {
|
||||
INSTANCE = new Configuration();
|
||||
INSTANCE = new Configuration_1();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private Configuration() {
|
||||
private Configuration_1() {
|
||||
mConfigFile = new File(AriaManager.APP.getFilesDir().getPath() + CONFIG_FILE);
|
||||
try {
|
||||
if (!mConfigFile.exists()) {
|
@ -20,7 +20,7 @@ Aria怎样使用?
|
||||
## 下载
|
||||
[](https://bintray.com/arialyy/maven/Aria/_latestVersion)</br>
|
||||
```java
|
||||
compile 'com.arialyy.aria:Aria:3.0.2'
|
||||
compile 'com.arialyy.aria:Aria:3.0.3'
|
||||
```
|
||||
|
||||
## 示例
|
||||
@ -149,6 +149,7 @@ compile 'com.arialyy.aria:Aria:3.0.2'
|
||||
***
|
||||
|
||||
## 开发日志
|
||||
+ v_3.0.3 修复暂停后删除任务,闪退问题,添加删除记录的api
|
||||
+ v_3.0.2 支持30x重定向链接下载
|
||||
+ v_3.0.0 添加上传任务支持,修复一些已发现的bug
|
||||
+ v_2.4.4 修复不支持断点的下载链接拿不到文件大小的问题
|
||||
|
46
app/src/main/assets/aria_config.xml
Normal file
46
app/src/main/assets/aria_config.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<aria>
|
||||
|
||||
|
||||
<download>
|
||||
<!--是否打开下载广播,默认为false-->
|
||||
<openBroadcast value="false"/>
|
||||
|
||||
<!--设置下载队列最大任务数, 默认为2-->
|
||||
<maxQueueNum value="2"/>
|
||||
|
||||
<!--设置下载失败,重试次数,默认为10-->
|
||||
<reTryNum value="10"/>
|
||||
|
||||
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
|
||||
<reTryInterval value="2000"/>
|
||||
|
||||
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||
<readTimeout value="20000"/>
|
||||
|
||||
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
|
||||
<buffSize value="8192"/>
|
||||
|
||||
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
|
||||
<ca name="" path=""/>
|
||||
|
||||
</download>
|
||||
|
||||
<upload>
|
||||
<!--是否打开上传广播,默认为false-->
|
||||
<openBroadcast value="false"/>
|
||||
|
||||
<!--设置上传队列最大任务数, 默认为2-->
|
||||
<maxQueueNum value="2"/>
|
||||
|
||||
<!--设置上传失败,重试次数,默认为10-->
|
||||
<reTryNum value="10"/>
|
||||
|
||||
<!--设置重试间隔,单位为毫秒-->
|
||||
<reTryInterval value="2000"/>
|
||||
|
||||
<!--设置url连接超时时间,单位为毫秒,默认5000毫秒-->
|
||||
<connectTimeOut value="5000"/>
|
||||
</upload>
|
||||
|
||||
</aria>
|
@ -55,10 +55,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
private static final String DOWNLOAD_URL =
|
||||
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
||||
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
||||
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//不支持断点的链接
|
||||
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
"http://172.18.104.50:8080/download/_302turn";
|
||||
//"http://172.18.104.50:8080/download/_302turn";
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
||||
@Bind(R.id.start) Button mStart;
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@ -233,6 +234,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
private void stop() {
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
|
Reference in New Issue
Block a user