From ae3d24f471dd37aded9c90056461e0d3585a8026 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Wed, 19 Jun 2019 22:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=A0=E9=99=A4=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E4=BC=98=E5=8C=96=E7=BD=91=E7=BB=9C=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=8A=B6=E6=80=81=E8=8E=B7=E5=8F=96=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=9F=90=E4=BA=9B=E9=85=8D=E7=BD=AE=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 58 +++++++- .../arialyy/aria/core/common/AbsFileer.java | 26 +++- .../aria/core/common/AbsThreadTask.java | 73 +++++---- .../aria/core/common/BaseListener.java | 6 +- .../aria/core/common/RecordHandler.java | 81 ++++++---- .../arialyy/aria/core/common/TaskRecord.java | 5 + .../aria/core/common/ThreadRecord.java | 6 +- .../aria/core/common/ftp/FtpDelegate.java | 140 +++++++++--------- .../aria/core/config/DownloadConfig.java | 17 ++- .../arialyy/aria/core/config/XMLReader.java | 52 +++---- .../aria/core/download/BaseDListener.java | 2 + .../aria/core/download/DownloadTask.java | 8 +- .../core/download/FtpDirDownloadTarget.java | 4 - .../aria/core/download/FtpDownloadTarget.java | 5 - .../downloader/FtpFileInfoThread.java | 4 +- .../core/download/m3u8/BaseM3U8Loader.java | 1 + .../core/download/m3u8/ITsMergeHandler.java | 2 +- .../aria/core/download/m3u8/M3U8KeyInfo.java | 37 ++++- ...iveDownloadUtil.java => M3U8LiveUtil.java} | 4 +- .../core/download/m3u8/M3U8VodLoader.java | 18 +-- ...8VodDownloadUtil.java => M3U8VodUtil.java} | 4 +- .../com/arialyy/aria/core/inf/AbsTask.java | 2 +- .../com/arialyy/aria/core/inf/IFtpTarget.java | 114 +++++++------- .../aria/core/upload/FtpUploadTarget.java | 4 - .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 34 ++++- .../java/com/arialyy/aria/util/NetUtils.java | 8 +- .../com/arialyy/aria/util/RecordUtil.java | 7 +- DEV_LOG.md | 3 + app/build.gradle | 4 +- app/src/main/assets/aria_config.xml | 4 +- .../core/download/HttpDownloadModule.java | 3 +- .../core/download/SingleTaskActivity.java | 5 + .../m3u8/M3U8VodDownloadActivity.java | 9 ++ .../arialyy/aria/core/upload/UploadTask.java | 2 +- build.gradle | 2 +- 36 files changed, 461 insertions(+), 295 deletions(-) rename Aria/src/main/java/com/arialyy/aria/core/download/m3u8/{M3U8LiveDownloadUtil.java => M3U8LiveUtil.java} (97%) rename Aria/src/main/java/com/arialyy/aria/core/download/m3u8/{M3U8VodDownloadUtil.java => M3U8VodUtil.java} (96%) 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 8cc3c948..02c4e7cf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -21,13 +21,20 @@ import android.app.Activity; import android.app.Application; import android.app.Dialog; import android.content.Context; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkInfo; +import android.net.NetworkRequest; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.support.annotation.RequiresApi; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.widget.PopupWindow; +import com.arialyy.aria.BuildConfig; import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.common.RecordHandler; @@ -71,6 +78,10 @@ import org.xml.sax.SAXException; public static final Object LOCK = new Object(); public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/"; public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/"; + /** + * 是否已经联网,true 已经联网 + */ + private static boolean isConnectedNet = true; @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null; private Map mReceivers = new ConcurrentHashMap<>(); @@ -85,7 +96,6 @@ import org.xml.sax.SAXException; private AppConfig mAConfig; private DGroupConfig mDGConfig; private Handler mAriaHandler; - private File[] files; private AriaManager(Context context) { APP = context.getApplicationContext(); @@ -94,6 +104,7 @@ import org.xml.sax.SAXException; initConfig(); initAria(); amendTaskState(); + regNetCallBack(context); } public static AriaManager getInstance(Context context) { @@ -109,6 +120,47 @@ import org.xml.sax.SAXException; return INSTANCE; } + /** + * 注册网络监听,只有配置了检查网络{@link AppConfig#isNetCheck()}才会注册事件 + */ + private void regNetCallBack(Context context) { + if (!getAppConfig().isNetCheck()) { + return; + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return; + } + ConnectivityManager cm = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm == null) { + return; + } + + NetworkRequest.Builder builder = new NetworkRequest.Builder(); + NetworkRequest request = builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) + .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) + .build(); + + cm.registerNetworkCallback(request, new ConnectivityManager.NetworkCallback() { + + @Override public void onLost(Network network) { + super.onLost(network); + isConnectedNet = false; + ALog.d(TAG, "onLost"); + } + + @Override public void onAvailable(Network network) { + super.onAvailable(network); + ALog.d(TAG, "onAvailable"); + isConnectedNet = true; + } + }); + } + + /** + * 初始化数据库 + */ private void initDb(Context context) { // 这个地方错误了,获取数据库路径见:https://www.jianshu.com/p/815c9efc5449 String oldDbName = "AriaLyyDb"; @@ -153,6 +205,10 @@ import org.xml.sax.SAXException; return mAriaHandler; } + public boolean isConnectedNet() { + return isConnectedNet; + } + public Map getReceiver() { return mReceivers; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 5fc8eaf8..6abfb470 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -193,7 +193,7 @@ public abstract class AbsFileer getEntity().getFileSize() && !getTaskWrapper().asHttp() - // .isChunked()) { - // String errorMsg = - // String.format("下载失败,下载长度超出文件真实长度;currentLocation=%s, fileSize=%s", - // getState().CURRENT_LOCATION, - // getEntity().getFileSize()); - // taskBreak = true; - // fail(mChildCurrentLocation, new FileException(TAG, errorMsg), false); - // return; - //} - mChildCurrentLocation += len; - if (!mStateHandler.getLooper().getThread().isAlive()) { - return; - } - mStateHandler.obtainMessage(IThreadState.STATE_RUNNING, len).sendToTarget(); - if (System.currentTimeMillis() - mLastSaveTime > 5000 - && mChildCurrentLocation < mRecord.endLocation) { - mLastSaveTime = System.currentTimeMillis(); - if (!mConfigThreadPool.isShutdown()) { - mConfigThreadPool.execute(mConfigThread); - } + //if (getState().CURRENT_LOCATION > getEntity().getFileSize() && !getTaskWrapper().asHttp() + // .isChunked()) { + // String errorMsg = + // String.format("下载失败,下载长度超出文件真实长度;currentLocation=%s, fileSize=%s", + // getState().CURRENT_LOCATION, + // getEntity().getFileSize()); + // taskBreak = true; + // fail(mChildCurrentLocation, new FileException(TAG, errorMsg), false); + // return; + //} + mChildCurrentLocation += len; + if (!mStateHandler.getLooper().getThread().isAlive()) { + return; + } + mStateHandler.obtainMessage(IThreadState.STATE_RUNNING, len).sendToTarget(); + if (System.currentTimeMillis() - mLastSaveTime > 5000 + && mChildCurrentLocation < mRecord.endLocation) { + mLastSaveTime = System.currentTimeMillis(); + if (!mConfigThreadPool.isShutdown()) { + mConfigThreadPool.execute(mConfigThread); } } } @@ -350,14 +346,15 @@ public abstract class AbsThreadTask 1) { + handleNoBlockMultiThreadRecord(); } else { handleSingleThreadRecord(); } @@ -105,7 +107,7 @@ public class RecordHandler { } } saveRecord(); - return mRecord; + return mTaskRecord; } /** @@ -119,7 +121,7 @@ public class RecordHandler { String cacheDir = wrapper.asM3U8().getCacheDir(); long currentProgress = 0; int completeNum = 0; - for (ThreadRecord record : mRecord.threadRecords) { + for (ThreadRecord record : mTaskRecord.threadRecords) { File temp = new File(BaseM3U8Loader.getTsFilePath(cacheDir, record.threadId)); if (!record.isComplete) { if (temp.exists()) { @@ -140,32 +142,45 @@ public class RecordHandler { } wrapper.asM3U8().setCompleteNum(completeNum); wrapper.getEntity().setCurrentProgress(currentProgress); + mTaskRecord.bandWidth = wrapper.asM3U8().getBandWidth(); } /** * 处理不支持断点的记录 */ private void handleNoSupportBPRecord() { - ThreadRecord tr = mRecord.threadRecords.get(0); + ThreadRecord tr = mTaskRecord.threadRecords.get(0); tr.startLocation = 0; tr.endLocation = mEntity.getFileSize(); - tr.key = mRecord.filePath; + tr.key = mTaskRecord.filePath; tr.blockLen = tr.endLocation; tr.isComplete = false; } + /** + * 处理为不分块的多线程任务 + */ + private void handleNoBlockMultiThreadRecord() { + File file = new File(mTaskRecord.filePath); + if (!file.exists()) { + ALog.w(TAG, String.format("文件【%s】不存在,重新分配线程区间", mTaskRecord.filePath)); + DbEntity.deleteData(ThreadRecord.class, "key=?", mTaskRecord.filePath); + initRecord(false); + } + } + /** * 处理单线程的任务的记录 */ private void handleSingleThreadRecord() { - File file = new File(mRecord.filePath); - ThreadRecord tr = mRecord.threadRecords.get(0); + File file = new File(mTaskRecord.filePath); + ThreadRecord tr = mTaskRecord.threadRecords.get(0); if (!file.exists()) { ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath())); tr.startLocation = 0; tr.isComplete = false; tr.endLocation = mEntity.getFileSize(); - } else if (mRecord.isOpenDynamicFile) { + } else if (mTaskRecord.isOpenDynamicFile) { if (file.length() > mEntity.getFileSize()) { ALog.i(TAG, String.format("文件【%s】错误,任务重新开始", file.getPath())); file.delete(); @@ -190,11 +205,11 @@ public class RecordHandler { */ private void handleBlockRecord() { // 默认线程分块长度 - long normalRectLen = mEntity.getFileSize() / mRecord.threadRecords.size(); - for (ThreadRecord tr : mRecord.threadRecords) { + long normalRectLen = mEntity.getFileSize() / mTaskRecord.threadRecords.size(); + for (ThreadRecord tr : mTaskRecord.threadRecords) { long threadRect = tr.blockLen; - File temp = new File(String.format(SUB_PATH, mRecord.filePath, tr.threadId)); + File temp = new File(String.format(SUB_PATH, mTaskRecord.filePath, tr.threadId)); if (!temp.exists()) { ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath())); tr.isComplete = false; @@ -269,13 +284,13 @@ public class RecordHandler { return; } mTaskWrapper.setNewTask(false); - mRecord = createTaskRecord(threadNum); - mRecord.isOpenDynamicFile = false; - mRecord.isBlock = false; + mTaskRecord = createTaskRecord(threadNum); + mTaskRecord.isOpenDynamicFile = false; + mTaskRecord.isBlock = false; File tempFile = new File(getFilePath()); for (int i = 0; i < threadNum; i++) { ThreadRecord tRecord = new ThreadRecord(); - tRecord.key = mRecord.filePath; + tRecord.key = mTaskRecord.filePath; Object state = pro.getProperty(tempFile.getName() + STATE + i); Object record = pro.getProperty(tempFile.getName() + RECORD + i); if (state != null && Integer.parseInt(String.valueOf(state)) == 1) { @@ -288,7 +303,7 @@ public class RecordHandler { } else { tRecord.startLocation = 0; } - mRecord.threadRecords.add(tRecord); + mTaskRecord.threadRecords.add(tRecord); } mConfigFile.delete(); } @@ -301,20 +316,20 @@ public class RecordHandler { */ private void initRecord(boolean newRecord) { if (newRecord) { - mRecord = createTaskRecord(getNewTaskThreadNum()); + mTaskRecord = createTaskRecord(getNewTaskThreadNum()); } mTaskWrapper.setNewTask(true); int requestType = mTaskWrapper.getRequestType(); if (requestType == ITaskWrapper.M3U8_LIVE) { return; } - long blockSize = mEntity.getFileSize() / mRecord.threadNum; + long blockSize = mEntity.getFileSize() / mTaskRecord.threadNum; // 处理线程区间记录 - for (int i = 0; i < mRecord.threadNum; i++) { + for (int i = 0; i < mTaskRecord.threadNum; i++) { long startL = i * blockSize, endL = (i + 1) * blockSize; ThreadRecord tr; tr = new ThreadRecord(); - tr.key = mRecord.filePath; + tr.key = mTaskRecord.filePath; tr.threadId = i; tr.startLocation = startL; tr.isComplete = false; @@ -325,13 +340,13 @@ public class RecordHandler { } else { tr.threadType = TaskRecord.TYPE_HTTP_FTP; //最后一个线程的结束位置即为文件的总长度 - if (i == (mRecord.threadNum - 1)) { + if (i == (mTaskRecord.threadNum - 1)) { endL = mEntity.getFileSize(); } tr.endLocation = endL; - tr.blockLen = RecordUtil.getBlockLen(mEntity.getFileSize(), i, mRecord.threadNum); + tr.blockLen = RecordUtil.getBlockLen(mEntity.getFileSize(), i, mTaskRecord.threadNum); } - mRecord.threadRecords.add(tr); + mTaskRecord.threadRecords.add(tr); } } @@ -350,9 +365,11 @@ public class RecordHandler { if (requestType == ITaskWrapper.M3U8_VOD) { record.taskType = TaskRecord.TYPE_M3U8_VOD; record.isOpenDynamicFile = true; + record.bandWidth = ((DTaskWrapper)mTaskWrapper).asM3U8().getBandWidth(); } else if (requestType == ITaskWrapper.M3U8_LIVE) { record.taskType = TaskRecord.TYPE_M3U8_LIVE; record.isOpenDynamicFile = true; + record.bandWidth = ((DTaskWrapper)mTaskWrapper).asM3U8().getBandWidth(); } else { if (getRecordType() == TYPE_DOWNLOAD) { record.isBlock = threadNum > 1 && Configuration.getInstance().downloadCfg.isUseBlock(); @@ -377,12 +394,12 @@ public class RecordHandler { * 保存任务记录 */ private void saveRecord() { - mRecord.threadNum = mRecord.threadRecords.size(); - mRecord.save(); - if (mRecord.threadRecords != null && !mRecord.threadRecords.isEmpty()) { - DbEntity.saveAll(mRecord.threadRecords); + mTaskRecord.threadNum = mTaskRecord.threadRecords.size(); + mTaskRecord.save(); + if (mTaskRecord.threadRecords != null && !mTaskRecord.threadRecords.isEmpty()) { + DbEntity.saveAll(mTaskRecord.threadRecords); } - ALog.d(TAG, String.format("保存记录,线程记录数:%s", mRecord.threadRecords.size())); + ALog.d(TAG, String.format("保存记录,线程记录数:%s", mTaskRecord.threadRecords.size())); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java b/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java index 182a97b2..90a03463 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java @@ -89,4 +89,9 @@ public class TaskRecord extends DbEntity { * {@link #TYPE_HTTP_FTP}、{@link #TYPE_M3U8_VOD} */ public int taskType = 0; + + /** + * m3u8文件码率 + */ + public long bandWidth = 0; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java b/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java index 41186d45..7e408b00 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java @@ -15,9 +15,7 @@ */ package com.arialyy.aria.core.common; -import com.arialyy.aria.orm.ActionPolicy; import com.arialyy.aria.orm.DbEntity; -import com.arialyy.aria.orm.annotation.Foreign; /** * Created by laoyuyu on 2018/5/8. @@ -25,7 +23,9 @@ import com.arialyy.aria.orm.annotation.Foreign; */ public class ThreadRecord extends DbEntity { - @Foreign(parent = TaskRecord.class, column = "filePath", onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE) + /** + * 任务的文件路径,不是当前线程记录的的分块文件路径 + */ public String key; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java index 70759200..d8c954e8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java @@ -1,70 +1,70 @@ -/* - * 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.common.ftp; - -import android.text.TextUtils; -import com.arialyy.aria.core.FtpUrlEntity; -import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.IFtpTarget; -import com.arialyy.aria.util.ALog; -import java.net.Proxy; - -/** - * Created by laoyuyu on 2018/3/9. - * ftp 委托 - */ -public class FtpDelegate implements IFtpTarget { - private static final String TAG = "FtpDelegate"; - private TARGET mTarget; - - public FtpDelegate(TARGET target) { - mTarget = target; - } - - @Override public TARGET charSet(String charSet) { - if (TextUtils.isEmpty(charSet)) { - throw new NullPointerException("字符编码为空"); - } - mTarget.getTaskWrapper().asFtp().setCharSet(charSet); - return mTarget; - } - - @Override public TARGET login(String userName, String password) { - return login(userName, password, null); - } - - @Override public TARGET login(String userName, String password, String account) { - if (TextUtils.isEmpty(userName)) { - ALog.e(TAG, "用户名不能为null"); - return mTarget; - } else if (TextUtils.isEmpty(password)) { - ALog.e(TAG, "密码不能为null"); - return mTarget; - } - // urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的 - FtpUrlEntity urlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); - urlEntity.needLogin = true; - urlEntity.user = userName; - urlEntity.password = password; - urlEntity.account = account; - return mTarget; - } - - @Override public TARGET setProxy(Proxy proxy) { - mTarget.getTaskWrapper().asFtp().setProxy(proxy); - return mTarget; - } -} +/* + * 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.common.ftp; + +import android.text.TextUtils; +import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.IFtpTarget; +import com.arialyy.aria.util.ALog; +import java.net.Proxy; + +/** + * Created by laoyuyu on 2018/3/9. + * ftp 委托 + */ +public class FtpDelegate implements IFtpTarget { + private static final String TAG = "FtpDelegate"; + private TARGET mTarget; + + public FtpDelegate(TARGET target) { + mTarget = target; + } + + @Override public TARGET charSet(String charSet) { + if (TextUtils.isEmpty(charSet)) { + throw new NullPointerException("字符编码为空"); + } + mTarget.getTaskWrapper().asFtp().setCharSet(charSet); + return mTarget; + } + + @Override public TARGET login(String userName, String password) { + return login(userName, password, null); + } + + @Override public TARGET login(String userName, String password, String account) { + if (TextUtils.isEmpty(userName)) { + ALog.e(TAG, "用户名不能为null"); + return mTarget; + } else if (TextUtils.isEmpty(password)) { + ALog.e(TAG, "密码不能为null"); + return mTarget; + } + // urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的 + FtpUrlEntity urlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); + urlEntity.needLogin = true; + urlEntity.user = userName; + urlEntity.password = password; + urlEntity.account = account; + return mTarget; + } + + //@Override public TARGET setProxy(Proxy proxy) { + // mTarget.getTaskWrapper().asFtp().setProxy(proxy); + // return mTarget; + //} +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java b/Aria/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java index d15f91c4..69ff2b69 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java @@ -23,16 +23,23 @@ import java.io.Serializable; */ public class DownloadConfig extends BaseTaskConfig implements Serializable { /** - * 下载线程数,下载线程数不能小于1 注意: 1、线程下载数改变后,新的下载任务才会生效; 2、如果任务大小小于1m,该设置不会生效; - * 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; + * 下载线程数,下载线程数不能小于1 + * 注意: + * 1、线程下载数改变后,新的下载任务才会生效; + * 2、如果任务大小小于1m,该设置不会生效; + * 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; + * 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; */ int threadNum = 3; /** - * 多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 注意: 1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; - * 2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 + * 多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 + * 注意: + * 1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; + * 2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; + * 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 */ - boolean useBlock = false; + boolean useBlock = true; public boolean isUseBlock() { return useBlock; diff --git a/Aria/src/main/java/com/arialyy/aria/core/config/XMLReader.java b/Aria/src/main/java/com/arialyy/aria/core/config/XMLReader.java index 9e21d3fd..d3472130 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/config/XMLReader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/config/XMLReader.java @@ -76,21 +76,21 @@ public class XMLReader extends DefaultHandler { ALog.w(TAG, "任务队列数不能小于 1"); maxTaskNum = 2; } - setField("maxTaskNum", maxTaskNum, getAllTaskType()); + setField("maxTaskNum", maxTaskNum, mType); break; case "reTryNum": //任务重试次数 - setField("reTryNum", checkInt(value) ? Integer.parseInt(value) : 0, getAllTaskType()); + setField("reTryNum", checkInt(value) ? Integer.parseInt(value) : 0, mType); break; case "connectTimeOut": // 连接超时时间 setField("connectTimeOut", checkInt(value) ? Integer.parseInt(value) : 5 * 1000, - getAllTaskType()); + mType); break; case "iOTimeOut": //io流超时时间 int iOTimeOut = checkInt(value) ? Integer.parseInt(value) : 10 * 1000; if (iOTimeOut < 10 * 1000) { iOTimeOut = 10 * 1000; } - setField("iOTimeOut", iOTimeOut, getAllTaskType()); + setField("iOTimeOut", iOTimeOut, mType); break; case "reTryInterval": //失败重试间隔 int reTryInterval = checkInt(value) ? Integer.parseInt(value) : 2 * 1000; @@ -98,7 +98,7 @@ public class XMLReader extends DefaultHandler { if (reTryInterval < 2 * 1000) { reTryInterval = 2 * 1000; } - setField("reTryInterval", reTryInterval, getAllTaskType()); + setField("reTryInterval", reTryInterval, mType); break; case "buffSize": //缓冲大小 int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192; @@ -107,21 +107,21 @@ public class XMLReader extends DefaultHandler { buffSize = 2048; } - setField("buffSize", buffSize, getAllTaskType()); + setField("buffSize", buffSize, mType); break; case "ca": // ca证书 String caName = attributes.getValue("name"); String caPath = attributes.getValue("path"); - setField("caName", caName, getAllTaskType()); - setField("caPath", caPath, getAllTaskType()); + setField("caName", caName, mType); + setField("caPath", caPath, mType); break; case "convertSpeed": // 是否转换速度 setField("isConvertSpeed", !checkBoolean(value) || Boolean.parseBoolean(value), - getAllTaskType()); + mType); break; case "maxSpeed": // 最大速度 int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0; - setField("maxSpeed", maxSpeed, getAllTaskType()); + setField("maxSpeed", maxSpeed, mType); break; case "queueMod": // 队列类型 String mod = "now"; @@ -129,11 +129,11 @@ public class XMLReader extends DefaultHandler { "wait"))) { mod = value; } - setField("queueMod", mod, getAllTaskType()); + setField("queueMod", mod, mType); break; case "updateInterval": // 进度更新时间 setField("updateInterval", checkLong(value) ? Long.parseLong(value) : 1000, - getAllTaskType()); + mType); break; case "useBlock": // 是否使用分块任务 @@ -184,25 +184,15 @@ public class XMLReader extends DefaultHandler { } } - /** - * 获取任务类型集合,类型有 {@link ConfigType#DOWNLOAD}、{@link ConfigType#UPLOAD}、{@link ConfigType#D_GROUP} - */ - private int[] getAllTaskType() { - return new int[] {ConfigType.DOWNLOAD, ConfigType.UPLOAD, - ConfigType.D_GROUP}; - } - - private void setField(String key, Object value, int... types) { - for (int type : types) { - if (type == ConfigType.DOWNLOAD) { - setField(DownloadConfig.class, mDownloadConfig, key, value); - } else if (type == ConfigType.UPLOAD) { - setField(UploadConfig.class, mUploadConfig, key, value); - } else if (type == ConfigType.APP) { - setField(AppConfig.class, mAppConfig, key, value); - } else if (type == ConfigType.D_GROUP) { - setField(DGroupConfig.class, mDGroupConfig, key, value); - } + private void setField(String key, Object value, int type) { + if (type == ConfigType.DOWNLOAD) { + setField(DownloadConfig.class, mDownloadConfig, key, value); + } else if (type == ConfigType.UPLOAD) { + setField(UploadConfig.class, mUploadConfig, key, value); + } else if (type == ConfigType.APP) { + setField(AppConfig.class, mAppConfig, key, value); + } else if (type == ConfigType.D_GROUP) { + setField(DGroupConfig.class, mDGroupConfig, key, value); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java index 6634bf9b..fa1ee9a8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java @@ -19,12 +19,14 @@ import android.os.Handler; import com.arialyy.aria.core.common.BaseListener; import com.arialyy.aria.core.common.RecordHandler; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.RecordUtil; +import java.io.File; /** * 下载监听类 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 0dbb7924..47fe8d1e 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 @@ -21,8 +21,8 @@ import android.os.Looper; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; -import com.arialyy.aria.core.download.m3u8.M3U8LiveDownloadUtil; -import com.arialyy.aria.core.download.m3u8.M3U8VodDownloadUtil; +import com.arialyy.aria.core.download.m3u8.M3U8LiveUtil; +import com.arialyy.aria.core.download.m3u8.M3U8VodUtil; import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.ITaskWrapper; @@ -90,9 +90,9 @@ public class DownloadTask extends AbsNormalTask { @Override protected synchronized IUtil createUtil() { if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) { - return new M3U8VodDownloadUtil(mTaskWrapper, (IDownloadListener) mListener); + return new M3U8VodUtil(mTaskWrapper, (IDownloadListener) mListener); } else if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) { - return new M3U8LiveDownloadUtil(mTaskWrapper, (IDownloadListener) mListener); + return new M3U8LiveUtil(mTaskWrapper, (IDownloadListener) mListener); } else { return new SimpleDownloadUtil(mTaskWrapper, (IDownloadListener) mListener); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java index 71899fde..e07b8629 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java @@ -107,8 +107,4 @@ public class FtpDirDownloadTarget extends AbsDGTarget @Override public FtpDirDownloadTarget login(String userName, String password, String account) { return mFtpDelegate.login(userName, password, account); } - - @Override public FtpDirDownloadTarget setProxy(Proxy proxy) { - return mFtpDelegate.setProxy(proxy); - } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java index f94644df..9e519f9e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java @@ -144,11 +144,6 @@ public class FtpDownloadTarget extends AbsDTarget return mFtpDelegate.login(userName, password, account); } - @CheckResult - @Override public FtpDownloadTarget setProxy(Proxy proxy) { - return mFtpDelegate.setProxy(proxy); - } - @Override public FtpDownloadTarget updateUrl(String newUrl) { return mConfigHandler.updateUrl(newUrl); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java index b0cc47bc..8e825ff2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java @@ -37,9 +37,9 @@ class FtpFileInfoThread extends AbsFtpInfoThread { @Override protected void handleFile(String remotePath, FTPFile ftpFile) { super.handleFile(remotePath, ftpFile); - if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), ftpFile.getSize())) { + if (!CommonUtil.checkSDMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) { mCallback.onFail(mEntity, new AriaIOException(TAG, - String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getDownloadPath())), + String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getFilePath())), false); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java index f6099b67..476f91af 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/BaseM3U8Loader.java @@ -26,6 +26,7 @@ public abstract class BaseM3U8Loader extends AbsFileer CREATOR = + new Parcelable.Creator() { + @Override public M3U8KeyInfo createFromParcel(Parcel source) { + return new M3U8KeyInfo(source); + } + + @Override public M3U8KeyInfo[] newArray(int size) { + return new M3U8KeyInfo[size]; + } + }; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDownloadUtil.java rename to Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java index ed343edc..49a1f1b0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java @@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit; * 4、对于直播来说是没有停止的,停止就代表完成 * 5、不处理直播切片下载失败的状态 */ -public class M3U8LiveDownloadUtil implements IUtil { +public class M3U8LiveUtil implements IUtil { private final String TAG = "M3U8LiveDownloadUtil"; private DTaskWrapper mWrapper; private IDownloadListener mListener; @@ -52,7 +52,7 @@ public class M3U8LiveDownloadUtil implements IUtil { private ExecutorService mInfoPool = Executors.newCachedThreadPool(); private List mPeerUrls = new ArrayList<>(); - public M3U8LiveDownloadUtil(DTaskWrapper wrapper, IDownloadListener listener) { + public M3U8LiveUtil(DTaskWrapper wrapper, IDownloadListener listener) { mWrapper = wrapper; mListener = listener; mLoader = new M3U8LiveLoader(mListener, mWrapper); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java index bd79bb8a..e0b882ed 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java @@ -104,16 +104,6 @@ public class M3U8VodLoader extends BaseM3U8Loader { } - @Override protected void onStop() { - super.onStop(); - //notifyLock(); - } - - @Override protected void onCancel() { - super.onCancel(); - //notifyLock(); - } - private void notifyLock() { try { LOCK.lock(); @@ -204,7 +194,7 @@ public class M3U8VodLoader extends BaseM3U8Loader { ThreadTaskManager.getInstance().removeSingleTaskThread(mTaskWrapper.getKey(), (AbsThreadTask) msg.obj); if (isStop()) { - ALog.d(TAG, "任务停止"); + ALog.d(TAG, String.format("vod任务【%s】停止", mTempFile.getName())); mListener.onStop(mProgress); quitLooper(); } @@ -214,7 +204,7 @@ public class M3U8VodLoader extends BaseM3U8Loader { ThreadTaskManager.getInstance().removeSingleTaskThread(mTaskWrapper.getKey(), (AbsThreadTask) msg.obj); if (isCancel()) { - ALog.d(TAG, "任务取消"); + ALog.d(TAG, String.format("vod任务【%s】取消", mTempFile.getName())); mListener.onCancel(); quitLooper(); } @@ -222,6 +212,7 @@ public class M3U8VodLoader extends BaseM3U8Loader { case STATE_FAIL: mFailNum++; if (isFail()) { + ALog.d(TAG, String.format("vod任务【%s】失败", mTempFile.getName())); Bundle b = msg.getData(); mListener.onFail(b.getBoolean(KEY_RETRY, true), (BaseException) b.getSerializable(KEY_ERROR_INFO)); @@ -235,7 +226,6 @@ public class M3U8VodLoader extends BaseM3U8Loader { handlerPercent(); notifyLock(); if (isComplete()) { - ALog.d(TAG, "isComplete, completeNum = " + mCompleteNum); if (mTaskWrapper.asM3U8().isMergeFile()) { if (mergeFile()) { mListener.onComplete(); @@ -274,7 +264,7 @@ public class M3U8VodLoader extends BaseM3U8Loader { @Override public boolean isFail() { printInfo("isFail"); - return mStartThreadNum == mStopNum + mFailNum + mCompleteNum + mCancelNum; + return mFailNum == mFlagQueue.size(); } @Override public boolean isComplete() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDownloadUtil.java rename to Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java index 5b87c1d4..3eb8b498 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java @@ -36,7 +36,7 @@ import java.util.List; * 3、完成所有分片下载后,合并ts文件 * 4、删除该隐藏文件夹 */ -public class M3U8VodDownloadUtil implements IUtil { +public class M3U8VodUtil implements IUtil { private final String TAG = "M3U8DownloadUtil"; private DTaskWrapper mWrapper; @@ -45,7 +45,7 @@ public class M3U8VodDownloadUtil implements IUtil { private List mUrls = new ArrayList<>(); private M3U8VodLoader mLoader; - public M3U8VodDownloadUtil(DTaskWrapper wrapper, IDownloadListener listener) { + public M3U8VodUtil(DTaskWrapper wrapper, IDownloadListener listener) { mWrapper = wrapper; mListener = listener; mLoader = new M3U8VodLoader(mListener, mWrapper); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index f8d7370a..71305430 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -78,7 +78,7 @@ public abstract class AbsTask ALog.e(TAG, "key 为空"); return; } else if (obj == null) { - ALog.e(TAG, "扩展数据为空"); + ALog.w(TAG, "扩展数据为空"); return; } mExpand.put(key, obj); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IFtpTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IFtpTarget.java index c1b5faf6..62833cec 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/IFtpTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IFtpTarget.java @@ -1,57 +1,57 @@ -/* - * 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.inf; - -import android.support.annotation.CheckResult; -import java.net.Proxy; - -/** - * Created by laoyuyu on 2018/3/9. - */ -public interface IFtpTarget { - /** - * 设置字符编码 - */ - @CheckResult - TARGET charSet(String charSet); - - /** - * ftp 用户登录信。 - * - * @param userName ftp用户名 - * @param password ftp用户密码 - */ - @CheckResult - TARGET login(String userName, String password); - - /** - * ftp 用户登录信息 - * - * @param userName ftp用户名 - * @param password ftp用户密码 - * @param account ftp账号 - */ - @CheckResult - TARGET login(String userName, String password, String account); - - /** - * 设置代理 - * - * @param proxy {@link Proxy} - */ - @CheckResult - TARGET setProxy(Proxy proxy); -} +/* + * 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.inf; + +import android.support.annotation.CheckResult; +import java.net.Proxy; + +/** + * Created by laoyuyu on 2018/3/9. + */ +public interface IFtpTarget { + /** + * 设置字符编码 + */ + @CheckResult + TARGET charSet(String charSet); + + /** + * ftp 用户登录信。 + * + * @param userName ftp用户名 + * @param password ftp用户密码 + */ + @CheckResult + TARGET login(String userName, String password); + + /** + * ftp 用户登录信息 + * + * @param userName ftp用户名 + * @param password ftp用户密码 + * @param account ftp账号 + */ + @CheckResult + TARGET login(String userName, String password, String account); + + ///** + // * 设置代理 + // * + // * @param proxy {@link Proxy} + // */ + //@CheckResult + //TARGET setProxy(Proxy proxy); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java index 40468674..7d3b02f3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java @@ -92,10 +92,6 @@ public class FtpUploadTarget extends AbsUploadTarget return mFtpDelegate.login(userName, password, account); } - @Override public FtpUploadTarget setProxy(Proxy proxy) { - return mFtpDelegate.setProxy(proxy); - } - @Override protected boolean checkEntity() { return mConfigHandler.checkEntity(); } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index 09385de4..eead24ba 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -57,7 +57,7 @@ class DBConfig { mapping.put("DownloadGroupEntity", DownloadGroupEntity.class); mapping.put("DownloadEntity", DownloadEntity.class); mapping.put("UploadEntity", UploadEntity.class); - mapping.put("TaskRecord", TaskRecord.class); mapping.put("ThreadRecord", ThreadRecord.class); + mapping.put("TaskRecord", TaskRecord.class); } } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index dc67dd72..e8358158 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -98,8 +98,8 @@ final class SqlHelper extends SQLiteOpenHelper { handle314AriaUpdate(db); } else if (oldVersion < 45) { handle360AriaUpdate(db); - } else if (oldVersion < 46) { - db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1"); + } else if (oldVersion < 48) { + handle365Update(db); } else { handleDbUpdate(db, null, null); } @@ -227,12 +227,37 @@ final class SqlHelper extends SQLiteOpenHelper { } db.setTransactionSuccessful(); } catch (Exception e) { - ALog.e(TAG, e); + e.printStackTrace(); } finally { db.endTransaction(); } } + /** + * 删除重复的repeat数据 + */ + private void delRepeatThreadRecord(SQLiteDatabase db) { + String repeatSql = + "DELETE FROM ThreadRecord WHERE (key, threadId, endLocation) " + + "IN (SELECT key, threadId, endLocation FROM ThreadRecord GROUP BY key, threadId, endLocation " + + "HAVING COUNT(*) > 1) AND rowid " + + "NOT IN (SELECT MIN(rowid) FROM ThreadRecord GROUP BY key, threadId, endLocation " + + "HAVING COUNT(*)> 1)"; + ALog.d(TAG, repeatSql); + db.execSQL(repeatSql); + } + + /** + * 处理365版本以下的升级 + */ + private void handle365Update(SQLiteDatabase db) { + db.execSQL("UPDATE ThreadRecord SET threadId=0 WHERE threadId=-1"); + + // 执行升级操作 + handleDbUpdate(db, null, null); + delRepeatThreadRecord(db); + } + /** * 处理3.6以下版本的数据库升级 */ @@ -255,7 +280,10 @@ final class SqlHelper extends SQLiteOpenHelper { Map dGroupNameModify = new HashMap<>(); dGroupNameModify.put("dGroupName", "dGroupHash"); columnMap.put("TaskRecord", dGroupNameModify); + + // 执行升级操作 handleDbUpdate(db, columnMap, null); + delRepeatThreadRecord(db); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/util/NetUtils.java b/Aria/src/main/java/com/arialyy/aria/util/NetUtils.java index 44f63c52..fd864e13 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/NetUtils.java +++ b/Aria/src/main/java/com/arialyy/aria/util/NetUtils.java @@ -20,9 +20,11 @@ package com.arialyy.aria.util; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Build; import android.telephony.TelephonyManager; import android.text.TextUtils; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.AriaManager; /** * 跟网络相关的工具类 @@ -52,12 +54,16 @@ public class NetUtils { /** * 判断网络是否连接 + * * @return {@code true} 网络已连接、{@code false}网络未连接 */ public static boolean isConnected(Context context) { - if (!Aria.get(context).getAppConfig().isNetCheck()){ + if (!Aria.get(context).getAppConfig().isNetCheck()) { return true; } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + return AriaManager.getInstance(context).isConnectedNet(); + } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); diff --git a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java index 3f77a160..289414c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/RecordUtil.java @@ -182,6 +182,9 @@ public class RecordUtil { if (TextUtils.isEmpty(filePath)) { throw new NullPointerException("删除记录失败,文件路径为空"); } + if (!filePath.startsWith("/")) { + throw new IllegalArgumentException(String.format("文件路径错误,filePath:%s", filePath)); + } if (type != RecordHandler.TYPE_DOWNLOAD && type != RecordHandler.TYPE_UPLOAD) { throw new IllegalArgumentException("任务记录类型错误"); } @@ -210,7 +213,8 @@ public class RecordUtil { if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件 String cacheDir = null; if (!targetFile.isDirectory()) { - cacheDir = targetFile.getParent() + "/." + targetFile.getName(); + cacheDir = String.format("%s/.%s_%s", targetFile.getParent(), targetFile.getName(), + record.bandWidth); } removeTsCache(record, cacheDir); } else if (record.isBlock) { // 删除分块文件 @@ -235,6 +239,7 @@ public class RecordUtil { } private static void removeRecord(String filePath) { + ALog.i(TAG, "删除任务记录"); DbEntity.deleteData(ThreadRecord.class, "key=?", filePath); DbEntity.deleteData(TaskRecord.class, "filePath=?", filePath); } diff --git a/DEV_LOG.md b/DEV_LOG.md index a9cbc75b..56fd3b4e 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -8,6 +8,9 @@ - 修复拦截器可能出现的空指针问题 - 移除`DownloadGroupEntity`字段`groupHash`的主键约束,`DownloadEntity`字段`groupHash`的外键约束,`TaskRecord`字段`dGroupHash`的外键约束 - 优化关联查询的性能 + - 修复任务记录删除失败的问题 + - 优化网络连接状态获取的逻辑 + - 修复配置文件的某些配置失效的问题 + v_3.6.4 (2019/5/16) - 优化任务接收器的代码结构 - 修复`DbEntity.saveAll()`失败的问题 diff --git a/app/build.gradle b/app/build.gradle index 83893668..ee2ab92a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,8 +50,8 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}" api project(':Aria') kapt project(':AriaCompiler') -// api 'com.arialyy.aria:aria-core:3.6.5_dev_4' -// kapt 'com.arialyy.aria:aria-compiler:3.6.5_dev_4' +// api 'com.arialyy.aria:aria-core:3.6.4' +// kapt 'com.arialyy.aria:aria-compiler:3.6.4' // compile 'com.arialyy.aria:aria-core:3.3.14' // annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.14' diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index a9d5ccfb..0889a681 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -9,12 +9,12 @@ - + - + diff --git a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java index b32368e2..230807c9 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java @@ -34,9 +34,10 @@ public class HttpDownloadModule extends BaseViewModule { private final String defUrl = "http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk"; + //"http://202.98.201.103:7000/vrs/TPK/ZTC440402001Z.tpk"; private final String defFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() - + "/test.apk"; + + "/ZTC440402001Z.tpk"; private MutableLiveData liveData = new MutableLiveData<>(); private DownloadEntity singDownloadInfo; 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 012e5ae3..700c51a4 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 @@ -26,6 +26,7 @@ import android.support.annotation.Nullable; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.widget.Toast; @@ -310,6 +311,10 @@ public class SingleTaskActivity extends BaseActivity { //Aria.download(this).unRegister(); } + @Override public boolean dispatchTouchEvent(MotionEvent ev) { + return super.dispatchTouchEvent(ev); + } + @Override protected void dataCallback(int result, Object data) { super.dataCallback(result, data); if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDownloadActivity.java index 4731a50e..e26240cf 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDownloadActivity.java @@ -31,7 +31,9 @@ import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.m3u8.IBandWidthUrlConverter; +import com.arialyy.aria.core.download.m3u8.ITsMergeHandler; import com.arialyy.aria.core.download.m3u8.IVodTsUrlConverter; +import com.arialyy.aria.core.download.m3u8.M3U8KeyInfo; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -201,6 +203,8 @@ public class M3U8VodDownloadActivity extends BaseActivity tsPath) { + return false; + } + }) .start(); } 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 7f2bdf33..a96b6c88 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.upload.uploader.SimpleUploadUtil; /** * Created by lyy on 2017/2/23. 上传任务 */ -public class UploadTask extends AbsNormalTask { +public class UploadTask extends AbsNormalTask { private UploadTask(UTaskWrapper taskWrapper, Handler outHandler) { mTaskWrapper = taskWrapper; diff --git a/build.gradle b/build.gradle index fe7e1ccc..e9b72b95 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.5_dev_4' + publishVersion = '3.6.5_beta_1' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架'