新增201 重定向支持 https://github.com/AriaLyy/Aria/issues/318
修复使用`useServerFileName(true)`中含有`"`导致的文件后缀名错误问题
修改下载线程的优先级为: Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
v3.6.6
laoyuyu 6 years ago
parent e22e2dc840
commit a625bd27a3
  1. 4
      Aria/build.gradle
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 12
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/SSLSessionReuseFTPSClient.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  7. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java
  9. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  10. 8
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  11. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  12. 5
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  14. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java
  15. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  16. 41
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  17. 8
      Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
  18. 2
      AriaAnnotations/build.gradle
  19. 2
      AriaCompiler/build.gradle
  20. 2
      AriaFtpPlug/build.gradle
  21. 5
      AriaFtpPlug/src/main/java/aria/apache/commons/net/util/TrustManagerUtils.java
  22. 5
      DEV_LOG.md
  23. 11
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  24. 4
      build.gradle
  25. 2
      gradle.properties

@ -26,8 +26,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaAnnotations')
compile 'com.arialyy.aria:aria-ftp-plug:1.0.3'
compile 'com.arialyy.aria:aria-ftp-plug:1.0.4'
// compile project(':AriaFtpPlug')
}
//apply from: 'bintray-release.gradle'
apply from: 'bintray-release.gradle'

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.common;
import android.os.Process;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -74,6 +75,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
private Thread mConfigThread = new Thread(new Runnable() {
@Override public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
final long currentTemp = mChildCurrentLocation;
writeConfig(false, currentTemp);
}
@ -460,6 +462,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
@Override public AbsThreadTask call() throws Exception {
isInterrupted = false;
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
return this;
}
}

