[6.2.8][应用升级] 优化升级逻辑,防止重复下载

This commit is contained in:
renwj
2024-01-18 20:24:20 +08:00
parent 657fb9eb29
commit c0d8a47cc3
3 changed files with 21 additions and 0 deletions

View File

@@ -55,6 +55,12 @@ class UpgradeAppNetWorkManager private constructor() {
fun getAppUpgradeInfo(context: Context?, mac: String, screenType: String) {
upgradeJob?.safeCancel()
scope.launch {
if (provider?.isDownloading() == true) {
withContext(Dispatchers.Main) {
ToastUtils.showShort("正在下载最新版本,不要重复下载...")
}
return@launch
}
val sn = SharedPrefsMgr.getInstance().sn
val macAddress = mac //"48:b0:2d:4d:31:7f"
val type = screenType //"10"

View File

@@ -18,10 +18,13 @@ import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecor
import com.zhjt.service.chain.*
import java.util.TreeMap
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
@Route(path = MogoServicePaths.PATH_UPGRADE_TYPE_API)
class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
private val isDownloading by lazy { AtomicBoolean(false) }
override fun init(context: Context?) {}
override suspend fun recordUpgradeRecord(sn: String, mac: String, type: String?, isSupportPatch: Boolean) {
@@ -80,6 +83,8 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
onUpgradeRecordLinkLog(mapOf("upgrade_download_start" to record))
} catch (t: Throwable) {
t.printStackTrace()
} finally {
isDownloading.set(true)
}
}
@@ -100,6 +105,8 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
onUpgradeRecordLinkLog(mapOf("upgrade_download_failed" to record))
} catch (t: Throwable) {
t.printStackTrace()
} finally {
isDownloading.set(false)
}
}
@@ -110,6 +117,8 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
onUpgradeRecordLinkLog(mapOf("upgrade_download_success" to record))
} catch (t: Throwable) {
t.printStackTrace()
} finally {
isDownloading.set(false)
}
}
@@ -297,6 +306,10 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
} == null
}
override fun isDownloading(): Boolean {
return isDownloading.get()
}
private fun getType(type: Int): Type = if (type == 0) FULL else PATCH

View File

@@ -49,4 +49,6 @@ interface IMoGoUpgradeProvider: IProvider {
suspend fun hasUpgradeRecord(): Boolean
suspend fun isNeedGoPatchUpgrade(): Boolean
fun isDownloading(): Boolean
}