From 703078e750075928f3affc3b2110ea15513bf186 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Fri, 1 Jun 2018 00:20:53 +0800 Subject: [PATCH] fix bug https://github.com/AriaLyy/Aria/issues/248 https://github.com/AriaLyy/Aria/issues/247 --- .../com/arialyy/aria/core/download/DownloadReceiver.java | 4 ++-- .../core/download/downloader/HttpFileInfoThread.java | 9 +++++++-- DEV_LOG.md | 3 +++ .../java/com/arialyy/simple/test/AnyRunActivity.java | 8 +++++++- .../main/java/com/arialyy/simple/test/AnyRunnModule.java | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) 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 9fccd6d5..e28836d8 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 @@ -265,7 +265,7 @@ public class DownloadReceiver extends AbsReceiver { * @return 如果url错误或查找不到数据,则返回null */ public DownloadEntity getDownloadEntity(String downloadUrl) { - if (CheckUtil.checkUrl(downloadUrl)) { + if (!CheckUtil.checkUrl(downloadUrl)) { return null; } return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'", downloadUrl); @@ -278,7 +278,7 @@ public class DownloadReceiver extends AbsReceiver { * @return 如果url错误或查找不到数据,则返回null */ public DownloadTaskEntity getDownloadTask(String downloadUrl) { - if (CheckUtil.checkUrl(downloadUrl)) { + if (!CheckUtil.checkUrl(downloadUrl)) { return null; } return TEManager.getInstance().getTEntity(DownloadTaskEntity.class, downloadUrl); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 10183650..4a73f1f2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -133,7 +133,11 @@ class HttpFileInfoThread implements Runnable { mTaskEntity.setSupportBP(true); end = true; } else if (code == HttpURLConnection.HTTP_OK) { - if (conn.getHeaderField("Content-Type").equals("text/html")) { + String contentType = conn.getHeaderField("Content-Type"); + if (TextUtils.isEmpty(contentType)) { + return; + } + if (contentType.equals("text/html")) { BufferedReader reader = new BufferedReader(new InputStreamReader(ConnectionHelp.convertInputStream(conn))); StringBuilder sb = new StringBuilder(); @@ -155,7 +159,8 @@ class HttpFileInfoThread implements Runnable { failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:404", true); } else if (code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_MOVED_PERM - || code == HttpURLConnection.HTTP_SEE_OTHER) { + || code == HttpURLConnection.HTTP_SEE_OTHER + || code == 307) { handleUrlReTurn(conn, conn.getHeaderField("Location")); } else { failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:" + code, true); diff --git a/DEV_LOG.md b/DEV_LOG.md index ece42758..b5ab1e9b 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.4.2 + - fix bug https://github.com/AriaLyy/Aria/issues/248 + - fix bug https://github.com/AriaLyy/Aria/issues/247 + v_3.4.1 - 移除记录配置文件,改用数据库记录任务记录 - 上传配置添加io超时时间、缓存大小配置 diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java index d99c955e..bbbdb32c 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java @@ -1,8 +1,11 @@ package com.arialyy.simple.test; import android.os.Bundle; +import android.util.Log; import android.view.View; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityTestBinding; @@ -15,7 +18,8 @@ public class AnyRunActivity extends BaseActivity { AnyRunnModule module; String[] urls; int index = 0; - String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk"; + //String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk"; + String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk"; //String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar"; //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; @@ -30,6 +34,8 @@ public class AnyRunActivity extends BaseActivity { mBar.setVisibility(View.GONE); module = new AnyRunnModule(this); urls = getResources().getStringArray(R.array.group_urls); + DownloadTaskEntity entity = Aria.download(this).getDownloadTask(URL); + Log.d(TAG, entity + ""); } public void onClick(View view) { diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java index 19dd6b8a..fd4fb8fe 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java @@ -68,7 +68,7 @@ public class AnyRunnModule { .load(url) //.addHeader("Accept-Encoding", "gzip") .setRequestMode(RequestEnum.GET) - .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1234567.apk") + .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg12345678.apk") //.resetState() .start(); //String[] urls = new String[] {