|
|
@ -23,141 +23,103 @@ import com.arialyy.aria.core.queue.UploadTaskQueue; |
|
|
|
import com.arialyy.aria.util.ALog; |
|
|
|
import com.arialyy.aria.util.ALog; |
|
|
|
import com.arialyy.aria.util.AriaCrashHandler; |
|
|
|
import com.arialyy.aria.util.AriaCrashHandler; |
|
|
|
import com.arialyy.aria.util.CommonUtil; |
|
|
|
import com.arialyy.aria.util.CommonUtil; |
|
|
|
import com.arialyy.aria.util.ErrorHelp; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.io.Serializable; |
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by lyy on 2016/12/8. |
|
|
|
* Created by lyy on 2016/12/8. 信息配置 |
|
|
|
* 信息配置 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Configuration { |
|
|
|
final class Configuration { |
|
|
|
static final String TAG = "Configuration"; |
|
|
|
private static final String TAG = "Configuration"; |
|
|
|
static final String DOWNLOAD_CONFIG_FILE = "/Aria/DownloadConfig.properties"; |
|
|
|
private static final String DOWNLOAD_CONFIG_FILE = "/Aria/AriaDownload.cfg"; |
|
|
|
static final String UPLOAD_CONFIG_FILE = "/Aria/UploadConfig.properties"; |
|
|
|
private static final String UPLOAD_CONFIG_FILE = "/Aria/AriaUpload.cfg"; |
|
|
|
static final String APP_CONFIG_FILE = "/Aria/AppConfig.properties"; |
|
|
|
private static final String APP_CONFIG_FILE = "/Aria/AriaApp.cfg"; |
|
|
|
|
|
|
|
private static final int TYPE_DOWNLOAD = 1; |
|
|
|
|
|
|
|
private static final int TYPE_UPLOAD = 2; |
|
|
|
|
|
|
|
private static final int TYPE_APP = 3; |
|
|
|
|
|
|
|
private static volatile Configuration INSTANCE = null; |
|
|
|
static final String XML_FILE = "/Aria/aria_config.xml"; |
|
|
|
static final String XML_FILE = "/Aria/aria_config.xml"; |
|
|
|
static final int TYPE_DOWNLOAD = 1; |
|
|
|
DownloadConfig downloadCfg; |
|
|
|
static final int TYPE_UPLOAD = 2; |
|
|
|
UploadConfig uploadCfg; |
|
|
|
static final int TYPE_APP = 3; |
|
|
|
AppConfig appCfg; |
|
|
|
|
|
|
|
|
|
|
|
abstract static class BaseConfig { |
|
|
|
private Configuration() { |
|
|
|
|
|
|
|
//删除老版本的配置文件
|
|
|
|
/** |
|
|
|
String basePath = AriaManager.APP.getFilesDir().getPath(); |
|
|
|
* 类型 |
|
|
|
File oldDCfg = new File(String.format("%s/Aria/DownloadConfig.properties", basePath)); |
|
|
|
* |
|
|
|
if (oldDCfg.exists()) { // 只需要判断一个
|
|
|
|
* @return {@link #TYPE_DOWNLOAD}、{@link #TYPE_UPLOAD}、{@link #TYPE_APP} |
|
|
|
File oldUCfg = new File(String.format("%s/Aria/UploadConfig.properties", basePath)); |
|
|
|
*/ |
|
|
|
File oldACfg = new File(String.format("%s/Aria/AppConfig.properties", basePath)); |
|
|
|
abstract int getType(); |
|
|
|
oldDCfg.delete(); |
|
|
|
|
|
|
|
oldUCfg.delete(); |
|
|
|
/** |
|
|
|
oldACfg.delete(); |
|
|
|
* 加载配置 |
|
|
|
// 删除配置触发更新
|
|
|
|
*/ |
|
|
|
File temp = new File(String.format("%s%s", basePath, XML_FILE)); |
|
|
|
void loadConfig() { |
|
|
|
if (temp.exists()) { |
|
|
|
String path = null; |
|
|
|
temp.delete(); |
|
|
|
Class clazz = null; |
|
|
|
|
|
|
|
switch (getType()) { |
|
|
|
|
|
|
|
case TYPE_DOWNLOAD: |
|
|
|
|
|
|
|
path = DOWNLOAD_CONFIG_FILE; |
|
|
|
|
|
|
|
clazz = DownloadConfig.class; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_UPLOAD: |
|
|
|
|
|
|
|
path = UPLOAD_CONFIG_FILE; |
|
|
|
|
|
|
|
clazz = UploadConfig.class; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_APP: |
|
|
|
|
|
|
|
path = APP_CONFIG_FILE; |
|
|
|
|
|
|
|
clazz = AppConfig.class; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (TextUtils.isEmpty(path)) { |
|
|
|
|
|
|
|
ALog.e(TAG, "读取配置失败:未知文件类型"); |
|
|
|
|
|
|
|
ErrorHelp.saveError(TAG, "读取配置失败:未知文件类型", ""); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File file = new File(AriaManager.APP.getFilesDir().getPath() + path); |
|
|
|
|
|
|
|
if (file.exists()) { |
|
|
|
|
|
|
|
Properties properties = CommonUtil.loadConfig(file); |
|
|
|
|
|
|
|
List<Field> fields = CommonUtil.getAllFields(clazz); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (Field field : fields) { |
|
|
|
|
|
|
|
int m = field.getModifiers(); |
|
|
|
|
|
|
|
String fileName = field.getName(); |
|
|
|
|
|
|
|
if (fileName.equals("oldMaxTaskNum") |
|
|
|
|
|
|
|
|| field.isSynthetic() |
|
|
|
|
|
|
|
|| Modifier.isFinal(m) |
|
|
|
|
|
|
|
|| Modifier.isStatic(m) |
|
|
|
|
|
|
|
|| fileName.equals("shadow$_klass_") |
|
|
|
|
|
|
|
|| fileName.equals("shadow$_monitor_")) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
|
|
String value = properties.getProperty(field.getName()); |
|
|
|
|
|
|
|
if (TextUtils.isEmpty(value) || value.equalsIgnoreCase("null")) continue; |
|
|
|
|
|
|
|
Class<?> type = field.getType(); |
|
|
|
|
|
|
|
if (type == String.class) { |
|
|
|
|
|
|
|
field.set(this, value); |
|
|
|
|
|
|
|
} else if (type == int.class || type == Integer.class) { |
|
|
|
|
|
|
|
if (fileName.equalsIgnoreCase("maxSpeed")) { //兼容以前版本,以前maxSpeed是double类型的
|
|
|
|
|
|
|
|
Double d = Double.parseDouble(value); |
|
|
|
|
|
|
|
field.setInt(this, (int) d.doubleValue()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
field.setInt(this, Integer.parseInt(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else if (type == float.class || type == Float.class) { |
|
|
|
File newDCfg = new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE)); |
|
|
|
field.setFloat(this, Float.parseFloat(value)); |
|
|
|
File newUCfg = new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE)); |
|
|
|
} else if (type == double.class || type == Double.class) { |
|
|
|
File newACfg = new File(String.format("%s%s", basePath, APP_CONFIG_FILE)); |
|
|
|
if (TextUtils.isEmpty(value)) { |
|
|
|
// 加载下载配置
|
|
|
|
value = "0"; |
|
|
|
if (newDCfg.exists()) { |
|
|
|
|
|
|
|
downloadCfg = (DownloadConfig) CommonUtil.readObjFromFile(newDCfg.getPath()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (downloadCfg == null) { |
|
|
|
|
|
|
|
downloadCfg = new DownloadConfig(); |
|
|
|
} |
|
|
|
} |
|
|
|
field.setDouble(this, Double.parseDouble(value)); |
|
|
|
// 加载上传配置
|
|
|
|
} else if (type == long.class || type == Long.class) { |
|
|
|
if (newUCfg.exists()) { |
|
|
|
field.setLong(this, Long.parseLong(value)); |
|
|
|
uploadCfg = (UploadConfig) CommonUtil.readObjFromFile(newUCfg.getPath()); |
|
|
|
} else if (type == boolean.class || type == Boolean.class) { |
|
|
|
|
|
|
|
field.setBoolean(this, Boolean.parseBoolean(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (uploadCfg == null) { |
|
|
|
|
|
|
|
uploadCfg = new UploadConfig(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
// 加载app配置
|
|
|
|
e.printStackTrace(); |
|
|
|
if (newACfg.exists()) { |
|
|
|
|
|
|
|
appCfg = (AppConfig) CommonUtil.readObjFromFile(newACfg.getPath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (appCfg == null) { |
|
|
|
|
|
|
|
appCfg = new AppConfig(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
static Configuration getInstance() { |
|
|
|
* 保存key |
|
|
|
if (INSTANCE == null) { |
|
|
|
*/ |
|
|
|
synchronized (AppConfig.class) { |
|
|
|
void saveKey(String key, String value) { |
|
|
|
INSTANCE = new Configuration(); |
|
|
|
String path = null; |
|
|
|
|
|
|
|
switch (getType()) { |
|
|
|
|
|
|
|
case TYPE_DOWNLOAD: |
|
|
|
|
|
|
|
path = DOWNLOAD_CONFIG_FILE; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_UPLOAD: |
|
|
|
|
|
|
|
path = UPLOAD_CONFIG_FILE; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_APP: |
|
|
|
|
|
|
|
path = APP_CONFIG_FILE; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
File file = new File( |
|
|
|
|
|
|
|
AriaManager.APP.getFilesDir().getPath() + path); |
|
|
|
|
|
|
|
if (file.exists()) { |
|
|
|
|
|
|
|
Properties properties = CommonUtil.loadConfig(file); |
|
|
|
|
|
|
|
properties.setProperty(key, value); |
|
|
|
|
|
|
|
CommonUtil.saveConfig(file, properties); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return INSTANCE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 检查配置文件是否存在,只要{@link DownloadConfig}、{@link UploadConfig}、{@link AppConfig}其中一个不存在 则任务配置文件不存在 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return {@code true}配置存在,{@code false}配置不存在 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
boolean configExists() { |
|
|
|
|
|
|
|
String basePath = AriaManager.APP.getFilesDir().getPath(); |
|
|
|
|
|
|
|
return (new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE))).exists() |
|
|
|
|
|
|
|
&& (new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE))).exists() |
|
|
|
|
|
|
|
&& (new File(String.format("%s%s", basePath, APP_CONFIG_FILE))).exists(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract static class BaseConfig implements Serializable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 类型 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return {@link #TYPE_DOWNLOAD}、{@link #TYPE_UPLOAD}、{@link #TYPE_APP} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
abstract int getType(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 保存配置 |
|
|
|
* 保存配置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void saveAll() { |
|
|
|
void save() { |
|
|
|
List<Field> fields = CommonUtil.getAllFields(getClass()); |
|
|
|
String basePath = AriaManager.APP.getFilesDir().getPath(); |
|
|
|
try { |
|
|
|
|
|
|
|
String path = null; |
|
|
|
String path = null; |
|
|
|
switch (getType()) { |
|
|
|
switch (getType()) { |
|
|
|
case TYPE_DOWNLOAD: |
|
|
|
case TYPE_DOWNLOAD: |
|
|
@ -170,21 +132,12 @@ public class Configuration { |
|
|
|
path = APP_CONFIG_FILE; |
|
|
|
path = APP_CONFIG_FILE; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
File file = new File( |
|
|
|
if (!TextUtils.isEmpty(path)) { |
|
|
|
AriaManager.APP.getFilesDir().getPath() + path); |
|
|
|
String tempPath = String.format("%s%s", basePath, path); |
|
|
|
Properties properties = CommonUtil.loadConfig(file); |
|
|
|
CommonUtil.deleteFile(tempPath); |
|
|
|
for (Field field : fields) { |
|
|
|
CommonUtil.writeObjToFile(tempPath, this); |
|
|
|
int m = field.getModifiers(); |
|
|
|
} else { |
|
|
|
if (field.isSynthetic() || Modifier.isFinal(m) || Modifier.isStatic(m) || field.getName() |
|
|
|
ALog.e(TAG, String.format("保存配置失败,配置类型:%s,原因:路径错误", getType())); |
|
|
|
.equals("shadow$_klass_") || field.getName().equals("shadow$_monitor_")) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
field.setAccessible(true); |
|
|
|
|
|
|
|
properties.setProperty(field.getName(), field.get(this) + ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CommonUtil.saveConfig(file, properties); |
|
|
|
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -192,7 +145,7 @@ public class Configuration { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通用任务配置 |
|
|
|
* 通用任务配置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
abstract static class BaseTaskConfig extends BaseConfig { |
|
|
|
abstract static class BaseTaskConfig extends BaseConfig implements Serializable { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢 |
|
|
|
* 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢 |
|
|
@ -259,7 +212,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setMaxSpeed(int maxSpeed) { |
|
|
|
public BaseTaskConfig setMaxSpeed(int maxSpeed) { |
|
|
|
this.maxSpeed = maxSpeed; |
|
|
|
this.maxSpeed = maxSpeed; |
|
|
|
saveKey("maxSpeed", String.valueOf(maxSpeed)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -278,7 +231,7 @@ public class Configuration { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
this.updateInterval = updateInterval; |
|
|
|
this.updateInterval = updateInterval; |
|
|
|
saveKey("updateInterval", String.valueOf(updateInterval)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -288,7 +241,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setQueueMod(String queueMod) { |
|
|
|
public BaseTaskConfig setQueueMod(String queueMod) { |
|
|
|
this.queueMod = queueMod; |
|
|
|
this.queueMod = queueMod; |
|
|
|
saveKey("queueMod", queueMod); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -302,7 +255,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setReTryNum(int reTryNum) { |
|
|
|
public BaseTaskConfig setReTryNum(int reTryNum) { |
|
|
|
this.reTryNum = reTryNum; |
|
|
|
this.reTryNum = reTryNum; |
|
|
|
saveKey("reTryNum", String.valueOf(reTryNum)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -312,7 +265,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setReTryInterval(int reTryInterval) { |
|
|
|
public BaseTaskConfig setReTryInterval(int reTryInterval) { |
|
|
|
this.reTryInterval = reTryInterval; |
|
|
|
this.reTryInterval = reTryInterval; |
|
|
|
saveKey("reTryInterval", String.valueOf(reTryInterval)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -322,7 +275,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setConvertSpeed(boolean convertSpeed) { |
|
|
|
public BaseTaskConfig setConvertSpeed(boolean convertSpeed) { |
|
|
|
isConvertSpeed = convertSpeed; |
|
|
|
isConvertSpeed = convertSpeed; |
|
|
|
saveKey("isConvertSpeed", String.valueOf(isConvertSpeed)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -332,7 +285,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setConnectTimeOut(int connectTimeOut) { |
|
|
|
public BaseTaskConfig setConnectTimeOut(int connectTimeOut) { |
|
|
|
this.connectTimeOut = connectTimeOut; |
|
|
|
this.connectTimeOut = connectTimeOut; |
|
|
|
saveKey("connectTimeOut", String.valueOf(connectTimeOut)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -342,7 +295,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setNotNetRetry(boolean notNetRetry) { |
|
|
|
public BaseTaskConfig setNotNetRetry(boolean notNetRetry) { |
|
|
|
this.notNetRetry = notNetRetry; |
|
|
|
this.notNetRetry = notNetRetry; |
|
|
|
saveKey("notNetRetry", String.valueOf(notNetRetry)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -352,7 +305,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setIOTimeOut(int iOTimeOut) { |
|
|
|
public BaseTaskConfig setIOTimeOut(int iOTimeOut) { |
|
|
|
this.iOTimeOut = iOTimeOut; |
|
|
|
this.iOTimeOut = iOTimeOut; |
|
|
|
saveKey("iOTimeOut", String.valueOf(iOTimeOut)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -362,7 +315,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public BaseTaskConfig setBuffSize(int buffSize) { |
|
|
|
public BaseTaskConfig setBuffSize(int buffSize) { |
|
|
|
this.buffSize = buffSize; |
|
|
|
this.buffSize = buffSize; |
|
|
|
saveKey("buffSize", String.valueOf(buffSize)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -370,7 +323,7 @@ public class Configuration { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 下载配置 |
|
|
|
* 下载配置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static class DownloadConfig extends BaseTaskConfig { |
|
|
|
public static class DownloadConfig extends BaseTaskConfig implements Serializable { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置https ca 证书信息;path 为assets目录下的CA证书完整路径 |
|
|
|
* 设置https ca 证书信息;path 为assets目录下的CA证书完整路径 |
|
|
@ -381,22 +334,14 @@ public class Configuration { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
String caName; |
|
|
|
String caName; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 下载线程数,下载线程数不能小于1 |
|
|
|
* 下载线程数,下载线程数不能小于1 注意: 1、线程下载数改变后,新的下载任务才会生效; 2、如果任务大小小于1m,该设置不会生效; |
|
|
|
* 注意: |
|
|
|
* 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; |
|
|
|
* 1、线程下载数改变后,新的下载任务才会生效; |
|
|
|
|
|
|
|
* 2、如果任务大小小于1m,该设置不会生效; |
|
|
|
|
|
|
|
* 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; |
|
|
|
|
|
|
|
* 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int threadNum = 3; |
|
|
|
int threadNum = 3; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 |
|
|
|
* 多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 注意: 1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; |
|
|
|
* 注意: |
|
|
|
* 2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 |
|
|
|
* 1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; |
|
|
|
|
|
|
|
* 2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; |
|
|
|
|
|
|
|
* 3、只对新的多线程下载任务有效 |
|
|
|
|
|
|
|
* 4、只对多线程的任务有效 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean useBlock = false; |
|
|
|
boolean useBlock = false; |
|
|
|
|
|
|
|
|
|
|
@ -413,21 +358,21 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public DownloadConfig setUseBlock(boolean useBlock) { |
|
|
|
public DownloadConfig setUseBlock(boolean useBlock) { |
|
|
|
this.useBlock = useBlock; |
|
|
|
this.useBlock = useBlock; |
|
|
|
saveKey("useBlock", String.valueOf(useBlock)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DownloadConfig setMaxTaskNum(int maxTaskNum) { |
|
|
|
public DownloadConfig setMaxTaskNum(int maxTaskNum) { |
|
|
|
oldMaxTaskNum = this.maxTaskNum; |
|
|
|
oldMaxTaskNum = this.maxTaskNum; |
|
|
|
this.maxTaskNum = maxTaskNum; |
|
|
|
this.maxTaskNum = maxTaskNum; |
|
|
|
saveKey("maxTaskNum", String.valueOf(maxTaskNum)); |
|
|
|
|
|
|
|
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); |
|
|
|
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); |
|
|
|
|
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DownloadConfig setThreadNum(int threadNum) { |
|
|
|
public DownloadConfig setThreadNum(int threadNum) { |
|
|
|
this.threadNum = threadNum; |
|
|
|
this.threadNum = threadNum; |
|
|
|
saveKey("threadNum", String.valueOf(threadNum)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -437,7 +382,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public DownloadConfig setCaPath(String caPath) { |
|
|
|
public DownloadConfig setCaPath(String caPath) { |
|
|
|
this.caPath = caPath; |
|
|
|
this.caPath = caPath; |
|
|
|
saveKey("caPath", caPath); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -447,7 +392,7 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public DownloadConfig setCaName(String caName) { |
|
|
|
public DownloadConfig setCaName(String caName) { |
|
|
|
this.caName = caName; |
|
|
|
this.caName = caName; |
|
|
|
saveKey("caName", caName); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -456,18 +401,6 @@ public class Configuration { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private DownloadConfig() { |
|
|
|
private DownloadConfig() { |
|
|
|
loadConfig(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static DownloadConfig INSTANCE = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static DownloadConfig getInstance() { |
|
|
|
|
|
|
|
if (INSTANCE == null) { |
|
|
|
|
|
|
|
synchronized (DownloadConfig.class) { |
|
|
|
|
|
|
|
INSTANCE = new DownloadConfig(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return INSTANCE; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override int getType() { |
|
|
|
@Override int getType() { |
|
|
@ -478,11 +411,11 @@ public class Configuration { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 上传配置 |
|
|
|
* 上传配置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static class UploadConfig extends BaseTaskConfig { |
|
|
|
public static class UploadConfig extends BaseTaskConfig implements Serializable { |
|
|
|
private static UploadConfig INSTANCE = null; |
|
|
|
private static UploadConfig INSTANCE = null; |
|
|
|
|
|
|
|
|
|
|
|
private UploadConfig() { |
|
|
|
private UploadConfig() { |
|
|
|
loadConfig(); |
|
|
|
//loadConfig();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public UploadConfig setMaxSpeed(int maxSpeed) { |
|
|
|
@Override public UploadConfig setMaxSpeed(int maxSpeed) { |
|
|
@ -494,8 +427,8 @@ public class Configuration { |
|
|
|
public UploadConfig setMaxTaskNum(int maxTaskNum) { |
|
|
|
public UploadConfig setMaxTaskNum(int maxTaskNum) { |
|
|
|
oldMaxTaskNum = this.maxTaskNum; |
|
|
|
oldMaxTaskNum = this.maxTaskNum; |
|
|
|
this.maxTaskNum = maxTaskNum; |
|
|
|
this.maxTaskNum = maxTaskNum; |
|
|
|
saveKey("maxTaskNum", String.valueOf(maxTaskNum)); |
|
|
|
|
|
|
|
UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); |
|
|
|
UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); |
|
|
|
|
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -517,10 +450,8 @@ public class Configuration { |
|
|
|
* 应用配置 |
|
|
|
* 应用配置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static class AppConfig extends BaseConfig { |
|
|
|
public static class AppConfig extends BaseConfig { |
|
|
|
private static AppConfig INSTANCE = null; |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 是否使用{@link AriaCrashHandler}来捕获异常 |
|
|
|
* 是否使用{@link AriaCrashHandler}来捕获异常 {@code true} 使用;{@code false} 不使用 |
|
|
|
* {@code true} 使用;{@code false} 不使用 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean useAriaCrashHandler; |
|
|
|
boolean useAriaCrashHandler; |
|
|
|
|
|
|
|
|
|
|
@ -531,23 +462,13 @@ public class Configuration { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int logLevel; |
|
|
|
int logLevel; |
|
|
|
|
|
|
|
|
|
|
|
AppConfig() { |
|
|
|
private AppConfig() { |
|
|
|
loadConfig(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static AppConfig getInstance() { |
|
|
|
|
|
|
|
if (INSTANCE == null) { |
|
|
|
|
|
|
|
synchronized (AppConfig.class) { |
|
|
|
|
|
|
|
INSTANCE = new AppConfig(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return INSTANCE; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public AppConfig setLogLevel(int level) { |
|
|
|
public AppConfig setLogLevel(int level) { |
|
|
|
this.logLevel = level; |
|
|
|
this.logLevel = level; |
|
|
|
ALog.LOG_LEVEL = level; |
|
|
|
ALog.LOG_LEVEL = level; |
|
|
|
saveKey("logLevel", String.valueOf(logLevel)); |
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -561,12 +482,12 @@ public class Configuration { |
|
|
|
|
|
|
|
|
|
|
|
public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) { |
|
|
|
public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) { |
|
|
|
this.useAriaCrashHandler = useAriaCrashHandler; |
|
|
|
this.useAriaCrashHandler = useAriaCrashHandler; |
|
|
|
saveKey("useAriaCrashHandler", String.valueOf(useAriaCrashHandler)); |
|
|
|
|
|
|
|
if (useAriaCrashHandler) { |
|
|
|
if (useAriaCrashHandler) { |
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler()); |
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Thread.setDefaultUncaughtExceptionHandler(null); |
|
|
|
Thread.setDefaultUncaughtExceptionHandler(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
save(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|