增加广播支持,增加get参数

v3.6.6
laoyuyu 6 years ago
parent ed0c98fd7e
commit 44f3b4faf1
  1. 3
      .gitignore
  2. 86
      Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java
  3. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  6. 36
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  9. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  10. 29
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  11. 61
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  12. 1
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  13. 1
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  14. 61
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  15. 1
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  16. 2
      app/src/main/AndroidManifest.xml
  17. 5
      app/src/main/assets/aria_config.xml
  18. 97
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  19. 7
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  20. 11
      py/download.py

3
.gitignore vendored

@ -14,4 +14,5 @@
.idea .idea
/cache /cache
*.log *.log
uml uml
*.swp

@ -0,0 +1,86 @@
/*
* 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.common.http;
import android.text.TextUtils;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadGroupTarget;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IPostDelegate;
import com.arialyy.aria.core.inf.ITarget;
import com.arialyy.aria.util.ALog;
import java.util.HashMap;
import java.util.Map;
/**
* get处理委托类
*/
public class GetDelegate<TARGET extends AbsTarget> implements IPostDelegate<TARGET>, ITarget {
private static final String TAG = "PostDelegate";
private TARGET mTarget;
public GetDelegate(TARGET target) {
mTarget = target;
mTarget.getTaskEntity().setRequestEnum(RequestEnum.GET);
}
@Override public TARGET setParams(Map<String, String> params) {
mTarget.getTaskEntity().setParams(params);
if (mTarget instanceof DownloadGroupTarget) {
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
subTask.setParams(params);
}
}
return mTarget;
}
@Override public TARGET setParam(String key, String value) {
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) {
ALog.d(TAG, "key 或value 为空");
return mTarget;
}
Map<String, String> params = mTarget.getTaskEntity().getParams();
if (params == null) {
params = new HashMap<>();
mTarget.getTaskEntity().setParams(params);
}
params.put(key, value);
if (mTarget instanceof DownloadGroupTarget) {
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
subTask.setParams(params);
}
}
return mTarget;
}
@Override public void start() {
mTarget.start();
}
@Override public void stop() {
mTarget.stop();
}
@Override public void resume() {
mTarget.resume();
}
@Override public void cancel() {
mTarget.cancel();
}
}

