[dev_opt_2.15.0] 优化下载逻辑

This commit is contained in:
renwj
2023-03-07 16:13:20 +08:00
parent 3c58608ca6
commit 908ca545e9
8 changed files with 24 additions and 27 deletions

View File

@@ -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 = ""