cinfig准备重构

pull/330/head
AriaLyy 8 years ago
parent f9a3b50f36
commit 9882455cef
  1. 16
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 78
      Aria/src/main/java/com/arialyy/aria/core/Configuration.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java
  4. 5
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  5. 3
      Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java
  6. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  7. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
  8. 6
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  9. 6
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  10. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  11. 12
      Aria/src/main/java/com/arialyy/aria/util/Configuration_1.java
  12. 46
      app/src/main/assets/aria_config.xml

@ -28,17 +28,14 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.inf.ICmd; import com.arialyy.aria.core.inf.ICmd;
import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadReceiver; import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.util.CAConfiguration; import com.arialyy.aria.util.CAConfiguration;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import com.arialyy.aria.util.Speed; import com.arialyy.aria.util.Speed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -60,6 +57,7 @@ import java.util.Map;
private Map<String, IReceiver> mReceivers = new HashMap<>(); private Map<String, IReceiver> mReceivers = new HashMap<>();
public static Context APP; public static Context APP;
private List<ICmd> mCommands = new ArrayList<>(); private List<ICmd> mCommands = new ArrayList<>();
private Configuration mConfig;
private AriaManager(Context context) { private AriaManager(Context context) {
DbUtil.init(context.getApplicationContext()); DbUtil.init(context.getApplicationContext());
@ -84,7 +82,7 @@ import java.util.Map;
* 设置最大下载速度 * 设置最大下载速度
*/ */
public void setMaxSpeed(Speed speed) { public void setMaxSpeed(Speed speed) {
Configuration.getInstance().setMaxSpeed(speed); Configuration_1.getInstance().setMaxSpeed(speed);
} }
/** /**
@ -159,7 +157,7 @@ import java.util.Map;
* 设置下载超时时间 * 设置下载超时时间
*/ */
@Deprecated private AriaManager setTimeOut(int timeOut) { @Deprecated private AriaManager setTimeOut(int timeOut) {
Configuration.getInstance().setTimeOut(timeOut); Configuration_1.getInstance().setTimeOut(timeOut);
return this; return this;
} }
@ -167,7 +165,7 @@ import java.util.Map;
* 设置失败重试次数 * 设置失败重试次数
*/ */
public AriaManager setReTryNum(int reTryNum) { public AriaManager setReTryNum(int reTryNum) {
Configuration.getInstance().setReTryNum(reTryNum); Configuration_1.getInstance().setReTryNum(reTryNum);
return this; return this;
} }
@ -175,7 +173,7 @@ import java.util.Map;
* 设置失败重试间隔 * 设置失败重试间隔
*/ */
public AriaManager setReTryInterval(int interval) { public AriaManager setReTryInterval(int interval) {
Configuration.getInstance().setReTryInterval(interval); Configuration_1.getInstance().setReTryInterval(interval);
return this; return this;
} }
@ -183,7 +181,7 @@ import java.util.Map;
* 是否打开下载广播 * 是否打开下载广播
*/ */
public AriaManager openBroadcast(boolean open) { public AriaManager openBroadcast(boolean open) {
Configuration.getInstance().setOpenBroadcast(open); Configuration_1.getInstance().setOpenBroadcast(open);
return this; return this;
} }

@ -0,0 +1,78 @@
/*
* 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;
/**
* Created by AriaL on 2016/12/8.
* 信息配置
*/
class Configuration {
private static final String TAG = "Configuration";
private static final String CONFIG_FILE = "/Aria/ADConfig.properties";
private static final String CONFIG_KEY = "ARIA_CONFIG";
/**
* 通用配置
*/
static class BaseConfig {
public boolean isOpenBreadCast = false;
/**
* 任务队列最大任务数 默认为2
*/
public int maxQueueNum = 2;
/**
* 下载失败重试次数默认为10
*/
public int reTryNum = 10;
/**
* 设置重试间隔单位为毫秒默认2000毫秒
*/
public long reTryInterval = 2000;
/**
* 设置url连接超时时间单位为毫秒默认5000毫秒
*/
public long connectTimeOut = 5000;
}
/**
* 下载配置
*/
public static class DownloadConfig extends BaseConfig {
/**
* 设置IO流读取时间单位为毫秒默认20000毫秒该时间不能少于10000毫秒
*/
public long readTimeout = 20 * 1000;
/**
* 设置写文件buff大小该数值大小不能小于2048数值变小下载速度会变慢
*/
public int buffSize = 8192;
/**
* 设置https ca 证书信息path 为assets目录下的CA证书完整路径
*/
public String caPath;
/**
* name 为CA证书名
*/
public String caName;
}
/**
* 上传配置
*/
public static class UploadConfig extends BaseConfig {
}
}

@ -43,7 +43,7 @@ class ConnectionHelp {
if (urlConn instanceof HttpsURLConnection) { if (urlConn instanceof HttpsURLConnection) {
conn = (HttpsURLConnection) urlConn; conn = (HttpsURLConnection) urlConn;
SSLContext sslContext = SSLContext sslContext =
SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_ALIAS); SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_PATH);
if (sslContext == null) { if (sslContext == null) {
sslContext = SSLContextUtil.getDefaultSLLContext(); sslContext = SSLContextUtil.getDefaultSLLContext();
} }

@ -22,13 +22,12 @@ import android.os.Handler;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
/** /**
@ -349,7 +348,7 @@ public class DownloadTask implements ITask {
downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE)); downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE));
downloadEntity.setCurrentProgress(location); downloadEntity.setCurrentProgress(location);
downloadEntity.update(); downloadEntity.update();
if (!Configuration.isOpenBreadCast) return; if (!Configuration_1.isOpenBreadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action); Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
intent.putExtra(Aria.ENTITY, downloadEntity); intent.putExtra(Aria.ENTITY, downloadEntity);
if (location != -1) { if (location != -1) {

@ -21,7 +21,6 @@ import android.os.Message;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -55,7 +54,7 @@ final class SingleThreadTask implements Runnable {
if (mConfigEntity.isSupportBreakpoint) { if (mConfigEntity.isSupportBreakpoint) {
mConfigFPath = downloadInfo.CONFIG_FILE_PATH; mConfigFPath = downloadInfo.CONFIG_FILE_PATH;
} }
//mBufSize = Configuration.getInstance().getMaxSpeed(); //mBufSize = Configuration_1.getInstance().getMaxSpeed();
} }
@Override public void run() { @Override public void run() {

@ -25,7 +25,7 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.pool.CachePool; import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool; import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
/** /**
* Created by lyy on 2016/8/17. * Created by lyy on 2016/8/17.
@ -121,7 +121,7 @@ public class DownloadTaskQueue
@Override public void setDownloadNum(int downloadNum) { @Override public void setDownloadNum(int downloadNum) {
//原始长度 //原始长度
int size = Configuration.getInstance().getDownloadNum(); int size = Configuration_1.getInstance().getDownloadNum();
int diff = downloadNum - size; int diff = downloadNum - size;
if (size == downloadNum) { if (size == downloadNum) {
Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过"); Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");

@ -20,7 +20,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
@ -39,7 +39,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
private int mSize; private int mSize;
public ExecutePool() { public ExecutePool() {
mSize = Configuration.getInstance().getDownloadNum(); mSize = Configuration_1.getInstance().getDownloadNum();
mExecuteQueue = new ArrayBlockingQueue<>(mSize); mExecuteQueue = new ArrayBlockingQueue<>(mSize);
mExecuteArray = new HashMap<>(); mExecuteArray = new HashMap<>();
} }
@ -81,7 +81,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
} }
mExecuteQueue = temp; mExecuteQueue = temp;
mSize = downloadNum; mSize = downloadNum;
Configuration.getInstance().setDownloadNum(mSize); Configuration_1.getInstance().setDownloadNum(mSize);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -22,7 +22,7 @@ import android.util.Log;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -86,7 +86,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
case STOP: case STOP:
case CANCEL: case CANCEL:
mQueue.removeTask(entity); mQueue.removeTask(entity);
if (mQueue.size() < Configuration.getInstance().getDownloadNum()) { if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) {
startNextTask(); startNextTask();
} }
break; break;
@ -163,7 +163,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
* @param task 下载任务 * @param task 下载任务
*/ */
private void handleFailTask(final DownloadTask task) { private void handleFailTask(final DownloadTask task) {
final Configuration config = Configuration.getInstance(); final Configuration_1 config = Configuration_1.getInstance();
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) { CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
@Override public void onTick(long millisUntilFinished) { @Override public void onTick(long millisUntilFinished) {

@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -69,7 +69,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
} }
private void handleFailTask(final UploadTask task) { private void handleFailTask(final UploadTask task) {
final Configuration config = Configuration.getInstance(); final Configuration_1 config = Configuration_1.getInstance();
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) { CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
@Override public void onTick(long millisUntilFinished) { @Override public void onTick(long millisUntilFinished) {
@ -169,7 +169,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
case STOP: case STOP:
case CANCEL: case CANCEL:
mQueue.removeTask(entity); mQueue.removeTask(entity);
if (mQueue.size() < Configuration.getInstance().getDownloadNum()) { if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) {
startNextTask(); startNextTask();
} }
break; break;

@ -26,7 +26,7 @@ import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Configuration; import com.arialyy.aria.util.Configuration_1;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
/** /**
@ -220,7 +220,7 @@ public class UploadTask implements ITask {
entity.setComplete(action.equals(Aria.ACTION_COMPLETE)); entity.setComplete(action.equals(Aria.ACTION_COMPLETE));
entity.setCurrentProgress(location); entity.setCurrentProgress(location);
entity.update(); entity.update();
if (!Configuration.isOpenBreadCast) return; if (!Configuration_1.isOpenBreadCast) return;
Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action); Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action);
intent.putExtra(Aria.ENTITY, entity); intent.putExtra(Aria.ENTITY, entity);
if (location != -1) { if (location != -1) {

@ -28,8 +28,8 @@ import java.util.WeakHashMap;
* Created by AriaL on 2016/12/8. * Created by AriaL on 2016/12/8.
* 信息配置 * 信息配置
*/ */
public class Configuration { public class Configuration_1 {
private static final String TAG = "Configuration"; private static final String TAG = "Configuration_1";
private static final String CONFIG_FILE = "/Aria/ADConfig.properties"; private static final String CONFIG_FILE = "/Aria/ADConfig.properties";
/** /**
* 当前调度器最大下载数默认最大下载数为 2 * 当前调度器最大下载数默认最大下载数为 2
@ -58,20 +58,20 @@ public class Configuration {
public static boolean isOpenBreadCast = false; public static boolean isOpenBreadCast = false;
private static Configuration INSTANCE = null; private static Configuration_1 INSTANCE = null;
private File mConfigFile = null; private File mConfigFile = null;
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
public static Configuration getInstance() { public static Configuration_1 getInstance() {
if (INSTANCE == null) { if (INSTANCE == null) {
synchronized (LOCK) { synchronized (LOCK) {
INSTANCE = new Configuration(); INSTANCE = new Configuration_1();
} }
} }
return INSTANCE; return INSTANCE;
} }
private Configuration() { private Configuration_1() {
mConfigFile = new File(AriaManager.APP.getFilesDir().getPath() + CONFIG_FILE); mConfigFile = new File(AriaManager.APP.getFilesDir().getPath() + CONFIG_FILE);
try { try {
if (!mConfigFile.exists()) { if (!mConfigFile.exists()) {

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<aria>
<download>
<!--是否打开下载广播,默认为false-->
<openBroadcast value="false"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxQueueNum value="2"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="10"/>
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
<reTryInterval value="2000"/>
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<readTimeout value="20000"/>
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
<buffSize value="8192"/>
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
<ca name="" path=""/>
</download>
<upload>
<!--是否打开上传广播,默认为false-->
<openBroadcast value="false"/>
<!--设置上传队列最大任务数, 默认为2-->
<maxQueueNum value="2"/>
<!--设置上传失败,重试次数,默认为10-->
<reTryNum value="10"/>
<!--设置重试间隔,单位为毫秒-->
<reTryInterval value="2000"/>
<!--设置url连接超时时间,单位为毫秒,默认5000毫秒-->
<connectTimeOut value="5000"/>
</upload>
</aria>
Loading…
Cancel
Save