@ -57,6 +57,10 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupEntity, Downloa
? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias()); ? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias());
} }
@Override public int getTaskType() {
return DOWNLOAD_GROUP;
}
public static class Builder { public static class Builder {
DownloadGroupTaskEntity taskEntity; DownloadGroupTaskEntity taskEntity;
Handler outHandler; Handler outHandler;

@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult; import android.support.annotation.CheckResult;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.http.GetDelegate;
import com.arialyy.aria.core.common.http.HttpHeaderDelegate; import com.arialyy.aria.core.common.http.HttpHeaderDelegate;
import com.arialyy.aria.core.common.http.PostDelegate; import com.arialyy.aria.core.common.http.PostDelegate;
import com.arialyy.aria.core.inf.IHttpHeaderDelegate; import com.arialyy.aria.core.inf.IHttpHeaderDelegate;
@ -48,6 +49,13 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
return new PostDelegate<>(this); return new PostDelegate<>(this);
} }
/**
* get参数传递
*/
public GetDelegate asGet(){
return new GetDelegate<>(this);
}
/** /**
* 是否使用服务器通过content-disposition传递的文件名内容格式{@code attachment;filename=***} * 是否使用服务器通过content-disposition传递的文件名内容格式{@code attachment;filename=***}
* 如果获取不到服务器文件名则使用用户设置的文件名 * 如果获取不到服务器文件名则使用用户设置的文件名

@ -68,6 +68,10 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity, DownloadTaskEnti
return mEntity.getUrl(); return mEntity.getUrl();
} }
@Override public int getTaskType() {
return DOWNLOAD;
}
@Override public String getKey() { @Override public String getKey() {
return mEntity.getUrl(); return mEntity.getUrl();
} }

@ -21,16 +21,22 @@ import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.SSLContextUtil; import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.CookieManager; import java.net.CookieManager;
import java.net.CookieStore; import java.net.CookieStore;
import java.net.HttpCookie; import java.net.HttpCookie;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
@ -39,10 +45,36 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
/** /**
* Created by lyy on 2017/1/18. * Created by lyy on 2017/1/18. 链接帮助类
* 链接帮助类
*/ */
class ConnectionHelp { class ConnectionHelp {
private static final String TAG = "ConnectionHelp";
/**
* 处理url参数
*
* @throws MalformedURLException
*/
static URL handleUrl(String url, AbsTaskEntity taskEntity) throws MalformedURLException {
Map<String, String> params = taskEntity.getParams();
if (params != null && taskEntity.getRequestEnum() == RequestEnum.GET) {
if (url.contains("?")) {
ALog.e(TAG, String.format("设置参数失败,url中已经有?,url: %s", url));
return new URL(CommonUtil.convertUrl(url));
}
StringBuilder sb = new StringBuilder();
sb.append(url).append("?");
Set<String> keys = params.keySet();
for (String key : keys) {
sb.append(key).append("=").append(URLEncoder.encode(params.get(key))).append("&");
}
String temp = sb.toString();
temp = temp.substring(0, temp.length() - 1);
return new URL(CommonUtil.convertUrl(temp));
} else {
return new URL(CommonUtil.convertUrl(url));
}
}
/** /**
* 转换HttpUrlConnect的inputStream流 * 转换HttpUrlConnect的inputStream流

@ -69,7 +69,7 @@ class HttpFileInfoThread implements Runnable {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
HttpURLConnection conn = null; HttpURLConnection conn = null;
try { try {
URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl())); URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskEntity);
conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity);
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setRequestProperty("Range", "bytes=" + 0 + "-");
@ -275,7 +275,7 @@ class HttpFileInfoThread implements Runnable {
mEntity.setRedirect(true); mEntity.setRedirect(true);
mEntity.setRedirectUrl(newUrl); mEntity.setRedirectUrl(newUrl);
String cookies = conn.getHeaderField("Set-Cookie"); String cookies = conn.getHeaderField("Set-Cookie");
URL url = new URL(CommonUtil.convertUrl(newUrl)); URL url = ConnectionHelp.handleUrl(newUrl, mTaskEntity);
conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity);
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
conn.setRequestProperty("Cookie", cookies); conn.setRequestProperty("Cookie", cookies);

@ -75,7 +75,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
//当前子线程的下载位置 //当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION; mChildCurrentLocation = mConfig.START_LOCATION;
try { try {
URL url = new URL(CommonUtil.convertUrl(mConfig.URL)); URL url = ConnectionHelp.handleUrl(mConfig.URL, mTaskEntity);
conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity);
if (mConfig.SUPPORT_BP) { if (mConfig.SUPPORT_BP) {
ALog.d(TAG, ALog.d(TAG,

@ -17,6 +17,7 @@ package com.arialyy.aria.core.inf;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -63,8 +64,7 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
} }
/** /**
* 添加扩展数据 * 添加扩展数据 读取扩展数据{@link #getExpand(String)}
* 读取扩展数据{@link #getExpand(String)}
*/ */
public void putExpand(String key, Object obj) { public void putExpand(String key, Object obj) {
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {

@ -20,6 +20,34 @@ package com.arialyy.aria.core.inf;
*/ */
public interface ITask<TASK_ENTITY extends AbsTaskEntity> { public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
/**
* 普通下载任务
*/
int DOWNLOAD = 1;
/**
* 上传任务
*/
int UPLOAD = 2;
/**
* 组合任务
*/
int DOWNLOAD_GROUP = 3;
/**
* 组合任务的子任务
*/
int DOWNLOAD_GROUP_SUB = 4;
/**
* 未知
*/
int OTHER = -1;
/**
* 获取任务类型
*
* @return {@link #DOWNLOAD}{@link #UPLOAD}{@link #DOWNLOAD_GROUP}
*/
int getTaskType();
/** /**
* 获取下载状态 * 获取下载状态
*/ */
@ -51,6 +79,7 @@ public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
/** /**
* 停止任务 * 停止任务
*
* @param type {@code 0}默认操作{@code 1}停止任务不自动执行下一任务 * @param type {@code 0}默认操作{@code 1}停止任务不自动执行下一任务
*/ */
void stop(int type); void stop(int type);

@ -15,6 +15,8 @@
*/ */
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Message; import android.os.Message;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
@ -26,6 +28,7 @@ import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.queue.ITaskQueue;
@ -38,8 +41,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* Created by lyy on 2017/6/4. * Created by lyy on 2017/6/4. 事件调度器用于处理任务状态的调度
* 事件调度器用于处理任务状态的调度
*/ */
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask, abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask,
QUEUE extends ITaskQueue<TASK, TASK_ENTITY>> implements ISchedulers<TASK> { QUEUE extends ITaskQueue<TASK, TASK_ENTITY>> implements ISchedulers<TASK> {
@ -55,6 +57,12 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
*/ */
abstract String getProxySuffix(); abstract String getProxySuffix();
private AriaManager manager;
AbsSchedulers() {
manager = AriaManager.getInstance(AriaManager.APP);
}
@Override public void register(Object obj) { @Override public void register(Object obj) {
String targetName = obj.getClass().getName(); String targetName = obj.getClass().getName();
AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(getKey(obj)); AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(getKey(obj));
@ -155,6 +163,13 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
} }
} }
} }
boolean canSend = manager.getDownloadConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(msg.what, ITask.DOWNLOAD_GROUP_SUB, params.entity));
}
return true; return true;
} }
@ -201,6 +216,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
* @param state 状态 * @param state 状态
*/ */
private void callback(int state, TASK task) { private void callback(int state, TASK task) {
sendNormalBroadcast(state, task);
if (mObservers.size() > 0) { if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet(); Set<String> keys = mObservers.keySet();
for (String key : keys) { for (String key : keys) {
@ -254,6 +270,46 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
} }
} }
/**
* 发送普通任务的广播
*/
private void sendNormalBroadcast(int state, TASK task) {
if (task.getTaskType() == ITask.DOWNLOAD || task.getTaskType() == ITask.DOWNLOAD_GROUP) {
boolean canSend = manager.getDownloadConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(state, task.getTaskType(), task.getTaskEntity().getEntity()));
}
} else if (task.getTaskType() == ITask.UPLOAD) {
boolean canSend = manager.getUploadConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(state, task.getTaskType(), task.getTaskEntity().getEntity()));
}
} else {
ALog.w(TAG, "发送广播失败,没有对应的任务");
}
}
/**
* 创建广播发送的数据
*
* @param taskState 任务状态 {@link ISchedulers}
* @param taskType 任务类型 {@link ITask}
* @param entity 任务实体
*/
private Intent createData(int taskState, int taskType, AbsEntity entity) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
Bundle b = new Bundle();
b.putInt(ISchedulers.TASK_TYPE, taskType);
b.putInt(ISchedulers.TASK_STATE, taskState);
b.putLong(ISchedulers.TASK_SPEED, entity.getSpeed());
b.putInt(ISchedulers.TASK_PERCENT, entity.getPercent());
b.putParcelable(ISchedulers.TASK_ENTITY, entity);
intent.putExtras(b);
return intent;
}
/** /**
* 处理下载任务下载失败的情形 * 处理下载任务下载失败的情形
* *
@ -269,7 +325,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
long interval = 2000; long interval = 2000;
int num = 10; int num = 10;
boolean isNotNetRetry = false; boolean isNotNetRetry = false;
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
if (task instanceof DownloadTask || task instanceof DownloadGroupTask) { if (task instanceof DownloadTask || task instanceof DownloadGroupTask) {
interval = manager.getDownloadConfig().getReTryInterval(); interval = manager.getDownloadConfig().getReTryInterval();
num = manager.getDownloadConfig().getReTryNum(); num = manager.getDownloadConfig().getReTryNum();

@ -31,6 +31,7 @@ public class DownloadGroupSchedulers extends
private static volatile DownloadGroupSchedulers INSTANCE = null; private static volatile DownloadGroupSchedulers INSTANCE = null;
private DownloadGroupSchedulers() { private DownloadGroupSchedulers() {
super();
mQueue = DownloadGroupTaskQueue.getInstance(); mQueue = DownloadGroupTaskQueue.getInstance();
} }

@ -33,6 +33,7 @@ public class DownloadSchedulers
private static volatile DownloadSchedulers INSTANCE = null; private static volatile DownloadSchedulers INSTANCE = null;
private DownloadSchedulers() { private DownloadSchedulers() {
super();
mQueue = DownloadTaskQueue.getInstance(); mQueue = DownloadTaskQueue.getInstance();
} }

@ -17,20 +17,59 @@
package com.arialyy.aria.core.scheduler; package com.arialyy.aria.core.scheduler;
import android.os.Handler; import android.os.Handler;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.upload.UploadEntity;
/** /**
* Created by lyy on 2016/11/2. * Created by lyy on 2016/11/2. 调度器功能接口
* 调度器功能接口
*/ */
public interface ISchedulers<Task extends AbsTask> extends Handler.Callback { public interface ISchedulers<Task extends AbsTask> extends Handler.Callback {
String ARIA_TASK_INFO_ACTION = "ARIA_TASK_INFO_ACTION";
/**
* 广播接收器中通过TASK_TYPE字段获取任务类型 {@link ITask#DOWNLOAD}{@link ITask#DOWNLOAD_GROUP}{@link
* ITask#UPLOAD}{@link ITask#DOWNLOAD_GROUP_SUB}
*/
String TASK_TYPE = "ARIA_TASK_TYPE";
/**
* 广播接收器中通过TASK_STATE字段获取任务状态 普通任务的有
* </br>
* {@link #NO_SUPPORT_BREAK_POINT}{@link #PRE}{@link #POST_PRE}{@link #START}{@link
* #STOP}{@link #FAIL}{@link #CANCEL}{@link #COMPLETE}{@link #RUNNING}{@link #RESUME}{@link
* #WAIT}
* </br>
* 子任务的有{@link #SUB_PRE}{@link #SUB_START}{@link #SUB_STOP}{@link #SUB_CANCEL}{@link
* #SUB_FAIL}{@link #SUB_RUNNING}{@link #SUB_COMPLETE}
*/
String TASK_STATE = "ARIA_TASK_STATE";
/**
* 广播接收器中通过TASK_ENTITY字段获取任务实体 {@link DownloadEntity}{@link UploadEntity}{@link
* DownloadGroupEntity}
*/
String TASK_ENTITY = "ARIA_TASK_ENTITY";
/**
* 任务速度单位byte/s
*/
String TASK_SPEED = "ARIA_TASK_SPEED";
/**
* 任务进度
*/
String TASK_PERCENT = "ARIA_TASK_PERCENT";
/** /**
* 为任务组任务 * 组合任务任务
*/ */
int IS_SUB_TASK = 0xd1; int IS_SUB_TASK = 0xd1;
/** /**
* 不支持断点 * 任务不支持断点
*/ */
int NO_SUPPORT_BREAK_POINT = 9; int NO_SUPPORT_BREAK_POINT = 9;
/** /**
@ -76,37 +115,37 @@ public interface ISchedulers<Task extends AbsTask> extends Handler.Callback {
int WAIT = 10; int WAIT = 10;
/** /**
* 任务子任务预处理 * 组合任务子任务预处理
*/ */
int SUB_PRE = 0xa1; int SUB_PRE = 0xa1;
/** /**
* 任务子任务开始 * 组合任务子任务开始
*/ */
int SUB_START = 0xa2; int SUB_START = 0xa2;
/** /**
* 任务子任务停止 * 组合任务子任务停止
*/ */
int SUB_STOP = 0xa3; int SUB_STOP = 0xa3;
/** /**
* 任务子任务取消 * 组合任务子任务取消
*/ */
int SUB_CANCEL = 0xa4; int SUB_CANCEL = 0xa4;
/** /**
* 任务子任务失败 * 组合任务子任务失败
*/ */
int SUB_FAIL = 0xa5; int SUB_FAIL = 0xa5;
/** /**
* 任务子任务执行执行中 * 组合任务子任务执行执行中
*/ */
int SUB_RUNNING = 0xa6; int SUB_RUNNING = 0xa6;
/** /**
* 任务子任务完成 * 组合任务子任务完成
*/ */
int SUB_COMPLETE = 0xa7; int SUB_COMPLETE = 0xa7;

@ -29,6 +29,7 @@ public class UploadSchedulers extends AbsSchedulers<UploadTaskEntity, UploadTask
private static volatile UploadSchedulers INSTANCE = null; private static volatile UploadSchedulers INSTANCE = null;
private UploadSchedulers() { private UploadSchedulers() {
super();
mQueue = UploadTaskQueue.getInstance(); mQueue = UploadTaskQueue.getInstance();
} }

@ -20,7 +20,7 @@
<!--android:name=".download.group.DownloadGroupActivity"--> <!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".MainActivity"--> <!--android:name=".MainActivity"-->
<activity <activity
android:name=".test.AnyRunActivity" android:name=".download.SingleTaskActivity"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

@ -66,8 +66,10 @@
<!--进度更新更新间隔,默认1000毫秒--> <!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/> <updateInterval value="1000"/>
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 --> <!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
<useBroadcast value="false"/> <!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
<useBroadcast value="true"/>
</download> </download>
@ -105,6 +107,7 @@
<updateInterval value="1000"/> <updateInterval value="1000"/>
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 --> <!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
<!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
<useBroadcast value="false"/> <useBroadcast value="false"/>
</upload> </upload>

@ -16,8 +16,11 @@
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.content.BroadcastReceiver;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
@ -35,6 +38,7 @@ import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
@ -43,6 +47,7 @@ import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivitySingleBinding; import com.arialyy.simple.databinding.ActivitySingleBinding;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> { public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@ -51,22 +56,46 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks";
"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zips"; //"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip"; //"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk"; //"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 //"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//"https://static.donguo.me/video/ip/course/pfys_1.mp4"; //"https://static.donguo.me/video/ip/course/pfys_1.mp4";
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864"; //"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
//"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013"; //"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1"; //"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; //"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso"; //"http://9.9.9.50:5000/download1";
"http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota"; //"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
@Bind(R.id.start) Button mStart; @Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop; @Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel; @Bind(R.id.cancel) Button mCancel;
@Bind(R.id.speeds) RadioGroup mRg; @Bind(R.id.speeds) RadioGroup mRg;
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ISchedulers.ARIA_TASK_INFO_ACTION)) {
ALog.d(TAG, "state = " + intent.getIntExtra(ISchedulers.TASK_STATE, -1));
ALog.d(TAG, "type = " + intent.getIntExtra(ISchedulers.TASK_TYPE, -1));
ALog.d(TAG, "speed = " + intent.getLongExtra(ISchedulers.TASK_SPEED, -1));
ALog.d(TAG, "percent = " + intent.getIntExtra(ISchedulers.TASK_PERCENT, -1));
ALog.d(TAG, "entity = " + intent.getParcelableExtra(ISchedulers.TASK_ENTITY).toString());
}
}
};
@Override protected void onResume() {
super.onResume();
//registerReceiver(receiver, new IntentFilter(ISchedulers.ARIA_TASK_INFO_ACTION));
}
@Override protected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
Aria.download(this).unRegister();
}
@Override protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Aria.download(this).register(); Aria.download(this).register();
@ -142,14 +171,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Download.onTaskRunning protected void running(DownloadTask task) { @Download.onTaskRunning protected void running(DownloadTask task) {
ALog.d(TAG, String.format("%s_running_%s", getClass().getName(), hashCode())); ALog.d(TAG, String.format("%s_running_%s", getClass().getName(), hashCode()));
//if (task.getKey().equals(DOWNLOAD_URL)) { //if (task.getKey().equals(DOWNLOAD_URL)) {
//Log.d(TAG, task.getKey()); //Log.d(TAG, task.getKey());
long len = task.getFileSize(); long len = task.getFileSize();
if (len == 0) { if (len == 0) {
getBinding().setProgress(0); getBinding().setProgress(0);
} else { } else {
getBinding().setProgress(task.getPercent()); getBinding().setProgress(task.getPercent());
} }
getBinding().setSpeed(task.getConvertSpeed()); getBinding().setSpeed(task.getConvertSpeed());
//} //}
} }
@ -199,20 +228,20 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Download.onTaskComplete void taskComplete(DownloadTask task) { @Download.onTaskComplete void taskComplete(DownloadTask task) {
//if (task.getKey().equals(DOWNLOAD_URL)) { //if (task.getKey().equals(DOWNLOAD_URL)) {
getBinding().setProgress(100); getBinding().setProgress(100);
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show(); Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
mStart.setText("重新开始?"); mStart.setText("重新开始?");
//mCancel.setEnabled(false); //mCancel.setEnabled(false);
setBtState(true); setBtState(true);
getBinding().setSpeed(""); getBinding().setSpeed("");
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
//Intent install = new Intent(Intent.ACTION_VIEW); //Intent install = new Intent(Intent.ACTION_VIEW);
//install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//File apkFile = new File(task.getDownloadPath()); //File apkFile = new File(task.getDownloadPath());
//install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); //install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
//startActivity(install); //startActivity(install);
//} //}
} }
@ -271,6 +300,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
// file.delete(); // file.delete();
//} //}
Map<String, String> params = new HashMap<>();
params.put("key", "value");
params.put("filename", "CentOS-7-x86_64-Minimal-1804.iso");
Aria.download(SingleTaskActivity.this) Aria.download(SingleTaskActivity.this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") //.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
@ -279,7 +311,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.useServerFileName(true) .useServerFileName(true)
.setFilePath(path, true) .setFilePath(path, true)
//.asPost().setParam("key", "value") //.asGet()
.asPost()
.setParams(params)
//.setExtendField("{\n" //.setExtendField("{\n"
// + "\"id\":\"你的样子\"\n< > " // + "\"id\":\"你的样子\"\n< > "
// + "}") // + "}")
@ -288,11 +322,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.add(); //.add();
} }
@Override protected void onDestroy() {
super.onDestroy();
//Aria.download(this).unRegister();
}
@Override protected void onStop() { @Override protected void onStop() {
super.onStop(); super.onStop();
//Aria.download(this).unRegister(); //Aria.download(this).unRegister();

@ -23,8 +23,7 @@ import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil;
/** /**
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23. 上传任务
* 上传任务
*/ */
public class UploadTask extends AbsNormalTask<UploadEntity, UploadTaskEntity> { public class UploadTask extends AbsNormalTask<UploadEntity, UploadTaskEntity> {
@ -35,6 +34,10 @@ public class UploadTask extends AbsNormalTask<UploadEntity, UploadTaskEntity> {
mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener); mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener);
} }
@Override public int getTaskType() {
return UPLOAD;
}
@Override public String getKey() { @Override public String getKey() {
return mTaskEntity.getEntity().getFilePath(); return mTaskEntity.getEntity().getFilePath();
} }

@ -17,5 +17,16 @@ def downloader(filename):
return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载 return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载
@app.route("/download1", methods=['POST', 'GET'])
def downloader1():
"""
不支持断点的下载
"""
filename = request.values.get('filename')
data = request.values.get('key')
print data
dirpath = 'D:/test'
return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True) # 需要关闭防火墙 app.run(host='0.0.0.0', debug=True) # 需要关闭防火墙

Loading…
Cancel
Save