diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index c896c415..98cf7a27 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -28,17 +28,14 @@ import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; import android.widget.PopupWindow; -import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.inf.ICmd; import com.arialyy.aria.core.inf.IReceiver; 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.orm.DbEntity; import com.arialyy.aria.orm.DbUtil; 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 java.util.ArrayList; import java.util.HashMap; @@ -60,6 +57,7 @@ import java.util.Map; private Map mReceivers = new HashMap<>(); public static Context APP; private List mCommands = new ArrayList<>(); + private Configuration mConfig; private AriaManager(Context context) { DbUtil.init(context.getApplicationContext()); @@ -84,7 +82,7 @@ import java.util.Map; * 设置最大下载速度 */ 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) { - Configuration.getInstance().setTimeOut(timeOut); + Configuration_1.getInstance().setTimeOut(timeOut); return this; } @@ -167,7 +165,7 @@ import java.util.Map; * 设置失败重试次数 */ public AriaManager setReTryNum(int reTryNum) { - Configuration.getInstance().setReTryNum(reTryNum); + Configuration_1.getInstance().setReTryNum(reTryNum); return this; } @@ -175,7 +173,7 @@ import java.util.Map; * 设置失败重试间隔 */ public AriaManager setReTryInterval(int interval) { - Configuration.getInstance().setReTryInterval(interval); + Configuration_1.getInstance().setReTryInterval(interval); return this; } @@ -183,7 +181,7 @@ import java.util.Map; * 是否打开下载广播 */ public AriaManager openBroadcast(boolean open) { - Configuration.getInstance().setOpenBroadcast(open); + Configuration_1.getInstance().setOpenBroadcast(open); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java new file mode 100644 index 00000000..1c11d5f6 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -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 { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java index 0476ce8f..ca2cb6b5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java @@ -43,7 +43,7 @@ class ConnectionHelp { if (urlConn instanceof HttpsURLConnection) { conn = (HttpsURLConnection) urlConn; SSLContext sslContext = - SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_ALIAS); + SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_PATH); if (sslContext == null) { sslContext = SSLContextUtil.getDefaultSLLContext(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 27ffcc0b..2e3dc888 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -22,13 +22,12 @@ import android.os.Handler; import android.util.Log; import com.arialyy.aria.core.Aria; 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.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; -import com.arialyy.aria.util.Configuration; +import com.arialyy.aria.util.Configuration_1; import java.lang.ref.WeakReference; /** @@ -349,7 +348,7 @@ public class DownloadTask implements ITask { downloadEntity.setDownloadComplete(action.equals(Aria.ACTION_COMPLETE)); downloadEntity.setCurrentProgress(location); downloadEntity.update(); - if (!Configuration.isOpenBreadCast) return; + if (!Configuration_1.isOpenBreadCast) return; Intent intent = CommonUtil.createIntent(context.getPackageName(), action); intent.putExtra(Aria.ENTITY, downloadEntity); if (location != -1) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java index ee298579..bedf86c1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java @@ -21,7 +21,6 @@ import android.os.Message; import android.util.Log; import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.CommonUtil; -import com.arialyy.aria.util.Configuration; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -55,7 +54,7 @@ final class SingleThreadTask implements Runnable { if (mConfigEntity.isSupportBreakpoint) { mConfigFPath = downloadInfo.CONFIG_FILE_PATH; } - //mBufSize = Configuration.getInstance().getMaxSpeed(); + //mBufSize = Configuration_1.getInstance().getMaxSpeed(); } @Override public void run() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index a40d92b5..7bb7eba8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -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.ExecutePool; 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. @@ -121,7 +121,7 @@ public class DownloadTaskQueue @Override public void setDownloadNum(int downloadNum) { //原始长度 - int size = Configuration.getInstance().getDownloadNum(); + int size = Configuration_1.getInstance().getDownloadNum(); int diff = downloadNum - size; if (size == downloadNum) { Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java index 450018f6..29d23972 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java @@ -20,7 +20,7 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.inf.ITask; 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.Map; import java.util.concurrent.ArrayBlockingQueue; @@ -39,7 +39,7 @@ public class ExecutePool implements IPool { private int mSize; public ExecutePool() { - mSize = Configuration.getInstance().getDownloadNum(); + mSize = Configuration_1.getInstance().getDownloadNum(); mExecuteQueue = new ArrayBlockingQueue<>(mSize); mExecuteArray = new HashMap<>(); } @@ -81,7 +81,7 @@ public class ExecutePool implements IPool { } mExecuteQueue = temp; mSize = downloadNum; - Configuration.getInstance().setDownloadNum(mSize); + Configuration_1.getInstance().setDownloadNum(mSize); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java index 2ef63d82..21bb1189 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java @@ -22,7 +22,7 @@ import android.util.Log; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.download.DownloadEntity; 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.Map; import java.util.Set; @@ -86,7 +86,7 @@ public class DownloadSchedulers implements ISchedulers { case STOP: case CANCEL: mQueue.removeTask(entity); - if (mQueue.size() < Configuration.getInstance().getDownloadNum()) { + if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) { startNextTask(); } break; @@ -163,7 +163,7 @@ public class DownloadSchedulers implements ISchedulers { * @param 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) { @Override public void onTick(long millisUntilFinished) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java index b5108f6b..8c2777d2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java @@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadEntity; 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.Map; import java.util.Set; @@ -69,7 +69,7 @@ public class UploadSchedulers implements ISchedulers { } 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) { @Override public void onTick(long millisUntilFinished) { @@ -169,7 +169,7 @@ public class UploadSchedulers implements ISchedulers { case STOP: case CANCEL: mQueue.removeTask(entity); - if (mQueue.size() < Configuration.getInstance().getDownloadNum()) { + if (mQueue.size() < Configuration_1.getInstance().getDownloadNum()) { startNextTask(); } break; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index d35109b8..5aeba039 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -26,7 +26,7 @@ import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CommonUtil; -import com.arialyy.aria.util.Configuration; +import com.arialyy.aria.util.Configuration_1; import java.lang.ref.WeakReference; /** @@ -220,7 +220,7 @@ public class UploadTask implements ITask { entity.setComplete(action.equals(Aria.ACTION_COMPLETE)); entity.setCurrentProgress(location); entity.update(); - if (!Configuration.isOpenBreadCast) return; + if (!Configuration_1.isOpenBreadCast) return; Intent intent = CommonUtil.createIntent(AriaManager.APP.getPackageName(), action); intent.putExtra(Aria.ENTITY, entity); if (location != -1) { diff --git a/Aria/src/main/java/com/arialyy/aria/util/Configuration.java b/Aria/src/main/java/com/arialyy/aria/util/Configuration_1.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/util/Configuration.java rename to Aria/src/main/java/com/arialyy/aria/util/Configuration_1.java index 05081d1f..d89ffed4 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/Configuration.java +++ b/Aria/src/main/java/com/arialyy/aria/util/Configuration_1.java @@ -28,8 +28,8 @@ import java.util.WeakHashMap; * Created by AriaL on 2016/12/8. * 信息配置 */ -public class Configuration { - private static final String TAG = "Configuration"; +public class Configuration_1 { + private static final String TAG = "Configuration_1"; private static final String CONFIG_FILE = "/Aria/ADConfig.properties"; /** * 当前调度器最大下载数,默认最大下载数为 “2” @@ -58,20 +58,20 @@ public class Configuration { public static boolean isOpenBreadCast = false; - private static Configuration INSTANCE = null; + private static Configuration_1 INSTANCE = null; private File mConfigFile = null; private static final Object LOCK = new Object(); - public static Configuration getInstance() { + public static Configuration_1 getInstance() { if (INSTANCE == null) { synchronized (LOCK) { - INSTANCE = new Configuration(); + INSTANCE = new Configuration_1(); } } return INSTANCE; } - private Configuration() { + private Configuration_1() { mConfigFile = new File(AriaManager.APP.getFilesDir().getPath() + CONFIG_FILE); try { if (!mConfigFile.exists()) { diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml new file mode 100644 index 00000000..a87a1297 --- /dev/null +++ b/app/src/main/assets/aria_config.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file