[合并] 将分支2.15.0_merge_master的最新代码合并过来
This commit is contained in:
@@ -5,11 +5,8 @@ apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion "30.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 31
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@ import androidx.viewpager.widget.PagerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.IDownload
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.utils.DownloadUtils
|
||||
import com.mogo.eagle.core.utilcode.download.*
|
||||
import com.mogo.eagle.core.utilcode.download.callback.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
@@ -154,8 +153,7 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
Logger.d(ImageVideoRotationView.TAG, "startDownLoadVideo")
|
||||
FileUtils.createFileDir(mVideoDirPath)
|
||||
DownloadUtils.downLoad(
|
||||
context, fileNetPath, mVideoDirPath, downloadVideoName, 5, downListener
|
||||
)
|
||||
context, fileNetPath!!, mVideoDirPath!!, downloadVideoName, downListener)
|
||||
}
|
||||
|
||||
fun startPlay(localVideoPath: String?) {
|
||||
@@ -196,40 +194,33 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private val downListener = object : IDownload {
|
||||
override fun onStart(url: String?) {
|
||||
private val downListener = object : IDownloadListener {
|
||||
|
||||
override fun onStart(url: String) {
|
||||
setCacheImageViewVisible()
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onStart")
|
||||
}
|
||||
|
||||
override fun onPause(url: String?, threadBean: ThreadBean?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onPause")
|
||||
// UiThreadHandler.postDelayed(Runnable {
|
||||
// startDownLoadVideo()
|
||||
// },DOWNLOAD_DELAY)
|
||||
// todo 测试下网络断掉是否会走onpause,且网络回复也不会继续下载
|
||||
override fun onProgress(url: String, downloaded: Long, total: Long) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onProgress== ${ (downloaded * 100 / total).toInt() }")
|
||||
}
|
||||
|
||||
override fun onProgress(url: String?, length: Int) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onProgress== $length")
|
||||
}
|
||||
|
||||
override fun onFinished(url: String?, threadBean: ThreadBean?, localPath: String?) {
|
||||
override fun onFinished(url: String, path: String) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onFinished = $url")
|
||||
if (url.equals(fileNetPath)) { //发现下载工具在断网又连网后,已完成的任务又都下载,跳转播放出现问题
|
||||
if (url == fileNetPath) { //发现下载工具在断网又连网后,已完成的任务又都下载,跳转播放出现问题
|
||||
//下载完成
|
||||
ThreadUtils.runOnUiThread {
|
||||
startPlay(Uri.fromFile(File(mVideoDirPath + downloadVideoName)).toString())
|
||||
startPlay(Uri.fromFile(File(path)).toString())
|
||||
}
|
||||
} else {//如果当前文件不存在再次去下载当前的
|
||||
Logger.d(
|
||||
ImageVideoRotationView.TAG, "download-onFinished = not current" +
|
||||
",currentUrl = $fileNetPath "
|
||||
)
|
||||
if (FileUtils.isFileExists(mVideoDirPath + downloadVideoName)) {
|
||||
if (FileUtils.isFileExists(path)) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "have download startPlay")
|
||||
ThreadUtils.runOnUiThread {
|
||||
startPlay(Uri.fromFile(File(mVideoDirPath + downloadVideoName)).toString())
|
||||
startPlay(Uri.fromFile(File(path)).toString())
|
||||
}
|
||||
return
|
||||
} else {
|
||||
@@ -238,14 +229,10 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(url: String?, errorMsg: String?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onError-$errorMsg")
|
||||
override fun onError(url: String, error: String?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onError-$error")
|
||||
//出错再次下载
|
||||
if (errorMsg != null) {
|
||||
if (errorMsg.startsWith("initFailed")) {
|
||||
startDownLoadVideo()
|
||||
}
|
||||
}
|
||||
startDownLoadVideo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
defaultConfig {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 31
|
||||
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
@@ -231,6 +231,7 @@ dependencies {
|
||||
androidTestImplementation rootProject.ext.dependencies.androidx_runner
|
||||
androidTestImplementation rootProject.ext.dependencies.androidx_espresso_core
|
||||
androidTestImplementation rootProject.ext.dependencies.localbroadcastmanager
|
||||
androidTestImplementation rootProject.ext.dependencies.downloader
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.mogo.functions.test
|
||||
|
||||
import android.util.*
|
||||
import androidx.test.core.app.*
|
||||
import androidx.test.ext.junit.runners.*
|
||||
import androidx.test.filters.*
|
||||
import androidx.test.platform.app.*
|
||||
import com.mogo.core.download.*
|
||||
import com.mogo.eagle.core.function.main.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import org.junit.*
|
||||
import org.junit.runner.*
|
||||
import java.io.*
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class DownloaderTest {
|
||||
|
||||
lateinit var launch: ActivityScenario<MainLauncherActivity>
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val TAG = "DownloaderTest"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDownload() = runBlocking {
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
Downloader.init(appContext)
|
||||
Downloader.download(
|
||||
"https://scm-1255510688.cos.ap-beijing.myqcloud.com/test/com.mogo.launcher.f/2.9.0.1002/IntelligentPilot_v2.9.0.1002_20220725_[fPadLenovoOchBus-launcher-qa]_debug.apk",
|
||||
File(appContext.getExternalFilesDir(null), "/apks/2.apk").absolutePath)
|
||||
.flowOn(Dispatchers.IO)
|
||||
.collect {
|
||||
when(it) {
|
||||
is DownloadStart -> Log.d(TAG, "下载开始: ${it.downloadUrl}")
|
||||
is DownloadFailed -> Log.d(TAG, "---error: ${it.msg}: ${it.downloadUrl}")
|
||||
is DownloadSuccess -> Log.d(TAG, "下载成功: ${it.path}, 文件存在?:${File(it.path).exists()}")
|
||||
is Downloading -> Log.d(TAG, "下载进度: ${it.downloaded}/${it.total}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -28,6 +28,8 @@ ext {
|
||||
amapsearch : "com.amap.api:search:9.5.0",
|
||||
amaplocation : "com.amap.api:location:6.2.0",
|
||||
|
||||
downloader : "com.mogo.core.net:downloader:1.0.5_stable",
|
||||
|
||||
// json 转换
|
||||
gson : "com.google.code.gson:gson:2.8.4",
|
||||
// 内存泄漏检测
|
||||
|
||||
@@ -13,14 +13,13 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
|
||||
import com.mogo.eagle.core.function.call.obu.*
|
||||
import com.mogo.eagle.core.function.call.v2x.CallerLimitingVelocityListenerManager
|
||||
import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager
|
||||
import com.mogo.eagle.core.function.datacenter.obu.drawer.*
|
||||
import com.mogo.eagle.core.function.datacenter.obu.utils.TrafficDataConvertUtilsNew
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.Config
|
||||
import com.mogo.eagle.core.utilcode.download.Config
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_OBU
|
||||
import com.mogo.eagle.core.utilcode.util.FileUtils
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.zhjt.mogo_core_function_devatools
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
@@ -268,7 +267,7 @@ class DevaToolsProvider : IDevaToolsProvider {
|
||||
}
|
||||
|
||||
override fun updateUpgradeProgress() {
|
||||
upgradeManager.updateUpgradeProgress(mContext!!)
|
||||
upgradeManager.updateUpgradeProgress()
|
||||
}
|
||||
|
||||
override fun showStatusBar(ctx: Context, container: ViewGroup) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.zhjt.mogo_core_function_devatools.upgrade
|
||||
|
||||
import android.content.*
|
||||
import android.util.*
|
||||
import com.elegant.utils.UiThreadHandler
|
||||
import com.mogo.cloud.passport.*
|
||||
import com.mogo.commons.constants.*
|
||||
import com.mogo.commons.utils.*
|
||||
@@ -14,7 +13,7 @@ import com.mogo.eagle.core.function.call.patch.CallerPatchManager.addPatchInfo
|
||||
import com.mogo.eagle.core.function.call.patch.CallerPatchManager.isPatchAccept
|
||||
import com.mogo.eagle.core.network.*
|
||||
import com.mogo.eagle.core.network.utils.*
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.Config
|
||||
import com.mogo.eagle.core.utilcode.download.Config
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr
|
||||
|
||||
@@ -15,10 +15,9 @@ import com.mogo.eagle.core.function.call.devatools.*
|
||||
import com.mogo.eagle.core.function.call.patch.CallerPatchManager
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager.updateStatusBarDownloadView
|
||||
import com.mogo.eagle.core.function.call.obu.CallerObuApiManager
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.Config
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.IDownload
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.utils.DownloadUtils
|
||||
import com.mogo.eagle.core.utilcode.download.Config
|
||||
import com.mogo.eagle.core.utilcode.download.callback.IDownloadListener
|
||||
import com.mogo.eagle.core.utilcode.download.DownloadUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
@@ -31,7 +30,7 @@ import kotlinx.coroutines.*
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class UpgradeManager : IDownload {
|
||||
class UpgradeManager : IDownloadListener {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -55,55 +54,29 @@ class UpgradeManager : IDownload {
|
||||
fun downLoadPackage(context: Context, type: DownloadType, downloadKey: String, downloadUrl: String) {
|
||||
CallerLogger.d("$M_DEVA$TAG", "UpgradeManager downLoadPackage = " + downloadUrl.contains(".zip") + "---type =" + type + "----downloadKey = $downloadKey ---downloadUrl = $downloadUrl")
|
||||
types[downloadUrl] = type
|
||||
DownloadUtils.downLoad(
|
||||
context,
|
||||
downloadUrl,
|
||||
if (type == OBU) Config.downLoadObuPath else Config.downLoadPath,
|
||||
downloadKey,
|
||||
5,
|
||||
this
|
||||
)
|
||||
DownloadUtils.downLoad(context, downloadUrl, if (type == OBU) Config.downLoadObuPath else Config.downLoadPath, downloadKey, this)
|
||||
}
|
||||
|
||||
override fun onStart(downloadUrl: String?) {
|
||||
CallerLogger.d("$M_DEVA$TAG","onStart downloadUrl : $downloadUrl")
|
||||
if (downloadUrl != null) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeStart(downloadUrl)
|
||||
val type = types[downloadUrl]
|
||||
if (type == PATCH || type == APK) {
|
||||
scope.launch {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadStart(downloadUrl)
|
||||
}
|
||||
override fun onStart(url: String) {
|
||||
CallerLogger.d("$M_DEVA$TAG","onStart downloadUrl : $url")
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeStart(url)
|
||||
val type = types[url]
|
||||
if (type == PATCH || type == APK) {
|
||||
scope.launch {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadStart(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause(downloadUrl: String?, threadBean: ThreadBean?) {
|
||||
CallerLogger.d("$M_DEVA$TAG","onPause downloadUrl : $downloadUrl , threadBean : $threadBean")
|
||||
if (downloadUrl != null) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradePause(downloadUrl)
|
||||
val type = types[downloadUrl]
|
||||
if (type == PATCH || type == APK) {
|
||||
scope.launch {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadPause(downloadUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onProgress(url: String, downloaded: Long, total: Long) {
|
||||
CallerLogger.d("$M_DEVA$TAG"," onProgress downloadUrl : $url , downloaded: $downloaded, total: $total")
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeProgress(url, (downloaded * 100 / total).toInt())
|
||||
|
||||
}
|
||||
|
||||
override fun onProgress(downloadUrl: String?, length: Int) {
|
||||
CallerLogger.d("$M_DEVA$TAG"," onProgress downloadUrl : $downloadUrl , length : $length")
|
||||
if (downloadUrl != null) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeProgress(downloadUrl, length)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFinished(downloadUrl: String?, threadBean: ThreadBean?, localPath: String) {
|
||||
Log.d(TAG, "onFinished downloadUrl = $downloadUrl")
|
||||
if (downloadUrl == null) {
|
||||
return
|
||||
}
|
||||
doOnFinished(downloadUrl, localPath)
|
||||
override fun onFinished(url: String, path: String) {
|
||||
Log.d(TAG, "onFinished downloadUrl = $url")
|
||||
doOnFinished(url, path)
|
||||
}
|
||||
|
||||
private fun doOnFinished(downloadUrl: String, localPath: String) {
|
||||
@@ -215,25 +188,23 @@ class UpgradeManager : IDownload {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(downloadUrl: String?, errorMsg: String?) {
|
||||
CallerLogger.d("$M_DEVA$TAG","onError downloadUrl : $downloadUrl , errorMsg : $errorMsg")
|
||||
if (downloadUrl != null) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeError(downloadUrl, errorMsg ?: "未知错误")
|
||||
val type = types[downloadUrl]
|
||||
if (type == APK || type == PATCH) {
|
||||
scope.launch { upgradeProvider?.recordDownloadFailed(downloadUrl,errorMsg ?: "下载失败") }
|
||||
} else if (type == OBU) {
|
||||
CallerLogger.e("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}", "----updateObuUpgradeStatus errorMsg = $errorMsg ")
|
||||
//下载失败,删除文件夹
|
||||
CallerObuApiManager.deleteObuFile()
|
||||
}
|
||||
override fun onError(url: String, error: String?) {
|
||||
CallerLogger.d("$M_DEVA$TAG","onError downloadUrl : $url , errorMsg : $error")
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeError(url, error ?: "未知错误")
|
||||
val type = types[url]
|
||||
if (type == APK || type == PATCH) {
|
||||
scope.launch { upgradeProvider?.recordDownloadFailed(url, error ?: "下载失败") }
|
||||
} else if (type == OBU) {
|
||||
CallerLogger.e("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}", "----updateObuUpgradeStatus errorMsg = $error ")
|
||||
//下载失败,删除文件夹
|
||||
CallerObuApiManager.deleteObuFile()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 鹰眼app下载监听
|
||||
*/
|
||||
fun updateUpgradeProgress(context: Context) {
|
||||
fun updateUpgradeProgress() {
|
||||
CallerDevaToolsUpgradeListenerManager.addListener(
|
||||
TAG,
|
||||
object : IMogoDevaToolsUpgradeListener {
|
||||
|
||||
@@ -74,6 +74,7 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.coroutinesandroid
|
||||
implementation rootProject.ext.dependencies.androidautoSize
|
||||
implementation rootProject.ext.dependencies.litezxing
|
||||
implementation rootProject.ext.dependencies.downloader
|
||||
|
||||
api rootProject.ext.dependencies.mogoaicloudpassport
|
||||
api rootProject.ext.dependencies.mogoaicloudnetwork
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FileBean implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String savePath;
|
||||
private String fileName;
|
||||
private String url;
|
||||
private int length;
|
||||
private int finished;
|
||||
private int threadCount;
|
||||
|
||||
public FileBean() {
|
||||
}
|
||||
|
||||
public FileBean(int id, String fileName, String url, int finished) {
|
||||
this.id = id;
|
||||
this.fileName = fileName;
|
||||
this.url = url;
|
||||
this.finished = finished;
|
||||
}
|
||||
public FileBean(int id, String savePath,String fileName, String url, int finished) {
|
||||
this.id = id;
|
||||
this.savePath = savePath;
|
||||
this.fileName = fileName;
|
||||
this.url = url;
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSavePath() {
|
||||
return savePath;
|
||||
}
|
||||
|
||||
public void setSavePath(String savePath) {
|
||||
this.savePath = savePath;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
|
||||
public int getFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(int finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public int getThreadCount() {
|
||||
return threadCount;
|
||||
}
|
||||
|
||||
public void setThreadCount(int threadCount) {
|
||||
this.threadCount = threadCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
int progress = (int) (finished*1.0f/length *100);
|
||||
return "FileBean{" +
|
||||
"id=" + id +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", length=" + length +
|
||||
", finished=" + finished +
|
||||
",progress="+progress+
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ThreadBean implements Serializable{
|
||||
|
||||
private int id;
|
||||
private String url;
|
||||
private int start;
|
||||
private int end;
|
||||
private int finished;
|
||||
|
||||
public ThreadBean() {
|
||||
}
|
||||
|
||||
public ThreadBean(int id, String url, int start, int end, int finished) {
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(int start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(int end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public int getFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(int finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ThreadBean{" +
|
||||
"id=" + id +
|
||||
", url='" + url + '\'' +
|
||||
", start=" + start +
|
||||
", end=" + end +
|
||||
", finished=" + finished +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.callback;
|
||||
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
|
||||
/**
|
||||
* 下载进度回调
|
||||
*/
|
||||
public interface DownloadCallBack {
|
||||
|
||||
/**
|
||||
* 开始下载
|
||||
*/
|
||||
void startDownload(String url);
|
||||
|
||||
/**
|
||||
* 暂停回调
|
||||
* @param threadBean
|
||||
*/
|
||||
void pauseCallBack(String url,ThreadBean threadBean);
|
||||
/**
|
||||
* 下载进度
|
||||
* @param length
|
||||
*/
|
||||
void progressCallBack(String url,int length);
|
||||
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath);
|
||||
|
||||
/**
|
||||
* 下载错误
|
||||
* @param msg
|
||||
*/
|
||||
void errorCallBack(String url, String msg);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.callback;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
|
||||
public interface IDownload {
|
||||
|
||||
/**
|
||||
* 开始下载
|
||||
*/
|
||||
void onStart(String url);
|
||||
|
||||
/**
|
||||
* 暂停回调
|
||||
*
|
||||
* @param threadBean
|
||||
*/
|
||||
void onPause(String url,ThreadBean threadBean);
|
||||
|
||||
/**
|
||||
* 下载进度
|
||||
*
|
||||
* @param length
|
||||
*/
|
||||
void onProgress(String url,int length);
|
||||
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void onFinished(String url, ThreadBean threadBean, String localPath);
|
||||
|
||||
/**
|
||||
* 错误信息回调
|
||||
* @param errorMsg
|
||||
*/
|
||||
void onError(String url,String errorMsg);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.db;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper{
|
||||
|
||||
private static final String DB_NAME = "download.db";
|
||||
private static DBHelper dbHelper = null;
|
||||
|
||||
public static DBHelper getInstance(Context context){
|
||||
if(dbHelper==null) dbHelper = new DBHelper(context);
|
||||
return dbHelper;
|
||||
}
|
||||
|
||||
private DBHelper(Context context) {
|
||||
super(context, DB_NAME, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
String sql = "create table thread_info (_id integer primary key autoincrement," +
|
||||
"thread_id integer,url text,start integer,ends integer,finished integer)";
|
||||
db.execSQL(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.db.dao;
|
||||
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ThreadDao {
|
||||
/**
|
||||
* 插入下载线程信息
|
||||
* @param threadBean
|
||||
*/
|
||||
void insertThread(ThreadBean threadBean);
|
||||
|
||||
/**
|
||||
* 更新下载线程信息
|
||||
* @param url
|
||||
* @param thread_id
|
||||
* @param finished
|
||||
*/
|
||||
void updateThread(String url, int thread_id, int finished);
|
||||
|
||||
/**
|
||||
* 删除下载线程
|
||||
* @param url
|
||||
*/
|
||||
void deleteThread(String url);
|
||||
|
||||
/**
|
||||
* 获取下载线程
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
List<ThreadBean> getThreads(String url);
|
||||
|
||||
/**
|
||||
* 判断下载线程是否存在
|
||||
* @param url
|
||||
* @param thread_id
|
||||
* @return
|
||||
*/
|
||||
boolean isExists(String url, int thread_id);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.db.impl;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.db.DBHelper;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.db.dao.ThreadDao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ThreadDaoImpl implements ThreadDao {
|
||||
|
||||
private final DBHelper dbHelper;
|
||||
|
||||
public ThreadDaoImpl(Context context){
|
||||
dbHelper = DBHelper.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void insertThread(ThreadBean threadBean) {
|
||||
SQLiteDatabase db = null;
|
||||
try {
|
||||
db = dbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
db.execSQL("insert into thread_info ( thread_id, url, start, ends, finished) values (?,?,?,?,?)"
|
||||
,new Object[]{threadBean.getId(),threadBean.getUrl(),threadBean.getStart(),threadBean.getEnd(),threadBean.getFinished()});
|
||||
db.endTransaction();
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateThread(String url, int thread_id, int finished) {
|
||||
SQLiteDatabase db = null;
|
||||
try {
|
||||
db = dbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
db.execSQL("update thread_info set finished = ? where url = ? and thread_id = ?"
|
||||
,new Object[]{finished,url,thread_id});
|
||||
db.endTransaction();
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteThread(String url) {
|
||||
SQLiteDatabase db = null;
|
||||
try {
|
||||
db = dbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
db.execSQL("delete from thread_info where url = ?",new Object[]{url});
|
||||
db.endTransaction();
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThreadBean> getThreads(String url) {
|
||||
SQLiteDatabase db = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
db = dbHelper.getReadableDatabase();
|
||||
cursor = db.rawQuery("select * from thread_info where url = ?",new String[]{url});
|
||||
List<ThreadBean> threadBeanList = new ArrayList<>();
|
||||
while (cursor.moveToNext()){
|
||||
ThreadBean bean = new ThreadBean();
|
||||
bean.setId(cursor.getInt(cursor.getColumnIndex("thread_id")));
|
||||
bean.setUrl(cursor.getString(cursor.getColumnIndex("url")));
|
||||
bean.setStart(cursor.getInt(cursor.getColumnIndex("start")));
|
||||
bean.setEnd(cursor.getInt(cursor.getColumnIndex("ends")));
|
||||
bean.setFinished(cursor.getInt(cursor.getColumnIndex("finished")));
|
||||
threadBeanList.add(bean);
|
||||
}
|
||||
return threadBeanList;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExists(String url, int thread_id) {
|
||||
SQLiteDatabase db = null;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
db = dbHelper.getReadableDatabase();
|
||||
cursor = db.rawQuery("select * from thread_info where url = ? and thread_id = ?", new String[]{url,thread_id+""});
|
||||
return cursor.moveToNext();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.event;
|
||||
|
||||
public class DownloadData {
|
||||
private String url;
|
||||
private int progress;
|
||||
private int length;
|
||||
private String msg;
|
||||
private String filePath;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.services;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.DownloadCallBack;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.IDownload;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.event.DownloadData;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.thread.DownloadTask;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.thread.InitThread;
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 下载服务
|
||||
*/
|
||||
public class DownloadService implements InitThread.InitCallBack, DownloadCallBack, NetworkUtils.OnNetworkStatusChangedListener {
|
||||
|
||||
public static final String ACTION_START = "ACTION_START";
|
||||
public static final String ACTION_PAUSE = "ACTION_PAUSE";
|
||||
private static final byte[] obj = new byte[0];
|
||||
private static volatile DownloadService downloadService;
|
||||
private final Context mContext;
|
||||
/**
|
||||
* 下载任务集合
|
||||
*/
|
||||
private final List<DownloadTask> downloadTasks = new ArrayList<>();
|
||||
private final Map<String, IDownload> callBacks = new ConcurrentHashMap<>();
|
||||
public static ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
|
||||
private IDownload mIDownload = null;
|
||||
|
||||
private DownloadService(Context context) {
|
||||
mContext = context;
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
}
|
||||
|
||||
public static DownloadService getInstance(Context context) {
|
||||
if (downloadService == null) {
|
||||
synchronized (obj) {
|
||||
if (downloadService == null) {
|
||||
downloadService = new DownloadService(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return downloadService;
|
||||
}
|
||||
|
||||
public synchronized void onStartCommand(Intent intent, IDownload iDownload) {
|
||||
mIDownload = iDownload;
|
||||
|
||||
if (intent == null) {
|
||||
Log.e(DOWN_LOAD_TAG, "onStartCommand intent is null");
|
||||
return;
|
||||
}
|
||||
|
||||
String action = intent.getAction();
|
||||
if (action == null) {
|
||||
Log.e(DOWN_LOAD_TAG, "onStartCommand action is null");
|
||||
return;
|
||||
}
|
||||
|
||||
FileBean fileBean = (FileBean) intent.getSerializableExtra("FileBean");
|
||||
if (fileBean == null) {
|
||||
Log.e(DOWN_LOAD_TAG, "onStartCommand bean is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equals(ACTION_START)) {
|
||||
Log.d(DOWN_LOAD_TAG, "ACTION_START");
|
||||
if (downloadTasks.size() > 0) {
|
||||
for (DownloadTask downloadTask : downloadTasks) {
|
||||
String url = downloadTask.getFileBean().getUrl();
|
||||
if (url.equals(fileBean.getUrl())) {
|
||||
//如果下载任务中以后该文件的下载任务 则直接返回
|
||||
iDownload.onError(fileBean.getUrl(), "下载任务已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
executorService.execute(new InitThread(fileBean, this));
|
||||
} else if (intent.getAction().equals(ACTION_PAUSE)) {
|
||||
DownloadTask pauseTask = null;
|
||||
if (downloadTasks.size() > 0) {
|
||||
for (DownloadTask downloadTask : downloadTasks) {
|
||||
if (downloadTask.getFileBean().getUrl().equals(fileBean.getUrl())) {
|
||||
downloadTask.pauseDownload();
|
||||
pauseTask = downloadTask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//将下载任务移除
|
||||
downloadTasks.remove(pauseTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//下载线程初始化完毕
|
||||
@Override
|
||||
public void initSuccess(FileBean fileBean) {
|
||||
Log.d(DOWN_LOAD_TAG, "length:" + fileBean.getLength());
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg("开始下载");
|
||||
downloadData.setLength(fileBean.getLength());
|
||||
//开始下载
|
||||
DownloadTask downloadTask = new DownloadTask(mContext, fileBean, fileBean.getThreadCount(), this);
|
||||
downloadTasks.add(downloadTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initFailed(DownloadData downloadData) {
|
||||
Log.e(DOWN_LOAD_TAG, "initFailed : " + downloadData.getMsg());
|
||||
IDownload iDownload = callBacks.get(downloadData.getUrl());
|
||||
if (iDownload != null) {
|
||||
iDownload.onError(downloadData.getUrl(), "initFailed : " + downloadData.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDownload(String url) {
|
||||
callBacks.put(url, mIDownload);
|
||||
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onStart(url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseCallBack(String url, ThreadBean threadBean) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onPause(url, threadBean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progressCallBack(String url, int length) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onProgress(url, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
Log.d(DOWN_LOAD_TAG, "下载完成 -----> iDownload = " + iDownload);
|
||||
Log.d("UpgradeManager", "-------threadDownLoadFinished localPath = " + localPath + "---iDownload = " + iDownload);
|
||||
if (iDownload != null) {
|
||||
iDownload.onFinished(url, threadBean, localPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void errorCallBack(String url, String msg) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onError(url, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
//网络连接已连接
|
||||
for (DownloadTask downloadTask : downloadTasks) {
|
||||
downloadTask.startDownload();//继续所有下载任务
|
||||
String url = downloadTask.getFileBean().getUrl();
|
||||
int length = downloadTask.getFileBean().getLength();
|
||||
Log.d(DOWN_LOAD_TAG, "网络恢复继续下载");
|
||||
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onProgress(url, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
//网络连接已断开
|
||||
for (DownloadTask downloadTask : downloadTasks) {
|
||||
downloadTask.pauseDownload();//暂停所有下载任务
|
||||
//发送下载进度回调
|
||||
String url = downloadTask.getFileBean().getUrl();
|
||||
Log.d(DOWN_LOAD_TAG, "网络断开暂停下载");
|
||||
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onPause(url, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.thread;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.DownloadCallBack;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.db.dao.ThreadDao;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.db.impl.ThreadDaoImpl;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.event.DownloadData;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.services.DownloadService;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 下载任务
|
||||
*/
|
||||
public class DownloadTask implements DownloadCallBack {
|
||||
|
||||
private final FileBean fileBean;
|
||||
private final int downloadThreadCount;
|
||||
private final ThreadDao dao;
|
||||
private final DownloadCallBack downloadCallBack;
|
||||
|
||||
/**
|
||||
* 总下载完成进度
|
||||
*/
|
||||
private int finishedProgress = 0;
|
||||
/**
|
||||
* 下载线程信息集合
|
||||
*/
|
||||
private List<ThreadBean> threads;
|
||||
/**
|
||||
* 下载线程集合
|
||||
*/
|
||||
private final List<DownloadThread> downloadThreads = new ArrayList<>();
|
||||
|
||||
public DownloadTask(Context context, FileBean fileBean, int downloadThreadCount, DownloadCallBack downloadCallBack) {
|
||||
this.fileBean = fileBean;
|
||||
this.downloadThreadCount = downloadThreadCount;
|
||||
this.downloadCallBack = downloadCallBack;
|
||||
dao = new ThreadDaoImpl(context);
|
||||
//初始化下载线程
|
||||
initDownThreads();
|
||||
}
|
||||
|
||||
private void initDownThreads() {
|
||||
//查询数据库中的下载线程信息
|
||||
threads = dao.getThreads(fileBean.getUrl());
|
||||
if (threads.size() == 0) {//如果列表没有数据 则为第一次下载
|
||||
Log.d(DOWN_LOAD_TAG, "第一次下载");
|
||||
//根据下载的线程总数平分各自下载的文件长度
|
||||
int length = fileBean.getLength() / downloadThreadCount;
|
||||
for (int i = 0; i < downloadThreadCount; i++) {
|
||||
ThreadBean thread = new ThreadBean(i, fileBean.getUrl(), i * length,
|
||||
(i + 1) * length - 1, 0);
|
||||
if (i == downloadThreadCount - 1) {
|
||||
thread.setEnd(fileBean.getLength());
|
||||
}
|
||||
//将下载线程保存到数据库
|
||||
dao.insertThread(thread);
|
||||
threads.add(thread);
|
||||
}
|
||||
}
|
||||
//创建下载线程开始下载
|
||||
for (ThreadBean thread : threads) {
|
||||
finishedProgress += thread.getFinished();
|
||||
DownloadThread downloadThread = new DownloadThread(fileBean, thread, this);
|
||||
DownloadService.executorService.execute(downloadThread);
|
||||
downloadThreads.add(downloadThread);
|
||||
}
|
||||
UiThreadHandler.post(() -> downloadCallBack.startDownload(fileBean.getUrl()));
|
||||
Log.d(DOWN_LOAD_TAG, " 开始下载:" + finishedProgress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始下载
|
||||
*/
|
||||
public void startDownload() {
|
||||
finishedProgress = 0;
|
||||
threads.clear();
|
||||
downloadThreads.clear();
|
||||
initDownThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停下载
|
||||
*/
|
||||
public void pauseDownload() {
|
||||
for (DownloadThread downloadThread : downloadThreads) {
|
||||
if (downloadThread != null) {
|
||||
downloadThread.setPause(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDownload(String url) {
|
||||
UiThreadHandler.post(() -> downloadCallBack.startDownload(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseCallBack(String url, ThreadBean threadBean) {
|
||||
//保存下载进度到数据库
|
||||
Log.d(DOWN_LOAD_TAG, "保存数据:" + threadBean.toString());
|
||||
dao.updateThread(threadBean.getUrl(), threadBean.getId(), threadBean.getFinished());
|
||||
UiThreadHandler.post(() -> downloadCallBack.pauseCallBack(url,threadBean));
|
||||
}
|
||||
|
||||
private long curTime = 0;
|
||||
|
||||
@Override
|
||||
public void progressCallBack(String url, int length) {
|
||||
finishedProgress += length;
|
||||
//每500毫秒发送刷新进度事件
|
||||
if (System.currentTimeMillis() - curTime > 500 || finishedProgress == fileBean.getLength()) {
|
||||
int progress = (int) (finishedProgress * 1.0 / fileBean.getLength() * 100);
|
||||
fileBean.setFinished(finishedProgress);
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setProgress(progress);
|
||||
downloadData.setLength(fileBean.getLength());
|
||||
downloadData.setMsg("下载进度回调");
|
||||
UiThreadHandler.post(() -> downloadCallBack.progressCallBack(url,progress));
|
||||
curTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
for (ThreadBean bean : threads) {
|
||||
if (bean.getId() == threadBean.getId()) {
|
||||
//从列表中将已下载完成的线程信息移除
|
||||
threads.remove(bean);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (threads.size() == 0) {//如果列表size为0 则所有线程已下载完成
|
||||
Log.d(DOWN_LOAD_TAG, " DownloadTask threadDownLoadFinished 下载完成----->");
|
||||
//删除数据库中的信息
|
||||
dao.deleteThread(fileBean.getUrl());
|
||||
//发送下载完成事件
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg("下载完成");
|
||||
downloadData.setFilePath(fileBean.getSavePath() + fileBean.getFileName());
|
||||
UiThreadHandler.post(() -> downloadCallBack.threadDownLoadFinished(url,threadBean, localPath));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void errorCallBack(String url, String msg) {
|
||||
UiThreadHandler.post(() -> downloadCallBack.errorCallBack(url, msg));
|
||||
}
|
||||
|
||||
public FileBean getFileBean() {
|
||||
return fileBean;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.thread;
|
||||
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.ThreadBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.DownloadCallBack;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.event.DownloadData;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 下载线程
|
||||
*/
|
||||
public class DownloadThread extends Thread {
|
||||
|
||||
private final FileBean fileBean;
|
||||
private final ThreadBean threadBean;
|
||||
private final DownloadCallBack callback;
|
||||
private Boolean isPause = false;
|
||||
|
||||
public DownloadThread(FileBean fileBean, ThreadBean threadBean, DownloadCallBack callback) {
|
||||
this.fileBean = fileBean;
|
||||
this.threadBean = threadBean;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void setPause(Boolean pause) {
|
||||
isPause = pause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
HttpURLConnection connection = null;
|
||||
RandomAccessFile raf = null;
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
URL url = new URL(threadBean.getUrl());
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setConnectTimeout(10000);
|
||||
connection.setRequestMethod("GET");
|
||||
//设置下载起始位置
|
||||
int start = threadBean.getStart() + threadBean.getFinished();
|
||||
connection.setRequestProperty("Range","bytes="+start+"-"+threadBean.getEnd());
|
||||
//设置写入位置
|
||||
File file = new File(fileBean.getSavePath(),fileBean.getFileName());
|
||||
raf = new RandomAccessFile(file,"rwd");
|
||||
raf.seek(start);
|
||||
//开始下载
|
||||
Log.d(DOWN_LOAD_TAG, "DownloadThread connection.getResponseCode() = " + connection.getResponseCode() + "---threadBean.getUrl() =" + threadBean.getUrl());
|
||||
if(connection.getResponseCode() == HttpURLConnection.HTTP_PARTIAL){
|
||||
inputStream = connection.getInputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = -1;
|
||||
while ((len = inputStream.read(bytes))!=-1){
|
||||
raf.write(bytes,0,len);
|
||||
//将加载的进度回调出去
|
||||
callback.progressCallBack(fileBean.getUrl(), len);
|
||||
//保存进度
|
||||
threadBean.setFinished(threadBean.getFinished()+len);
|
||||
//在下载暂停的时候将下载进度保存到数据库
|
||||
if(isPause){
|
||||
UiThreadHandler.post(() -> callback.pauseCallBack(this.fileBean.getUrl(),threadBean));
|
||||
return;
|
||||
}
|
||||
}
|
||||
//下载完成
|
||||
UiThreadHandler.post(() -> callback.threadDownLoadFinished(this.fileBean.getUrl(),threadBean, file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(DOWN_LOAD_TAG, "error: " + e.getMessage());
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg(e.getMessage());
|
||||
UiThreadHandler.post(() -> callback.errorCallBack(this.fileBean.getUrl(), e.getMessage()));
|
||||
|
||||
// EventMessage eventMessage = new EventMessage(EventMessage.TYPE_ERROR,downloadData);
|
||||
// EventBus.getDefault().post(eventMessage);
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
raf.close();
|
||||
connection.disconnect();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
Log.e(DOWN_LOAD_TAG, "error2: " + e.getMessage());
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg(e.getMessage());
|
||||
// EventMessage eventMessage = new EventMessage(EventMessage.TYPE_ERROR,downloadData);
|
||||
// EventBus.getDefault().post(eventMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.thread;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.event.DownloadData;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 初始化线程
|
||||
*/
|
||||
public class InitThread extends Thread {
|
||||
|
||||
private final FileBean fileBean;
|
||||
private final InitCallBack initCallBack;
|
||||
|
||||
public InitThread(FileBean fileBean, InitCallBack initCallBack) {
|
||||
this.fileBean = fileBean;
|
||||
this.initCallBack = initCallBack;
|
||||
}
|
||||
|
||||
public interface InitCallBack {
|
||||
|
||||
void initSuccess(FileBean fileBean);
|
||||
|
||||
void initFailed(DownloadData downloadData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
HttpURLConnection connection;
|
||||
RandomAccessFile randomAccessFile;
|
||||
try {
|
||||
URL url = new URL(fileBean.getUrl());
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setConnectTimeout(10000);
|
||||
connection.setRequestMethod("GET");
|
||||
int fileLength = -1;
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
fileLength = connection.getContentLength();
|
||||
}
|
||||
Log.d(DOWN_LOAD_TAG, "InitThread fileLength = " + fileLength + "---connection.getResponseCode() = " + connection.getResponseCode());
|
||||
if (fileLength <= 0) return;
|
||||
File dir = new File(fileBean.getSavePath());
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
File file = new File(dir, fileBean.getFileName());
|
||||
randomAccessFile = new RandomAccessFile(file, "rwd");
|
||||
randomAccessFile.setLength(fileLength);
|
||||
fileBean.setLength(fileLength);
|
||||
this.initCallBack.initSuccess(fileBean);
|
||||
} catch (Exception e) {
|
||||
Log.e(DOWN_LOAD_TAG, "InitThread e = " + e);
|
||||
DownloadData downloadData = new DownloadData();
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg(e.getMessage());
|
||||
this.initCallBack.initFailed(downloadData);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.callback.IDownload;
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.services.DownloadService;
|
||||
|
||||
|
||||
public class DownloadUtils {
|
||||
|
||||
public static void downLoad(Context context, String url, String savePath, String fileName, int downloadThreadCount, IDownload iDownload) {
|
||||
FileBean fileBean = new FileBean(0, savePath, fileName, url, 0);
|
||||
fileBean.setThreadCount(downloadThreadCount);
|
||||
Intent startIntent = new Intent(context, DownloadService.class);
|
||||
startIntent.setAction(DownloadService.ACTION_START);
|
||||
startIntent.putExtra("FileBean", fileBean);
|
||||
DownloadService.getInstance(context).onStartCommand(startIntent, iDownload);
|
||||
}
|
||||
|
||||
public static void pauseDownLoad(Context context, String url, IDownload iDownload) {
|
||||
FileBean fileBean = new FileBean(0, null, null, url, 0);
|
||||
Intent pauseIntent = new Intent(context, DownloadService.class);
|
||||
pauseIntent.setAction(DownloadService.ACTION_PAUSE);
|
||||
pauseIntent.putExtra("FileBean", fileBean);
|
||||
DownloadService.getInstance(context).onStartCommand(pauseIntent, iDownload);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.eagle.core.utilcode.breakpoint;
|
||||
package com.mogo.eagle.core.utilcode.download;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mogo.eagle.core.utilcode.download
|
||||
|
||||
import android.content.*
|
||||
import com.mogo.core.download.*
|
||||
import com.mogo.eagle.core.utilcode.download.callback.*
|
||||
import com.mogo.eagle.core.utilcode.util.BuildConfig
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.io.*
|
||||
|
||||
object DownloadUtils {
|
||||
|
||||
|
||||
private val poller = object : INetStatePoller {
|
||||
|
||||
override fun interval(): Long {
|
||||
return 5000
|
||||
}
|
||||
|
||||
override fun isNetConnected(): Boolean {
|
||||
return NetworkUtils.isConnected()
|
||||
}
|
||||
}
|
||||
|
||||
private val scope by lazy { CoroutineScope(ThreadUtils.getIoPool().asCoroutineDispatcher() + SupervisorJob()) }
|
||||
|
||||
fun downLoad(ctx: Context?, url: String, savePath: String, fileName: String, listener: IDownloadListener?) { // FileBean fileBean = new FileBean(0, savePath, fileName, url, 0);
|
||||
val context = ctx ?: Utils.getApp() ?: throw AssertionError("context must not be null.")
|
||||
if (!Downloader.hasInit()) {
|
||||
Downloader.init(context)
|
||||
Downloader.setLoggable(BuildConfig.DEBUG)
|
||||
}
|
||||
Downloader.setNetStatePoller(poller)
|
||||
Downloader.download(url, File(savePath, fileName))
|
||||
.onEach {
|
||||
when(it) {
|
||||
is DownloadStart ->
|
||||
UiThreadHandler.post { listener?.onStart(url) }
|
||||
is Downloading -> {
|
||||
UiThreadHandler.post { listener?.onProgress(url, it.downloaded, it.total) }
|
||||
}
|
||||
is DownloadSuccess -> {
|
||||
UiThreadHandler.post { listener?.onFinished(url, it.path)}
|
||||
}
|
||||
is DownloadFailed -> {
|
||||
UiThreadHandler.post { listener?.onError(url, it.msg) }
|
||||
}
|
||||
}
|
||||
}
|
||||
.filter {
|
||||
it.isComplete()
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mogo.eagle.core.utilcode.download.callback
|
||||
|
||||
interface IDownloadListener {
|
||||
/**
|
||||
* 开始下载
|
||||
*/
|
||||
fun onStart(url: String)
|
||||
|
||||
/**
|
||||
* 下载进度
|
||||
*
|
||||
* @param url 下载链接
|
||||
* @param downloaded 已下载进度
|
||||
* @param total 文件总大小
|
||||
*/
|
||||
fun onProgress(url: String, downloaded: Long, total: Long)
|
||||
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param path 下载完成后的本地存储路径
|
||||
*/
|
||||
fun onFinished(url: String, path: String)
|
||||
|
||||
/**
|
||||
* 错误信息回调
|
||||
* @param error 下载失败后的错误消息
|
||||
*/
|
||||
fun onError(url: String, error: String?)
|
||||
}
|
||||
@@ -146,10 +146,7 @@ ADAS_DATA_LIB_CHILD_VERSION=.4
|
||||
|
||||
# 是否支持patch升级
|
||||
PATCH_UPGRADE_SUPPORT=true
|
||||
MOGO_PLUGIN_VERSION=1.0.0.31
|
||||
|
||||
# 线程优化版本
|
||||
THREAD_OPT_VERSION=4.0.1
|
||||
# matrix版本
|
||||
MATRIX_VERSION=2.0.8
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
//apply ByteX宿主
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
def isAndroidTest = rootProject.isAndroidTestBuild()
|
||||
if (!isAndroidTest) {
|
||||
apply plugin: 'bytex'
|
||||
|
||||
ByteX {
|
||||
enable true
|
||||
enableInDebug true
|
||||
}
|
||||
|
||||
apply from: rootProject.file('gradle/bytex/bytex_config.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_router.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_log_chain.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_sticky_service.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_thread_opt.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_lancetx.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_apm.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_systrace.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_matrix.gradle')
|
||||
}
|
||||
apply from: rootProject.file('gradle/bytex/bytex_config.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_router.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_log_chain.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_sticky_service.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_thread_opt.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_lancetx.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_apm.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_systrace.gradle')
|
||||
apply from: rootProject.file('gradle/bytex/bytex_matrix.gradle')
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'apm-plugin'
|
||||
ApmPlugin {
|
||||
// 是否进行插桩
|
||||
enable true
|
||||
// 是否在Debug包插桩,默认不插桩
|
||||
enableInDebug true
|
||||
// DEBUG("DEBUG"), INFO("INFO"), WARN("WARN"), ERROR("ERROR");
|
||||
// INFO 级别Log会汇总所有被插桩处理的类供查看,路径 app/build/ByteX/ApmPlugin
|
||||
logLevel "DEBUG"
|
||||
// 启动分析开关:监控App启动耗时,需要同时开启pageLoadSwitch
|
||||
startSwitch = true
|
||||
// 页面响应开关:监控Activity的生命周期耗时
|
||||
pageLoadSwitch = true
|
||||
// 网络监控开关:监控okhttp3的网络请求
|
||||
okHttp3Switch = false
|
||||
// 白名单下的包进行插桩,需要填写要插装类所在的包名,支持前缀配置
|
||||
whiteList = [
|
||||
"com.mogo"
|
||||
]
|
||||
// 黑名单包下类不进行插桩,可以配置包名和类名,没有可以填空
|
||||
blackList = [
|
||||
apply plugin: 'apm-plugin'
|
||||
ApmPlugin {
|
||||
// 是否进行插桩
|
||||
enable true
|
||||
// 是否在Debug包插桩,默认不插桩
|
||||
enableInDebug true
|
||||
// DEBUG("DEBUG"), INFO("INFO"), WARN("WARN"), ERROR("ERROR");
|
||||
// INFO 级别Log会汇总所有被插桩处理的类供查看,路径 app/build/ByteX/ApmPlugin
|
||||
logLevel "DEBUG"
|
||||
// 启动分析开关:监控App启动耗时,需要同时开启pageLoadSwitch
|
||||
startSwitch = true
|
||||
// 页面响应开关:监控Activity的生命周期耗时
|
||||
pageLoadSwitch = true
|
||||
// 网络监控开关:监控okhttp3的网络请求
|
||||
okHttp3Switch = false
|
||||
// 白名单下的包进行插桩,需要填写要插装类所在的包名,支持前缀配置
|
||||
whiteList = [
|
||||
"com.mogo"
|
||||
]
|
||||
// 黑名单包下类不进行插桩,可以配置包名和类名,没有可以填空
|
||||
blackList = [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'biz.config.hook'
|
||||
}
|
||||
|
||||
apply plugin: 'biz.config.hook'
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'LancetX'
|
||||
LancetX {
|
||||
enable true
|
||||
enableInDebug true
|
||||
weaveGroup {
|
||||
anr_fix {
|
||||
enable true
|
||||
}
|
||||
crash_fix {
|
||||
enable true
|
||||
}
|
||||
memory_leak {
|
||||
enable true
|
||||
}
|
||||
textview_opt {
|
||||
enable true
|
||||
}
|
||||
apply plugin: 'LancetX'
|
||||
LancetX {
|
||||
enable true
|
||||
enableInDebug true
|
||||
weaveGroup {
|
||||
anr_fix {
|
||||
enable true
|
||||
}
|
||||
crash_fix {
|
||||
enable true
|
||||
}
|
||||
memory_leak {
|
||||
enable true
|
||||
}
|
||||
textview_opt {
|
||||
enable true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'chain.log.hook'
|
||||
hooklog {
|
||||
enableTraceToServer false
|
||||
enableLoggerToLocal true
|
||||
}
|
||||
apply plugin: 'chain.log.hook'
|
||||
hooklog {
|
||||
enableTraceToServer false
|
||||
enableLoggerToLocal true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'bytex.arouter'
|
||||
arouter {
|
||||
enable true
|
||||
enableInDebug true
|
||||
}
|
||||
apply plugin: 'bytex.arouter'
|
||||
arouter {
|
||||
enable true
|
||||
enableInDebug true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'bytex.notsticky.service'
|
||||
}
|
||||
apply plugin: 'bytex.notsticky.service'
|
||||
@@ -1,50 +1,48 @@
|
||||
//if (!isAndroidTestBuild()) {
|
||||
///**
|
||||
// * 方便使用systrace工具,在工程侧打点,便于分析工程侧性能问题
|
||||
// */
|
||||
//apply plugin: 'bytex.systrace'
|
||||
//systrace {
|
||||
// /**
|
||||
// * 方便使用systrace工具,在工程侧打点,便于分析工程侧性能问题
|
||||
// * 交付时要关闭,会有性能损耗
|
||||
// */
|
||||
// apply plugin: 'bytex.systrace'
|
||||
// systrace {
|
||||
// /**
|
||||
// * 交付时要关闭,会有性能损耗
|
||||
// */
|
||||
// enable false
|
||||
// enableInDebug false
|
||||
// /**
|
||||
// * - 是否使用[Trace.beginAsyncSection(String, int)/Trace.endAsyncSection(String, int)]进行打点
|
||||
// * - 默认使用[Trace.beginSection(String)/Trace.endSection()]进行打点
|
||||
// */
|
||||
// isTraceAsync false
|
||||
// /**
|
||||
// * - 是否在运行时只针对主线程打点,其它线程不打
|
||||
// */
|
||||
// isOnlyMainThread false
|
||||
// enable false
|
||||
// enableInDebug false
|
||||
// /**
|
||||
// * - 是否使用[Trace.beginAsyncSection(String, int)/Trace.endAsyncSection(String, int)]进行打点
|
||||
// * - 默认使用[Trace.beginSection(String)/Trace.endSection()]进行打点
|
||||
// */
|
||||
// isTraceAsync false
|
||||
// /**
|
||||
// * - 是否在运行时只针对主线程打点,其它线程不打
|
||||
// */
|
||||
// isOnlyMainThread false
|
||||
//
|
||||
// /**
|
||||
// * - 是否忽略对类的静态构造方法打点
|
||||
// * - 默认不忽略
|
||||
// */
|
||||
// isIgnoreClinitMethod false
|
||||
// /**
|
||||
// * - 是否忽略对类的静态构造方法打点
|
||||
// * - 默认不忽略
|
||||
// */
|
||||
// isIgnoreClinitMethod false
|
||||
//
|
||||
// /**
|
||||
// * - 是否忽略对类中的简单方法打点
|
||||
// * 简单方法定义:
|
||||
// * - 空方法
|
||||
// * - get/set 方法
|
||||
// * - 单独的方法,方法体内没有调用其它方法
|
||||
// * - 默认不忽略
|
||||
// */
|
||||
// isIgnoreSampleMethod false
|
||||
// /**
|
||||
// * - 是否忽略对类中的简单方法打点
|
||||
// * 简单方法定义:
|
||||
// * - 空方法
|
||||
// * - get/set 方法
|
||||
// * - 单独的方法,方法体内没有调用其它方法
|
||||
// * - 默认不忽略
|
||||
// */
|
||||
// isIgnoreSampleMethod false
|
||||
//
|
||||
// /**
|
||||
// * - 针对特定类集合,配置打点白名单,在此集合中的类中的所有方法不打点
|
||||
// * - 支持正则表达式
|
||||
// */
|
||||
// whiteListForClass = []
|
||||
// /**
|
||||
// * - 针对特定类集合,配置打点白名单,在此集合中的类中的所有方法不打点
|
||||
// * - 支持正则表达式
|
||||
// */
|
||||
// whiteListForClass = []
|
||||
//
|
||||
// /**
|
||||
// * - 针对特定包名集合,配置打点白名单,所有类以此包名为前缀的类不打点
|
||||
// * - 支持正则表达式
|
||||
// */
|
||||
// whiteListForPackage = []
|
||||
// }
|
||||
// /**
|
||||
// * - 针对特定包名集合,配置打点白名单,所有类以此包名为前缀的类不打点
|
||||
// * - 支持正则表达式
|
||||
// */
|
||||
// whiteListForPackage = []
|
||||
//}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
if (!rootProject.isAndroidTestBuild()) {
|
||||
apply plugin: 'bytex.threadOpt'
|
||||
thread_opt {
|
||||
enable true
|
||||
enableInDebug true
|
||||
logLevel "DEBUG"
|
||||
}
|
||||
apply plugin: 'bytex.threadOpt'
|
||||
thread_opt {
|
||||
enable true
|
||||
enableInDebug true
|
||||
logLevel "DEBUG"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user