[2.15.0] 升级功能添加链路日志

This commit is contained in:
renwj
2023-03-27 16:22:31 +08:00
parent 65e0802de5
commit e14bde9129

View File

@@ -4,6 +4,8 @@ import android.content.*
import android.content.pm.PackageInstaller
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.data.deva.chain.*
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion
import com.mogo.eagle.core.function.api.upgrade.*
import com.mogo.eagle.core.utilcode.util.*
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.UpgradeDbHelper
@@ -14,6 +16,8 @@ import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.InstallRecor
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecord.Type
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecord.Type.FULL
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecord.Type.PATCH
import com.zhjt.service.chain.*
import com.zhjt.service.chain.TracingConstants.Endpoint
import java.util.TreeMap
@Route(path = MogoServicePaths.PATH_UPGRADE_TYPE_API)
@@ -22,79 +26,192 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
override fun init(context: Context?) {}
override suspend fun recordUpgradeRecord(sn: String, mac: String, type: String?) {
UpgradeDbHelper.insertRecord(Record(AppUtils.getAppVersionName(), sn, mac, type, time = System.currentTimeMillis()))
val record = Record(AppUtils.getAppVersionName(), sn, mac, type, time = System.currentTimeMillis())
UpgradeDbHelper.insertRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordUpgradeRequestStart() {
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), START, time = System.currentTimeMillis()))
val record = CheckRecord(AppUtils.getAppVersionName(), START, time = System.currentTimeMillis())
UpgradeDbHelper.insertCheckRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_request_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordUpgradeRequestSuccess(response: String) {
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), SUCCESS, response, time = System.currentTimeMillis()))
val record = CheckRecord(AppUtils.getAppVersionName(), SUCCESS, response, time = System.currentTimeMillis())
UpgradeDbHelper.insertCheckRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_request_success" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordUpgradeRequestFailed(error: String) {
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), FAIL, error, time = System.currentTimeMillis()))
try {
onUpgradeRecordLinkLog(mapOf("upgrade_request_failed" to error))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordUpgradeRecord(newVersionName: String, newMd5: String?, type: Int) {
UpgradeDbHelper.insertUpgradeRecord(UpgradeRecord(fromVersionName = AppUtils.getAppVersionName(), toVersionName = newVersionName, fromMd5 = AppUtils.getAppApkMd5(), toMD5 = newMd5, type = getType(type), time = System.currentTimeMillis()))
val record = UpgradeRecord(fromVersionName = AppUtils.getAppVersionName(), toVersionName = newVersionName, fromMd5 = AppUtils.getAppApkMd5(), toMD5 = newMd5, type = getType(type), time = System.currentTimeMillis())
UpgradeDbHelper.insertUpgradeRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_record" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordDownloadStart(downloadUrl: String) {
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadStart, downloadUrl = downloadUrl, time = System.currentTimeMillis()))
val record = DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadStart, downloadUrl = downloadUrl, time = System.currentTimeMillis())
UpgradeDbHelper.insertDownloadRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_download_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordDownloadFailed(downloadUrl: String, error: String) {
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadFailed, failReason = error, downloadUrl = downloadUrl, time = System.currentTimeMillis()))
val record = DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadFailed, failReason = error, downloadUrl = downloadUrl, time = System.currentTimeMillis())
UpgradeDbHelper.insertDownloadRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_download_failed" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordDownloadSuccess(downloadUrl: String) {
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadComplete, downloadUrl = downloadUrl, time = System.currentTimeMillis()))
val record = DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadComplete, downloadUrl = downloadUrl, time = System.currentTimeMillis())
UpgradeDbHelper.insertDownloadRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_download_success" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordInstallStart() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStart, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStart, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_install_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordSourceMd5CheckStart() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckStart, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckStart, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_source_md5_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordSourceMd5CheckFailed(error: String) {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckFailed, failReason = error, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckFailed, failReason = error, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_source_md5_failed" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordSourceMd5CheckSuccess() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckSuccess, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckSuccess, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_source_md5_success" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordInstallApplyPatchStart() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchStart, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchStart, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_apply_patch_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordInstallApplyPatchFailed(error: String) {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchFailed, failReason = error, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchFailed, failReason = error, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_apply_patch_failed" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordInstallApplyPatchSuccess() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchSuccess, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchSuccess, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_apply_patch_success" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordTargetMd5CheckStart() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckStart, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckStart, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_target_md5_start" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordTargetMd5CheckFailed(error: String) {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckFailed, failReason = error, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckFailed, failReason = error, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_target_md5_failed" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordTargetMd5CheckSuccess() {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckSuccess, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckSuccess, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_check_target_md5_success" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun recordInstallFailed(code: Int, error: String) {
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallFailed, code = code, failReason = error, time = System.currentTimeMillis()))
val record = InstallRecord(version = AppUtils.getAppVersionName(), status = InstallFailed, code = code, failReason = error, time = System.currentTimeMillis())
UpgradeDbHelper.insertInstallRecord(record)
try {
onUpgradeRecordLinkLog(mapOf("upgrade_install_failed" to GsonUtils.toJson(record)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
override suspend fun getUpgradeRecords(): Map<String, List<Pair<String, String>>>? {
@@ -118,6 +235,11 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
itx["step_2"] = all.upgrades?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
itx["step_3"] = all.downloads?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
itx["step_4"] = all.installs?.let { ArrayList<InstallRecord>(it) + InstallRecord(success.versionName, InstallSuccess, 0) }?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
try {
onUpgradeRecordLinkLog(mapOf("upgrade_success" to GsonUtils.toJson(all)))
} catch (t: Throwable) {
t.printStackTrace()
}
return@also
}
}
@@ -129,6 +251,11 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
itx["step_2"] = all.upgrades?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
itx["step_3"] = all.downloads?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
itx["step_4"] = all.installs?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
try {
onUpgradeRecordLinkLog(mapOf("upgrade_failed" to GsonUtils.toJson(all)))
} catch (t: Throwable) {
t.printStackTrace()
}
}
}
}
@@ -153,4 +280,15 @@ class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
}
private fun getType(type: Int): Type = if (type == 0) FULL else PATCH
@ChainLog(
linkChainLog = ChainConstant.CHAIN_LINK_LOG_CONNECT_STATUS,
linkCode = ChainConstant.CHAIN_LINK_CLOUD,
endpoint = Endpoint.PAD,
nodeAliasCode = ChainConstant.CHAIN_ALIAS_CODE_CLOUD_PASSPORT_TOKEN,
paramIndexes = [0],
clientPkFileName = "sn"
)
private fun onUpgradeRecordLinkLog(extra: Map<String, String>) {}
}