From 685f6b55255d99a9caaafb0626fb383e3513cadc Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 26 Dec 2019 20:58:08 +0800 Subject: [PATCH] =?UTF-8?q?android=20P=E9=80=82=E9=85=8D=20https://github.?= =?UTF-8?q?com/AriaLyy/Aria/issues/581?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 2 +- .../common/controller/BuilderController.java | 2 +- DEV_LOG.md | 3 +- .../aria/ftp/download/FtpDFileInfoThread.java | 2 +- .../arialyy/aria/http/HttpFileInfoThread.java | 2 +- .../java/com/arialyy/aria/util/FileUtil.java | 133 ++++++++++-------- app/src/main/assets/aria_config.xml | 2 +- .../java/com/arialyy/simple/MainActivity.java | 1 - .../core/download/SingleTaskActivity.java | 5 +- .../core/download/group/GroupModule.java | 7 + build.gradle | 4 +- 11 files changed, 94 insertions(+), 69 deletions(-) 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 a562e53b..4b9dc368 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -115,7 +115,6 @@ import java.util.concurrent.ConcurrentHashMap; initDb(APP); regAppLifeCallback(APP); initAria(); - amendTaskState(); } public Context getAPP() { @@ -137,6 +136,7 @@ import java.util.concurrent.ConcurrentHashMap; } } mDbWrapper = DelegateWrapper.init(context.getApplicationContext()); + amendTaskState(); } private void initAria() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java index 70002c01..586b243d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java @@ -30,7 +30,7 @@ public final class BuilderController extends FeatureController implements IStart } /** - * 添加任务 + * 添加任务,只添加任务不进行下载 * * @return 正常添加,返回任务id,否则返回-1 */ diff --git a/DEV_LOG.md b/DEV_LOG.md index 6d6cae72..17a10a44 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,6 +1,7 @@ ## 开发日志 - + v_3.8.2 + + v_3.8.3 - fix bug https://github.com/AriaLyy/Aria/issues/573 + - android P适配 https://github.com/AriaLyy/Aria/issues/581 + v_3.8.1 (2019/12/22) - 修复一个表创建失败的问题 https://github.com/AriaLyy/Aria/issues/570 - 修复一个非分块模式下导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/571 diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDFileInfoThread.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDFileInfoThread.java index a9f35116..39f55101 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDFileInfoThread.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDFileInfoThread.java @@ -38,7 +38,7 @@ class FtpDFileInfoThread extends AbsFtpInfoThread @Override protected void handleFile(String remotePath, FTPFile ftpFile) { super.handleFile(remotePath, ftpFile); - if (!FileUtil.checkSDMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) { + if (!FileUtil.checkMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) { mCallback.onFail(mEntity, new AriaIOException(TAG, String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getFilePath())), false); diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java index e484c5cc..f910ae02 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java @@ -125,7 +125,7 @@ public class HttpFileInfoThread implements Runnable { } long len = lenAdapter.handleFileLen(conn.getHeaderFields()); - if (!FileUtil.checkSDMemorySpace(mEntity.getFilePath(), len)) { + if (!FileUtil.checkMemorySpace(mEntity.getFilePath(), len)) { failDownload(new TaskException(TAG, String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())), false); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java index f954c7f9..b5c8bd26 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -374,6 +374,76 @@ public class FileUtil { } } + /** + * 检查内存空间是否充足 + * + * @param path 文件路径 + * @param fileSize 下载的文件的大小 + * @return true 空间足够 + */ + public static boolean checkMemorySpace(String path, long fileSize) { + File temp = new File(path); + if (!temp.exists()){ + if (!temp.getParentFile().exists()){ + FileUtil.createDir(temp.getParentFile().getPath()); + } + path = temp.getParentFile().getPath(); + } + + StatFs stat = new StatFs(path); + long blockSize = stat.getBlockSize(); + long availableBlocks = stat.getAvailableBlocks(); + return fileSize <= availableBlocks * blockSize; + } + + /** + * 读取下载配置文件 + */ + public static Properties loadConfig(File file) { + Properties properties = new Properties(); + FileInputStream fis = null; + if (!file.exists()) { + createFile(file.getPath()); + } + try { + fis = new FileInputStream(file); + properties.load(fis); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return properties; + } + + /** + * 保存配置文件 + */ + public static void saveConfig(File file, Properties properties) { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(file, false); + properties.store(fos, null); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (fos != null) { + fos.flush(); + fos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + /** * 检查SD内存空间是否充足 * @@ -381,7 +451,8 @@ public class FileUtil { * @param fileSize 文件大小 * @return {@code false} 内存空间不足,{@code true}内存空间足够 */ - public static boolean checkSDMemorySpace(String filePath, long fileSize) { + @Deprecated + private static boolean checkSDMemorySpace(String filePath, long fileSize) { List dirs = FileUtil.getSDPathList(AriaConfig.getInstance().getAPP()); if (dirs == null || dirs.isEmpty()) { return true; @@ -402,7 +473,7 @@ public class FileUtil { * @param sdcardPath sdcard 根路径 * @return 单位为:byte */ - public static long getAvailableExternalMemorySize(String sdcardPath) { + private static long getAvailableExternalMemorySize(String sdcardPath) { StatFs stat = new StatFs(sdcardPath); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); @@ -415,7 +486,7 @@ public class FileUtil { * @param sdcardPath sdcard 根路径 * @return 单位为:byte */ - public static long getTotalExternalMemorySize(String sdcardPath) { + private static long getTotalExternalMemorySize(String sdcardPath) { StatFs stat = new StatFs(sdcardPath); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); @@ -425,13 +496,11 @@ public class FileUtil { /** * 获取SD卡目录列表 */ - public static List getSDPathList(Context context) { + private static List getSDPathList(Context context) { List paths = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { try { paths = getVolumeList(context); - } catch (ClassNotFoundException e) { - e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { @@ -447,59 +516,11 @@ public class FileUtil { return paths; } - /** - * 读取下载配置文件 - */ - public static Properties loadConfig(File file) { - Properties properties = new Properties(); - FileInputStream fis = null; - if (!file.exists()) { - createFile(file.getPath()); - } - try { - fis = new FileInputStream(file); - properties.load(fis); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return properties; - } - - /** - * 保存配置文件 - */ - public static void saveConfig(File file, Properties properties) { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file, false); - properties.store(fos, null); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (fos != null) { - fos.flush(); - fos.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - /** * getSDPathList */ private static List getVolumeList(final Context context) - throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { List pathList = new ArrayList<>(); @@ -589,7 +610,7 @@ public class FileUtil { * * @return paths to all available SD-Cards in the system (include emulated) */ - public static List getStorageDirectories() { + private static List getStorageDirectories() { // Final set of paths final List rv = new ArrayList<>(); // Primary physical SD-CARD (not emulated) diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index cb8d1c24..8ac9205c 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -44,7 +44,7 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/MainActivity.java b/app/src/main/java/com/arialyy/simple/MainActivity.java index cbf32eb2..8ac51204 100644 --- a/app/src/main/java/com/arialyy/simple/MainActivity.java +++ b/app/src/main/java/com/arialyy/simple/MainActivity.java @@ -29,7 +29,6 @@ import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.arialyy.aria.core.AriaManager; import com.arialyy.frame.permission.OnPermissionCallback; import com.arialyy.frame.permission.PermissionManager; import com.arialyy.frame.util.show.T; diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index c6b238f6..801b91f0 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -20,6 +20,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.os.StatFs; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -32,7 +33,6 @@ import androidx.lifecycle.ViewModelProviders; import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.common.HttpOption; -import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.listener.ISchedulers; @@ -40,16 +40,13 @@ import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; -import com.arialyy.aria.util.FileUtil; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.common.ModifyPathDialog; import com.arialyy.simple.common.ModifyUrlDialog; import com.arialyy.simple.databinding.ActivitySingleBinding; -import com.arialyy.simple.util.AppUtil; import java.io.File; -import java.io.IOException; import java.util.List; import java.util.Map; diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java b/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java index d35708f4..907e39ce 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java @@ -54,6 +54,13 @@ public class GroupModule extends BaseModule { return names; } + List getSubName1() { + List names = new ArrayList<>(); + String[] str = getContext().getResources().getStringArray(R.array.group_names); + Collections.addAll(names, str); + return names; + } + List getSubName2() { List taskSubFile; taskSubFile = new ArrayList<>(); diff --git a/build.gradle b/build.gradle index 63797bf6..84852cd5 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ task clean(type: Delete) { } ext { - versionCode = 381 - versionName = '3.8.1' + versionCode = 383 + versionName = '3.8.3_beta' userOrg = 'arialyy' groupId = 'com.arialyy.aria' publishVersion = versionName