This commit is contained in:
@@ -29,12 +29,18 @@ import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.common.QueueMod;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.common.QueueMod;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IReceiver;
|
||||
import com.arialyy.aria.core.scheduler.AbsSchedulerListener;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadReceiver;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.DbUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.File;
|
||||
@@ -184,6 +190,45 @@ import org.xml.sax.SAXException;
|
||||
return (receiver instanceof UploadReceiver) ? (UploadReceiver) receiver : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Aria下载错误日志
|
||||
*
|
||||
* @return 如果错误日志不存在则返回空,否则返回错误日志列表
|
||||
*/
|
||||
public List<ErrorEntity> getErrorLog() {
|
||||
return DbEntity.findAllData(ErrorEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清楚错误日志
|
||||
*/
|
||||
public void cleanLog() {
|
||||
DbEntity.clean(ErrorEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务记录
|
||||
*
|
||||
* @param type 需要删除的任务类型,1、表示单任务下载。2、表示任务组下载。3、单任务上传
|
||||
* @param key 下载为保存路径、任务组为任务组名、上传为上传文件路径
|
||||
*/
|
||||
public void delRecord(int type, String key) {
|
||||
switch (type) {
|
||||
case 1:
|
||||
DbEntity.deleteData(DownloadEntity.class, "url=?", key);
|
||||
DbEntity.deleteData(DownloadTaskEntity.class, "key=? and isGroupTask='false'", key);
|
||||
break;
|
||||
case 2:
|
||||
DbEntity.deleteData(DownloadGroupEntity.class, "groupName=?", key);
|
||||
DbEntity.deleteData(DownloadGroupTaskEntity.class, "key=?", key);
|
||||
break;
|
||||
case 3:
|
||||
DbEntity.deleteData(UploadEntity.class, "filePath=?", key);
|
||||
DbEntity.deleteData(UploadTaskEntity.class, "key=?", key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private IReceiver putReceiver(boolean isDownload, Object obj) {
|
||||
final String key = getKey(isDownload, obj);
|
||||
IReceiver receiver = mReceivers.get(key);
|
||||
|
77
Aria/src/main/java/com/arialyy/aria/core/ErrorEntity.java
Normal file
77
Aria/src/main/java/com/arialyy/aria/core/ErrorEntity.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/8/29.
|
||||
* 错误实体
|
||||
*/
|
||||
public class ErrorEntity extends DbEntity {
|
||||
|
||||
/**
|
||||
* 插入时间
|
||||
*/
|
||||
public long insertTime;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
public String err;
|
||||
|
||||
/**
|
||||
* 任务名
|
||||
*/
|
||||
public String taskName;
|
||||
|
||||
/**
|
||||
*任务类型
|
||||
*/
|
||||
public String taskType;
|
||||
|
||||
/**
|
||||
* 提示
|
||||
*/
|
||||
public String msg;
|
||||
|
||||
/**
|
||||
* 任务key
|
||||
*/
|
||||
public String key;
|
||||
|
||||
@Override public String toString() {
|
||||
return "ErrorEntity{"
|
||||
+ "insertTime="
|
||||
+ insertTime
|
||||
+ ", err='"
|
||||
+ err
|
||||
+ '\''
|
||||
+ ", taskName='"
|
||||
+ taskName
|
||||
+ '\''
|
||||
+ ", taskType='"
|
||||
+ taskType
|
||||
+ '\''
|
||||
+ ", msg='"
|
||||
+ msg
|
||||
+ '\''
|
||||
+ ", key='"
|
||||
+ key
|
||||
+ '\''
|
||||
+ '}';
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEventListener;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
@@ -33,7 +34,7 @@ import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/1/18.
|
||||
* 下载线程
|
||||
* 任务线程
|
||||
*/
|
||||
public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
implements Runnable {
|
||||
@@ -59,6 +60,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
*/
|
||||
public static String SERVER_CHARSET = "ISO-8859-1";
|
||||
private int mFailNum = 0;
|
||||
private String mTaskType;
|
||||
private Timer mFailTimer;
|
||||
|
||||
protected AbsThreadTask(StateConstance constance, IEventListener listener,
|
||||
@@ -76,8 +78,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}
|
||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
|
||||
mTaskType = getTaskType();
|
||||
}
|
||||
|
||||
protected abstract String getTaskType();
|
||||
|
||||
public void setMaxSpeed(double maxSpeed) {
|
||||
if (-0.9999 < maxSpeed && maxSpeed < 0.00001) {
|
||||
mSleepTime = 0;
|
||||
@@ -93,7 +98,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止下载
|
||||
* 停止任务
|
||||
*/
|
||||
public void stop() {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
@@ -124,7 +129,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载中
|
||||
* 执行中
|
||||
*/
|
||||
protected void progress(long len) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
@@ -134,7 +139,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消下载
|
||||
* 取消任务
|
||||
*/
|
||||
public void cancel() {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
@@ -185,6 +190,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
} else {
|
||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||
mListener.onFail(true);
|
||||
ErrorHelp.saveError(mTaskType, mEntity, "", CommonUtil.getPrintException(ex));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@@ -27,6 +27,7 @@ import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -103,11 +104,11 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void failDownload(String errorMsg) {
|
||||
closeTimer();
|
||||
Log.e(TAG, errorMsg);
|
||||
mConstance.isRunning = false;
|
||||
mListener.onFail(false);
|
||||
ErrorHelp.saveError("", mEntity, "", errorMsg);
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.arialyy.aria.core.download.downloader;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
|
||||
@Override public void onFail(String url, String errorMsg) {
|
||||
mListener.onFail(true);
|
||||
ErrorHelp.saveError("FTP_DIR", mTaskEntity.getEntity(), "", errorMsg);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@@ -148,4 +148,8 @@ class FtpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEntity> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected String getTaskType() {
|
||||
return "FTP_DOWNLOAD";
|
||||
}
|
||||
}
|
||||
|
@@ -126,4 +126,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected String getTaskType() {
|
||||
return "HTTP_DOWNLOAD";
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/8/25.
|
||||
@@ -83,6 +84,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
|
||||
private void failDownload(String msg) {
|
||||
mListener.onFail(true);
|
||||
ErrorHelp.saveError("HTTP_DOWNLOAD", mTaskEntity.getEntity(), msg, "");
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
|
@@ -45,6 +45,7 @@ class FtpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
super(constance, listener, info);
|
||||
}
|
||||
|
||||
|
||||
@Override public void run() {
|
||||
FTPClient client = null;
|
||||
OutputStream os = null;
|
||||
@@ -181,4 +182,9 @@ class FtpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
client.allocate(mBufSize);
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override protected String getTaskType() {
|
||||
return "FTP_UPLOAD";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -202,4 +202,8 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
mOutputStream.close();
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
@Override protected String getTaskType() {
|
||||
return "HTTP_UPLOAD";
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.orm;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.ErrorEntity;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
@@ -32,7 +33,7 @@ import java.util.Map;
|
||||
class DBConfig {
|
||||
static Map<String, Class> mapping = new HashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 12;
|
||||
static int VERSION = 13;
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
@@ -50,5 +51,6 @@ class DBConfig {
|
||||
mapping.put("DownloadGroupTaskEntity", DownloadGroupTaskEntity.class);
|
||||
mapping.put("UploadEntity", UploadEntity.class);
|
||||
mapping.put("UploadTaskEntity", UploadTaskEntity.class);
|
||||
mapping.put("ErrorEntity", ErrorEntity.class);
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,13 @@ public class DbEntity {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空表数据
|
||||
*/
|
||||
public static <T extends DbEntity> void clean(Class<T> clazz) {
|
||||
DbUtil.getInstance().clean(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接执行sql语句
|
||||
*/
|
||||
|
@@ -64,6 +64,18 @@ public class DbUtil {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空表数据
|
||||
*/
|
||||
synchronized <T extends DbEntity> void clean(Class<T> clazz) {
|
||||
checkDb();
|
||||
String tableName = CommonUtil.getClassName(clazz);
|
||||
if (tableExists(clazz)) {
|
||||
String sql = "DELETE FROM " + tableName;
|
||||
exeSql(sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql语句
|
||||
*/
|
||||
|
58
Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
Normal file
58
Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.arialyy.aria.core.ErrorEntity;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/8/29.
|
||||
* 错误帮助类
|
||||
*/
|
||||
public class ErrorHelp {
|
||||
|
||||
/**
|
||||
* 保存错误信息
|
||||
*
|
||||
* @param taskType 任务类型
|
||||
* @param entity 任务实体
|
||||
* @param msg 错误提示
|
||||
* @param ex 异常
|
||||
*/
|
||||
public static void saveError(String taskType, AbsEntity entity, String msg, String ex) {
|
||||
ErrorEntity errorEntity = new ErrorEntity();
|
||||
errorEntity.insertTime = System.currentTimeMillis();
|
||||
errorEntity.err = ex;
|
||||
errorEntity.msg = msg;
|
||||
errorEntity.taskType = taskType;
|
||||
String name = "";
|
||||
String key = entity.getKey();
|
||||
if (entity instanceof DownloadEntity) {
|
||||
name = ((DownloadEntity) entity).getFileName();
|
||||
} else if (entity instanceof DownloadGroupEntity) {
|
||||
name = ((DownloadGroupEntity) entity).getGroupName();
|
||||
} else if (entity instanceof UploadEntity) {
|
||||
name = ((UploadEntity) entity).getFileName();
|
||||
}
|
||||
|
||||
errorEntity.taskName = name;
|
||||
errorEntity.key = key;
|
||||
errorEntity.insert();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user