@ -15,7 +15,13 @@
*/
package com.arialyy.aria.core.common.ftp;
import android.os.Process;
import android.text.TextUtils;
import aria.apache.commons.net.ftp.FTP;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPFile;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.OnFileInfoCallback;
@ -37,11 +43,6 @@ import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
/**
* Created by Aria.Lao on 2017/7/25.
@ -78,6 +79,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
protected abstract String setRemotePath();
@Override public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
FTPClient client = null;
try {
client = createFtpClient();

@ -16,6 +16,10 @@
package com.arialyy.aria.core.common.ftp;
import android.text.TextUtils;
import aria.apache.commons.net.ftp.FTP;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.ProtocolType;
@ -30,10 +34,6 @@ import com.arialyy.aria.util.SSLContextUtil;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.net.ssl.SSLContext;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
/**
* Created by lyy on 2017/9/26.

@ -1,6 +1,6 @@
package com.arialyy.aria.core.common.ftp;
import com.arialyy.aria.util.ALog;
import aria.apache.commons.net.ftp.FTPSClient;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@ -10,7 +10,6 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.SSLSocket;
import org.apache.commons.net.ftp.FTPSClient;
public class SSLSessionReuseFTPSClient extends FTPSClient {
@ -40,7 +39,6 @@ public class SSLSessionReuseFTPSClient extends FTPSClient {
String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT), session);
method.invoke(cache, String.format("%s:%s", socket.getInetAddress().getHostAddress(),
String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT), session);
ALog.d("tag", "GGGG");
} catch (NoSuchFieldException e) {
throw new IOException(e);
} catch (Exception e) {

@ -111,7 +111,7 @@ class ConnectionHelp {
}
}
if (conn.getRequestProperty("Accept-Language") == null) {
conn.setRequestProperty("Accept-Language", "UTF-8");
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7");
}
if (conn.getRequestProperty("Accept-Encoding") == null) {
conn.setRequestProperty("Accept-Encoding", "identity");

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download.downloader;
import aria.apache.commons.net.ftp.FTPFile;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback;
@ -27,7 +28,6 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.util.CommonUtil;
import java.nio.charset.Charset;
import java.util.ArrayList;
import org.apache.commons.net.ftp.FTPFile;
/**
* Created by Aria.Lao on 2017/7/25.

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download.downloader;
import aria.apache.commons.net.ftp.FTPFile;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
@ -22,7 +23,6 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.CommonUtil;
import org.apache.commons.net.ftp.FTPFile;
/**
* Created by Aria.Lao on 2017/7/25.

@ -15,6 +15,8 @@
*/
package com.arialyy.aria.core.download.downloader;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPReply;
import com.arialyy.aria.core.common.StateConstance;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask;
@ -32,8 +34,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
/**
* Created by Aria.Lao on 2017/7/24.

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download.downloader;
import android.os.Process;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.CompleteInfo;
@ -59,6 +60,7 @@ class HttpFileInfoThread implements Runnable {
}
@Override public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
HttpURLConnection conn = null;
try {
URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl()));
@ -144,7 +146,7 @@ class HttpFileInfoThread implements Runnable {
if (info.startsWith("filename") && info.contains("=")) {
String[] temp = info.split("=");
if (temp.length > 1) {
String newName = URLDecoder.decode(temp[1], "utf-8");
String newName = URLDecoder.decode(temp[1], "utf-8").replaceAll("\"", "");
mEntity.setServerFileName(newName);
renameFile(newName);
break;
@ -191,11 +193,13 @@ class HttpFileInfoThread implements Runnable {
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|| code == HttpURLConnection.HTTP_MOVED_PERM
|| code == HttpURLConnection.HTTP_SEE_OTHER
|| code == HttpURLConnection.HTTP_CREATED // 201 跳转
|| code == 307) {
handleUrlReTurn(conn, conn.getHeaderField("Location"));
} else {
failDownload(new AriaIOException(TAG,
String.format("任务下载失败,errorCode:%s, url: %s", code, mEntity.getUrl())), true);
String.format("任务下载失败,errorCode:%s, errorMsg: %s, url: %s", code,
conn.getResponseMessage(), mEntity.getUrl())), true);
}
if (end) {
mTaskEntity.setChunked(isChunked);

@ -76,7 +76,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
int state = task.getState();
if (task.isRunning() || (state != IEntity.STATE_COMPLETE
&& state != IEntity.STATE_CANCEL)) {
task.stop();
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
}
}
}

@ -263,7 +263,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
if (!task.needRetry || task.isStop() || task.isCancel()) {
callback(FAIL, task);
mQueue.removeTaskFormQueue(task.getKey());
ALog.d(TAG, "fail_next");
startNextTask(task);
return;
}
@ -287,7 +286,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
callback(FAIL, task);
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
ALog.d(TAG, "retry_next");
TEManager.getInstance().removeTEntity(task.getKey());
return;
}
@ -306,7 +304,6 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
} else {
mQueue.removeTaskFormQueue(task.getKey());
startNextTask(task);
ALog.d(TAG, "retry_next_1");
TEManager.getInstance().removeTEntity(task.getKey());
}
}
@ -324,7 +321,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
TASK newTask = mQueue.getNextTask();
if (newTask == null) {
if (mQueue.getCurrentExePoolNum() == 0) {
ALog.i(TAG, "没有下一任务");
ALog.i(TAG, "没有等待中的任务");
}
return;
}

@ -61,7 +61,7 @@ public interface ISchedulerListener<TASK extends ITask> {
/**
* 任务失败
*
* @deprecated @see{{@link #onTaskFail(ITask, Exception)}}
* @deprecated {@link #onTaskFail(ITask, Exception)}
*/
@Deprecated
void onTaskFail(TASK task);

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.upload.uploader;
import aria.apache.commons.net.ftp.FTPFile;
import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback;
@ -25,7 +26,6 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.DbHelper;
import java.util.ArrayList;
import org.apache.commons.net.ftp.FTPFile;
/**
* Created by Aria.Lao on 2017/9/26.

@ -15,6 +15,9 @@
*/
package com.arialyy.aria.core.upload.uploader;
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.OnFtpInputStreamListener;
import com.arialyy.aria.core.common.StateConstance;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask;
@ -27,9 +30,6 @@ import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.OnFtpInputStreamListener;
/**
* Created by Aria.Lao on 2017/7/28.

@ -54,14 +54,17 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -352,25 +355,25 @@ public class CommonUtil {
public static String convertUrl(String url) {
Uri uri = Uri.parse(url);
url = uri.toString();
//if (hasDoubleCharacter(url)) {
// //预先处理空格,URLEncoder只会把空格转换为+
// url = url.replaceAll(" ", "%20");
// //匹配双字节字符(包括汉字在内)
// String regex = Regular.REG_DOUBLE_CHAR_AND_SPACE;
// Pattern p = Pattern.compile(regex);
// Matcher m = p.matcher(url);
// Set<String> strs = new HashSet<>();
// while (m.find()) {
// strs.add(m.group());
// }
// try {
// for (String str : strs) {
// url = url.replaceAll(str, URLEncoder.encode(str, "UTF-8"));
// }
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
//}
if (hasDoubleCharacter(url)) {
//预先处理空格,URLEncoder只会把空格转换为+
url = url.replaceAll(" ", "%20");
//匹配双字节字符(包括汉字在内)
String regex = Regular.REG_DOUBLE_CHAR_AND_SPACE;
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(url);
Set<String> strs = new HashSet<>();
while (m.find()) {
strs.add(m.group());
}
try {
for (String str : strs) {
url = url.replaceAll(str, URLEncoder.encode(str, "UTF-8"));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return url;
}

@ -47,7 +47,7 @@ public class ErrorHelp {
*/
private static String getLogPath() {
String path = String.format("%slog/AriaCrash_%s.log", CommonUtil.getAppPath(AriaManager.APP),
getData("yyyy-MM-dd_HH:mm:ss"));
getData("yyyy-MM-dd_HH_mm_ss"));
File log = new File(path);
if (!log.getParentFile().exists()) {
@ -76,7 +76,11 @@ public class ErrorHelp {
stringBuffer.append("\n\n");
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileWriter(getLogPath(), true));
File file = new File(getLogPath());
if(!file.exists()){
CommonUtil.createFile(file.getPath());
}
writer = new PrintWriter(new FileWriter(file.getPath(), true));
writer.append(stringBuffer);
writer.flush();
} catch (Exception e) {

@ -11,4 +11,4 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
//apply from: 'bintray-release.gradle'
apply from: 'bintray-release.gradle'

@ -14,4 +14,4 @@ dependencies {
compile project(':AriaAnnotations')
}
//apply from: 'bintray-release.gradle'
apply from: 'bintray-release.gradle'

@ -11,4 +11,4 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply from: 'bintray-release.gradle'
//apply from: 'bintray-release.gradle'

@ -19,9 +19,12 @@ package aria.apache.commons.net.util;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
@ -92,7 +95,7 @@ public final class TrustManagerUtils {
* Return the default TrustManager provided by the JVM.
* <p>
* This should be the same as the default used by
* {@link javax.net.ssl.SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], * java.security.SecureRandom)
* {@link javax.net.ssl.SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], SecureRandom)}
* SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
* when the TrustManager parameter is set to {@code null}
*

