修复无限下载出错的bug
This commit is contained in:
@ -199,19 +199,23 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
*
|
||||
* @param entity 失败实体
|
||||
*/
|
||||
@Override public void handleFailTask(DownloadEntity entity) {
|
||||
final Configuration config = Configuration.getInstance();
|
||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
||||
Task task = mQueue.getTask(entity);
|
||||
mQueue.reTryStart(task);
|
||||
try {
|
||||
Thread.currentThread().sleep(config.getReTryInterval());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
@Override public void handleFailTask(final DownloadEntity entity) {
|
||||
new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
final Configuration config = Configuration.getInstance();
|
||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
||||
Task task = mQueue.getTask(entity);
|
||||
mQueue.reTryStart(task);
|
||||
try {
|
||||
Thread.sleep(config.getReTryInterval());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
startNextTask(entity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
startNextTask(entity);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,10 +229,10 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
conn.setConnectTimeout(mConnectTimeOut * 4);
|
||||
conn.connect();
|
||||
int len = conn.getContentLength();
|
||||
if (len < 0) { //网络被劫持时会出现这个问题
|
||||
failDownload("下载失败,网络被劫持");
|
||||
return;
|
||||
}
|
||||
//if (len < 0) { //网络被劫持时会出现这个问题
|
||||
// failDownload("下载失败,网络被劫持");
|
||||
// return;
|
||||
//}
|
||||
int code = conn.getResponseCode();
|
||||
//https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81
|
||||
//206支持断点
|
||||
@ -240,8 +240,9 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
isSupportBreakpoint = true;
|
||||
mListener.supportBreakpoint(true);
|
||||
handleBreakpoint(conn);
|
||||
} else if (code == HttpURLConnection.HTTP_OK) {
|
||||
} else if (code == HttpURLConnection.HTTP_OK || len < 0) {
|
||||
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
|
||||
isSupportBreakpoint = false;
|
||||
mListener.supportBreakpoint(false);
|
||||
Log.w(TAG, "该下载链接不支持断点下载");
|
||||
handleBreakpoint(conn);
|
||||
|
@ -257,7 +257,6 @@ public class Task {
|
||||
@Override public void onStart(long startLocation) {
|
||||
super.onStart(startLocation);
|
||||
downloadEntity.setState(DownloadEntity.STATE_DOWNLOAD_ING);
|
||||
downloadEntity.setFailNum(0);
|
||||
sendInState2Target(DownloadSchedulers.START);
|
||||
sendIntent(Aria.ACTION_START, startLocation);
|
||||
}
|
||||
|
Reference in New Issue
Block a user