AriaLyy
2017-06-13 16:55:30 +08:00
parent 0bc96efaaf
commit b2db650aa3
10 changed files with 157 additions and 348 deletions

View File

@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 315
versionName "3.1.5"
versionCode 317
versionName "3.1.7"
}
buildTypes {
release {
@ -23,8 +23,8 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaCompiler')
// compile project(':AriaAnnotations')
// compile project(':AriaCompiler')
compile project(':AriaAnnotations')
}
//apply from: 'jcenter.gradle'

View File

@ -26,6 +26,8 @@ import android.app.Service;
import android.content.Context;
import android.os.Build;
import android.widget.PopupWindow;
import com.arialyy.annotations.Download;
import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.scheduler.IDownloadSchedulerListener;
import com.arialyy.aria.core.scheduler.ISchedulerListener;
@ -171,7 +173,9 @@ import com.arialyy.aria.core.upload.UploadTask;
/**
* 上传任务状态监听
* @deprecated 请使用注解函数的方式来实现事件的获取{@see {@link Upload}}
*/
@Deprecated
public static class UploadSchedulerListener implements ISchedulerListener<UploadTask> {
/**
@ -218,7 +222,9 @@ import com.arialyy.aria.core.upload.UploadTask;
/**
* 下载任务状态监听
* @deprecated 请使用注解函数的方式来实现事件的获取{@see {@link Download}}
*/
@Deprecated
public static class DownloadSchedulerListener
implements IDownloadSchedulerListener<DownloadTask> {
/**

View File

@ -71,9 +71,29 @@ class ConnectionHelp {
}
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
conn.setRequestProperty("Accept",
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
StringBuilder accept = new StringBuilder();
accept.append("image/gif, ")
.append("image/jpeg, ")
.append("image/pjpeg, ")
.append("image/webp, ")
.append("image/*, ")
.append("application/xml")
.append("application/xaml+xml, ")
.append("application/xhtml+xml, ")
.append("application/x-shockwave-flash, ")
.append("application/x-ms-xbap, ")
.append("application/x-ms-application, ")
.append("application/msword, ")
.append("application/vnd.ms-excel, ")
.append("application/vnd.ms-xpsdocument, ")
.append("application/vnd.ms-powerpoint, ")
.append("text/plain, ")
.append("text/html, ")
.append("*/*");
conn.setRequestProperty("Accept", accept.toString());
conn.setRequestProperty("Accept-Encoding", "identity");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestProperty("Connection", "Keep-Alive");
//302获取重定向地址
conn.setInstanceFollowRedirects(false);

View File

@ -39,13 +39,13 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
public Object obj;
public ISchedulerListener<DownloadTask> listener;
/**
* 设置最大下载速度单位kb
* 该方法为实验性功能,清不要轻易在生产环境中使用。
*
* @param maxSpeed 为0表示不限速
*/
public void setMaxSpeed(double maxSpeed) {
@Deprecated public void setMaxSpeed(double maxSpeed) {
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMsxSpeed(maxSpeed);
}

View File

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
@ -27,7 +28,9 @@ import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
/**
* Created by lyy on 2017/1/18.
@ -41,8 +44,9 @@ final class SingleThreadTask implements Runnable {
private int mBufSize;
private IDownloadListener mListener;
private DownloadStateConstance CONSTANCE;
/**
* speed = (bufSize / 1024) * threadNum / sleepTime; (8192 / 1024) * 4 / 1= 32 kb/s
* speed = (bufSize / 1024) * CoresNum / sleepTime; (8192 / 1024) * 4 / 1= 32 kb/s
*/
private long mSleepTime = 0;
@ -65,14 +69,17 @@ final class SingleThreadTask implements Runnable {
if (-0.9999 < maxSpeed && maxSpeed < 0.00001) {
mSleepTime = 0;
} else {
BigDecimal db = new BigDecimal(((mBufSize / 1024) / maxSpeed) * 1000);
BigDecimal db = new BigDecimal(
((mBufSize / 1024) * (filterVersion() ? 1 : CONSTANCE.THREAD_NUM) / maxSpeed) * 1000);
db.setScale(0, BigDecimal.ROUND_HALF_UP);
mSleepTime = db.longValue();
//mSleepTime = (long) ((mBufSize / 1024) * CONSTANCE.THREAD_NUM / maxSpeed * 1000);
//mSleepTime = (long) ((mBufSize / 1024) / maxSpeed * 1000);
}
}
private boolean filterVersion() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
@Override public void run() {
HttpURLConnection conn;
InputStream is;
@ -92,7 +99,6 @@ final class SingleThreadTask implements Runnable {
//在头里面请求下载开始位置和结束位置
conn.setRequestProperty("Range",
"bytes=" + mConfigEntity.START_LOCATION + "-" + (mConfigEntity.END_LOCATION - 1));
//"bytes=" + mConfigEntity.START_LOCATION + "-" + (mConfigEntity.END_LOCATION));
} else {
Log.w(TAG, "该下载不支持断点");
}

View File

@ -26,6 +26,7 @@ import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -40,6 +41,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
/**
* Created by lyy on 2016/1/22.
@ -47,6 +49,35 @@ import java.util.Properties;
public class CommonUtil {
private static final String TAG = "CommonUtil";
/**
* 获取CPU核心数
*/
public static int getNumCores() {
//Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
@Override public boolean accept(File pathname) {
//Check if filename is "cpu", followed by a single digit number
return Pattern.matches("cpu[0-9]", pathname.getName());
}
}
try {
//Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
//Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
Log.d(TAG, "CPU Count: " + files.length);
//Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
//Print exception
Log.d(TAG, "CPU Count: Failed.");
e.printStackTrace();
//Default to return 1 core
return 1;
}
}
/**
* 通过流创建文件
*/
@ -75,7 +106,6 @@ public class CommonUtil {
}
String calculatedDigest = getFileMD5(updateFile);
Log.d(TAG, "fileMd5Code" + calculatedDigest);
if (calculatedDigest == null) {
Log.e(TAG, "calculatedDigest null");
return false;