@ -9,6 +9,11 @@
}
```
- fix bug https://github.com/AriaLyy/Aria/issues/322
- 新增201 重定向支持 https://github.com/AriaLyy/Aria/issues/318
- 修复使用`useServerFileName(true)`中含有`"`导致的文件后缀名错误问题
- 优化logcat日志提示
- 修改下载线程的优先级为`Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);`
- fix bug https://github.com/AriaLyy/Aria/issues/319
+ v_3.5.1
- 优化`taskExists`方法
- 添加`post`参数请求支持

@ -50,7 +50,8 @@ 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.apks";
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks";
//"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
@ -60,6 +61,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"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";
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@ -249,7 +251,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private void startD() {
//Aria.get(this).setLogLevel(ALog.LOG_CLOSE);
//Aria.download(this).load("aaaa.apk");
String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg10.apk";
String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg11.apk";
//File file = new File(path);
//if (file.exists()){
// file.delete();
@ -261,9 +263,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.addHeader("Accept-Encoding", "gzip, deflate")
//.addHeader("DNT", "1")
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
//.useServerFileName(true)
//.setRequestMode(RequestEnum.GET)
.setFilePath(path, false)
.useServerFileName(true)
.setFilePath(path, true)
//.asPost().setParam("key", "value")
//.setExtendField("{\n"
// + "\"id\":\"你的样子\"\n< > "

@ -39,8 +39,8 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
// publishVersion = '3.5.1'
publishVersion = '1.0.4' //FTP插件
publishVersion = '3.5.2_dev'
// publishVersion = '1.0.4' //FTP插件
repoName='maven'
desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria'

@ -17,5 +17,5 @@
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
#systemProp.socksProxyHost=127.0.0.1
#systemProp.socksProxyPort=60777
#systemProp.socksProxyPort=1080
#systemprop.socksProxyVersion=5
Loading…
Cancel
Save