[dev_opt_2.15.0] 优化下载逻辑
This commit is contained in:
@@ -44,7 +44,6 @@ class UpgradeManager : IDownload {
|
||||
}
|
||||
|
||||
private var map: Map<String, String>? = null
|
||||
private var mDownloadFileName: String? = null
|
||||
|
||||
private val upgradeProvider: IMoGoUpgradeProvider? by lazy { CallerBase.getApiInstance(IMoGoUpgradeProvider::class.java, MogoServicePaths.PATH_UPGRADE_TYPE_API) }
|
||||
|
||||
@@ -56,9 +55,6 @@ class UpgradeManager : IDownload {
|
||||
|
||||
fun downLoadPackage(context: Context, type: DownloadType, downloadKey: String, downloadUrl: String) {
|
||||
CallerLogger.d("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}", "UpgradeManager downLoadPackage = " + downloadUrl.contains(".zip") + "----downloadKey = $downloadKey ---downloadUrl = $downloadUrl")
|
||||
if (type == OBU) {
|
||||
mDownloadFileName = downloadKey
|
||||
}
|
||||
types[downloadUrl] = type
|
||||
DownloadUtils.downLoad(
|
||||
context,
|
||||
@@ -115,7 +111,7 @@ class UpgradeManager : IDownload {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFinished(downloadUrl: String?, threadBean: ThreadBean?) {
|
||||
override fun onFinished(downloadUrl: String?, threadBean: ThreadBean?, localPath: String) {
|
||||
if (downloadUrl != null) {
|
||||
val type = types[downloadUrl]
|
||||
if (type == APK || type == PATCH) {
|
||||
@@ -124,7 +120,7 @@ class UpgradeManager : IDownload {
|
||||
var isPatchInstallFailed = false
|
||||
var patchInstallFailedReason = ""
|
||||
CallerPatchManager.removePatchInfoByUrl(downloadUrl)
|
||||
val patch = File(Config.downLoadPath, downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1))
|
||||
val patch = File(localPath)
|
||||
if (patch.exists()) {
|
||||
try {
|
||||
val newApk = File(Utils.getApp().getExternalFilesDir(null), "patch/merged/${SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.ROOT).format(Date()) }.apk")
|
||||
@@ -210,8 +206,7 @@ class UpgradeManager : IDownload {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val apkPath = Config.downLoadPath + downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1)
|
||||
val apk = File(apkPath)
|
||||
val apk = File(localPath)
|
||||
ApkInstaller.installApp(Utils.getApp(), apk) { code, reason ->
|
||||
if (code != PackageInstaller.STATUS_SUCCESS) {
|
||||
upgradeProvider?.also { itx ->
|
||||
@@ -231,10 +226,10 @@ class UpgradeManager : IDownload {
|
||||
}
|
||||
if (downloadUrl != null) {
|
||||
if (map.isNullOrEmpty()) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(downloadUrl)
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(downloadUrl, localPath)
|
||||
} else {
|
||||
findKey(downloadUrl) {
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(it)
|
||||
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(it, localPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +286,7 @@ class UpgradeManager : IDownload {
|
||||
updateStatusBarDownloadView(true, "download", length)
|
||||
}
|
||||
|
||||
override fun onFinished(url: String?) {
|
||||
override fun onFinished(url: String?, localPath: String) {
|
||||
builder.setContentText("已下载" + 100 + "%")
|
||||
UiThreadHandler.postDelayed({
|
||||
manager.cancel(0x3)
|
||||
@@ -316,11 +311,12 @@ class UpgradeManager : IDownload {
|
||||
override fun onProgress(url: String?, length: Int) {
|
||||
}
|
||||
|
||||
override fun onFinished(url: String?) {
|
||||
override fun onFinished(url: String?, localPath: String) {
|
||||
//下载完成,解压文件
|
||||
try {
|
||||
val files = ZipUtils.unzipFile(Config.downLoadObuPath + mDownloadFileName, Config.downLoadUnzipObuPath)
|
||||
CallerLogger.d("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}", " onFinished file = ${Config.downLoadObuPath + mDownloadFileName} -----files = $files ")
|
||||
val dest = File(localPath)
|
||||
val files = ZipUtils.unzipFile(localPath, Config.downLoadUnzipObuPath)
|
||||
CallerLogger.d("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}", " onFinished file = ${Config.downLoadObuPath + dest.name} -----files = $files ")
|
||||
//1传给obu升级,升级成功,2需要删除相应文件夹
|
||||
var md5Path = ""
|
||||
var tarPath = ""
|
||||
|
||||
@@ -22,7 +22,7 @@ interface IMogoDevaToolsUpgradeListener {
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*/
|
||||
fun onFinished(url: String?)
|
||||
fun onFinished(url: String?, localPath: String)
|
||||
|
||||
/**
|
||||
* 错误信息回调
|
||||
|
||||
@@ -27,10 +27,10 @@ object CallerDevaToolsUpgradeListenerManager : CallerBase<IMogoDevaToolsUpgrade
|
||||
}
|
||||
}
|
||||
|
||||
fun invokeUpgradeFinish(url: String) {
|
||||
fun invokeUpgradeFinish(url: String, destLocalPath: String) {
|
||||
M_LISTENERS.forEach {
|
||||
val listener = it.value
|
||||
listener.onFinished(url)
|
||||
listener.onFinished(url, destLocalPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ public interface DownloadCallBack {
|
||||
|
||||
/**
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void threadDownLoadFinished(String url,ThreadBean threadBean);
|
||||
void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ public interface IDownload {
|
||||
* 线程下载完毕
|
||||
*
|
||||
* @param threadBean
|
||||
* @param localPath
|
||||
*/
|
||||
void onFinished(String url,ThreadBean threadBean);
|
||||
void onFinished(String url, ThreadBean threadBean, String localPath);
|
||||
|
||||
/**
|
||||
* 错误信息回调
|
||||
|
||||
@@ -154,10 +154,10 @@ public class DownloadService implements InitThread.InitCallBack, DownloadCallBac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void threadDownLoadFinished(String url, ThreadBean threadBean) {
|
||||
public void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
IDownload iDownload = callBacks.get(url);
|
||||
if (iDownload != null) {
|
||||
iDownload.onFinished(url, threadBean);
|
||||
iDownload.onFinished(url, threadBean, localPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class DownloadTask implements DownloadCallBack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void threadDownLoadFinished(String url, ThreadBean threadBean) {
|
||||
public synchronized void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath) {
|
||||
for (ThreadBean bean : threads) {
|
||||
if (bean.getId() == threadBean.getId()) {
|
||||
//从列表中将已下载完成的线程信息移除
|
||||
@@ -151,7 +151,7 @@ public class DownloadTask implements DownloadCallBack {
|
||||
downloadData.setUrl(fileBean.getUrl());
|
||||
downloadData.setMsg("下载完成");
|
||||
downloadData.setFilePath(fileBean.getSavePath() + fileBean.getFileName());
|
||||
UiThreadHandler.post(() -> downloadCallBack.threadDownLoadFinished(url,threadBean));
|
||||
UiThreadHandler.post(() -> downloadCallBack.threadDownLoadFinished(url,threadBean, localPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,10 @@ import static com.mogo.eagle.core.utilcode.breakpoint.Config.DOWN_LOAD_TAG;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.Config;
|
||||
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.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
|
||||
import java.io.File;
|
||||
@@ -53,7 +51,7 @@ public class DownloadThread extends Thread {
|
||||
int start = threadBean.getStart() + threadBean.getFinished();
|
||||
connection.setRequestProperty("Range","bytes="+start+"-"+threadBean.getEnd());
|
||||
//设置写入位置
|
||||
File file = new File(fileBean.getFileName().contains(".zip") ? Config.downLoadObuPath : Config.downLoadPath,fileBean.getFileName());
|
||||
File file = new File(fileBean.getSavePath(),fileBean.getFileName());
|
||||
raf = new RandomAccessFile(file,"rwd");
|
||||
raf.seek(start);
|
||||
//开始下载
|
||||
@@ -75,7 +73,7 @@ public class DownloadThread extends Thread {
|
||||
}
|
||||
}
|
||||
//下载完成
|
||||
UiThreadHandler.post(() -> callback.threadDownLoadFinished(this.fileBean.getUrl(),threadBean));
|
||||
UiThreadHandler.post(() -> callback.threadDownLoadFinished(this.fileBean.getUrl(),threadBean, file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user