[2.15.0][增量升级] 优化升级状态记录,方便查看升级状态
This commit is contained in:
@@ -174,7 +174,7 @@ class BindingCarManager : IMoGoAutopilotCarConfigListener {
|
||||
fun queryObuUpgrade(obuVersionName: String) {
|
||||
if (screenType == 1) {
|
||||
CallerLogger.d("${SceneConstant.M_OBU}${MogoObuConst.TAG_UPGRADE_OBU}","queryObuUpgrade isConnected = ${CallerObuApiManager.isConnected()} --- mAddress = $mAddress")
|
||||
ObuUpgradeAppNetWorkManager.getInstance().getObuUpgradeInfo(mContext, mAddress, obuVersionName)
|
||||
ObuUpgradeAppNetWorkManager.instance?.getObuUpgradeInfo(mContext, mAddress, obuVersionName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package com.zhjt.mogo_core_function_devatools.upgrade;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BINDING;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.commons.constants.HostConst;
|
||||
import com.mogo.eagle.core.data.deva.bindingcar.UpgradeAppInfo;
|
||||
import com.mogo.eagle.core.function.api.devatools.download.DownloadType;
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
|
||||
import com.mogo.eagle.core.function.call.obu.CallerObuApiManager;
|
||||
import com.mogo.eagle.core.network.MoGoRetrofitFactory;
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 获取obu升级信息
|
||||
* @since: 3/25/22
|
||||
*/
|
||||
public class ObuUpgradeAppNetWorkManager {
|
||||
private static volatile ObuUpgradeAppNetWorkManager requestNoticeManager;
|
||||
private final UpgradeApiService mUpgradeApiService;
|
||||
private static final String TAG = "ObuUpgrade";
|
||||
|
||||
private ObuUpgradeAppNetWorkManager() {
|
||||
mUpgradeApiService = MoGoRetrofitFactory.getInstance(HostConst.getHost())
|
||||
.create(UpgradeApiService.class);
|
||||
}
|
||||
|
||||
public static ObuUpgradeAppNetWorkManager getInstance() {
|
||||
if (requestNoticeManager == null) {
|
||||
synchronized (ObuUpgradeAppNetWorkManager.class) {
|
||||
if (requestNoticeManager == null) {
|
||||
requestNoticeManager = new ObuUpgradeAppNetWorkManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return requestNoticeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取obu升级信息,obu升级服务端使用app升级接口,根据screenType区分类型
|
||||
* mac :工控机mac地址,
|
||||
* screenType : 类型
|
||||
*/
|
||||
public void getObuUpgradeInfo(Context context, String mac, String versionName) {
|
||||
// String sn = "X20202203105S688HZ";
|
||||
// String mac1 = "48:b0:2d:4d:33:40";
|
||||
|
||||
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
|
||||
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo mac = " + mac + " ---sn = " + sn + " ---versionName = " + versionName);
|
||||
UpgradeAppRequest request = new UpgradeAppRequest(sn, mac, "7", null, "0");
|
||||
RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request));
|
||||
mUpgradeApiService.getUpgradeInfo(requestBody)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<UpgradeAppInfo>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull UpgradeAppInfo info) {
|
||||
if (info != null && info.result != null) {
|
||||
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo appFileName = " + info.result.getAppFileName() + " ----url = " + info.result.getAppUrl() + " ----name = " + info.result.getVersionName() + " --obuVersionName =" + versionName + " ---info.result = " + info.result);
|
||||
if (!String.valueOf(info.result.getVersionName()).equals(versionName)) { //判断是否下载,当文件名称不一致的时候,就下载
|
||||
CallerDevaToolsManager.INSTANCE.downLoadPackage(DownloadType.OBU, info.result.getAppFileName(), info.result.getAppUrl());
|
||||
}
|
||||
} else {
|
||||
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo onNext info == null");
|
||||
CallerObuApiManager.INSTANCE.deleteObuFile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
CallerLogger.INSTANCE.e(M_BINDING + TAG, "getObuUpgradeInfo e = " + e);
|
||||
//请求出错,需要删除相关文件
|
||||
CallerObuApiManager.INSTANCE.deleteObuFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.zhjt.mogo_core_function_devatools.upgrade
|
||||
|
||||
import android.content.*
|
||||
import com.mogo.cloud.passport.*
|
||||
import com.mogo.commons.constants.*
|
||||
import com.mogo.eagle.core.data.deva.bindingcar.*
|
||||
import com.mogo.eagle.core.function.api.devatools.download.DownloadType.OBU
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager.downLoadPackage
|
||||
import com.mogo.eagle.core.function.call.obu.CallerObuApiManager.deleteObuFile
|
||||
import com.mogo.eagle.core.network.*
|
||||
import com.mogo.eagle.core.network.utils.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.*
|
||||
import io.reactivex.*
|
||||
import io.reactivex.android.schedulers.*
|
||||
import io.reactivex.disposables.*
|
||||
import io.reactivex.schedulers.*
|
||||
import kotlinx.coroutines.*
|
||||
import okhttp3.*
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 获取obu升级信息
|
||||
* @since: 3/25/22
|
||||
*/
|
||||
class ObuUpgradeAppNetWorkManager private constructor() {
|
||||
|
||||
private val mUpgradeApiService: UpgradeApiService by lazy {
|
||||
MoGoRetrofitFactory.getInstance(HostConst.getHost()).create(UpgradeApiService::class.java)
|
||||
}
|
||||
|
||||
private val scope by lazy { CoroutineScope(Dispatchers.IO + SupervisorJob()) }
|
||||
|
||||
|
||||
/**
|
||||
* 获取obu升级信息,obu升级服务端使用app升级接口,根据screenType区分类型
|
||||
* mac :工控机mac地址,
|
||||
* screenType : 类型
|
||||
*/
|
||||
fun getObuUpgradeInfo(context: Context?, mac: String?, versionName: String) { // String sn = "X20202203105S688HZ";
|
||||
// String mac1 = "48:b0:2d:4d:33:40";
|
||||
scope.launch {
|
||||
try {
|
||||
val sn = MoGoAiCloudClientConfig.getInstance().sn
|
||||
d(SceneConstant.M_BINDING + TAG, "getObuUpgradeInfo mac = $mac ---sn = $sn ---versionName = $versionName")
|
||||
val request = UpgradeAppRequest(sn, mac, "7", null, "0")
|
||||
val requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request))
|
||||
val info = mUpgradeApiService.getUpgradeInfo(requestBody)
|
||||
if (info.result == null) {
|
||||
d(SceneConstant.M_BINDING + TAG, "getObuUpgradeInfo onNext info == null")
|
||||
deleteObuFile()
|
||||
} else {
|
||||
d(SceneConstant.M_BINDING + TAG, "getObuUpgradeInfo appFileName = " + info.result.appFileName + " ----url = " + info.result.appUrl + " ----name = " + info.result.versionName + " --obuVersionName =" + versionName + " ---info.result = " + info.result)
|
||||
if (info.result.versionName.toString() != versionName) { //判断是否下载,当文件名称不一致的时候,就下载
|
||||
downLoadPackage(OBU, info.result.appFileName, info.result.appUrl)
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
e(SceneConstant.M_BINDING + TAG, "getObuUpgradeInfo e = $t") //请求出错,需要删除相关文件
|
||||
deleteObuFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile private var requestNoticeManager: ObuUpgradeAppNetWorkManager? = null
|
||||
private const val TAG = "ObuUpgrade"
|
||||
val instance: ObuUpgradeAppNetWorkManager?
|
||||
get() {
|
||||
if (requestNoticeManager == null) {
|
||||
synchronized(ObuUpgradeAppNetWorkManager::class.java) {
|
||||
if (requestNoticeManager == null) {
|
||||
requestNoticeManager = ObuUpgradeAppNetWorkManager()
|
||||
}
|
||||
}
|
||||
}
|
||||
return requestNoticeManager
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.zhjt.mogo_core_function_devatools.upgrade;
|
||||
|
||||
import com.mogo.eagle.core.data.deva.bindingcar.UpgradeAppInfo;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 升级
|
||||
* @since: 6/20/22
|
||||
*/
|
||||
public interface UpgradeApiService {
|
||||
/**
|
||||
* 获取升级信息
|
||||
* , @Query("resources") String i
|
||||
* @return {@link UpgradeAppInfo}
|
||||
*/
|
||||
@Headers("Content-Type:application/json;charset=UTF-8")
|
||||
@POST("eagleEye-mis/config/versionInfo")
|
||||
// Observable<UpgradeAppInfo> getUpgradeInfo(@Query("resources") String res, @Body RequestBody requestBody);
|
||||
Observable<UpgradeAppInfo> getUpgradeInfo(@Body RequestBody requestBody);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.zhjt.mogo_core_function_devatools.upgrade
|
||||
|
||||
import com.mogo.eagle.core.data.deva.bindingcar.*
|
||||
import io.reactivex.*
|
||||
import okhttp3.*
|
||||
import retrofit2.http.*
|
||||
import retrofit2.http.Headers
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 升级
|
||||
* @since: 6/20/22
|
||||
*/
|
||||
interface UpgradeApiService {
|
||||
/**
|
||||
* 获取升级信息
|
||||
* , @Query("resources") String i
|
||||
* @return [UpgradeAppInfo]
|
||||
*/
|
||||
@Headers("Content-Type:application/json;charset=UTF-8")
|
||||
@POST("eagleEye-mis/config/versionInfo")
|
||||
suspend fun getUpgradeInfo(@Body requestBody: RequestBody): UpgradeAppInfo
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.zhjt.mogo_core_function_devatools.upgrade
|
||||
|
||||
import android.content.*
|
||||
import android.text.*
|
||||
import android.util.*
|
||||
import com.elegant.utils.UiThreadHandler
|
||||
import com.mogo.cloud.passport.*
|
||||
@@ -14,16 +13,11 @@ 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.*
|
||||
import com.mogo.eagle.core.utilcode.breakpoint.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.util.*
|
||||
import com.mogo.eagle.core.utilcode.util.FileUtils
|
||||
import io.reactivex.*
|
||||
import io.reactivex.android.schedulers.*
|
||||
import io.reactivex.disposables.*
|
||||
import io.reactivex.schedulers.*
|
||||
import kotlinx.coroutines.*
|
||||
import okhttp3.*
|
||||
|
||||
@@ -38,86 +32,94 @@ class UpgradeAppNetWorkManager private constructor() {
|
||||
|
||||
private val scope by lazy { CoroutineScope(Dispatchers.IO + SupervisorJob()) }
|
||||
|
||||
private val provider by lazy { upgradeProvider() }
|
||||
|
||||
/**
|
||||
* 获取app升级信息
|
||||
*/
|
||||
fun getAppUpgradeInfo(context: Context?, mac: String, screenType: String) { // String sn = "X20202203105S688HZ";
|
||||
// String mac = "48:b0:2d:3a:bc:78";
|
||||
val sn = MoGoAiCloudClientConfig.getInstance().sn
|
||||
val versionCode = AppUtils.getAppVersionCode()
|
||||
val versionName = AppUtils.getAppVersionName()
|
||||
d(SceneConstant.M_BINDING + TAG, "getAppUpgradeInfo mac = $mac---type = $screenType---sn = $sn---versionCode =$versionCode---versionName =$versionName")
|
||||
val request = UpgradeAppRequest(sn, mac, screenType, versionName, "1")
|
||||
val requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request))
|
||||
mUpgradeApiService.getUpgradeInfo(requestBody).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<UpgradeAppInfo> {
|
||||
override fun onSubscribe(d: Disposable) {}
|
||||
override fun onNext(info: UpgradeAppInfo) {
|
||||
doUpgrade(info)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
deleteApkFile()
|
||||
}
|
||||
|
||||
override fun onComplete() {}
|
||||
})
|
||||
}
|
||||
|
||||
private fun doUpgrade(info: UpgradeAppInfo) {
|
||||
scope.launch {
|
||||
if (info.result != null) {
|
||||
val sn = MoGoAiCloudClientConfig.getInstance().sn //null
|
||||
val macAddress = mac //"48:b0:2d:4d:31:7f"
|
||||
val type = screenType //10
|
||||
try {
|
||||
val records = provider?.getUpgradeRecords()
|
||||
Log.d(TAG, "getAppUpgradeInfo: -> records:" + records?.entries?.joinToString(",") { itx -> "key:${itx.key} -> value:[${itx.value.joinToString(",") { "${it.first},${it.second}" } }]"})
|
||||
val versionCode = AppUtils.getAppVersionCode()
|
||||
d(SceneConstant.M_BINDING + TAG, "UpgradeAppInfo url = " + info.result.appUrl + "----code = " + info.result.versionCode + "--versionCode =" + versionCode + "--info.result = " + info.result)
|
||||
if (info.result.versionCode > versionCode) {
|
||||
val patchInfo = info.result.patchInfo
|
||||
var downloadUrl: String = info.result.appUrl
|
||||
val provider = upgradeProvider()
|
||||
if (patchInfo != null) {
|
||||
val f1 = FunctionBuildConfig.isSupportPatchUpgrade
|
||||
if (!f1) {
|
||||
Log.d("ApkInstaller", "当前版本配置不支持增量升级...")
|
||||
}
|
||||
val f2 = provider != null
|
||||
if (f1 && !f2) {
|
||||
Log.d("ApkInstaller", "provider为空...")
|
||||
}
|
||||
var f3 = true
|
||||
if (f2 && provider != null && !provider.isNeedGoPatchUpgrade()) {
|
||||
Log.d("ApkInstaller", "上次patch升级失败了...")
|
||||
f3 = false
|
||||
}
|
||||
var f4 = true
|
||||
if (f3) {
|
||||
provider?.recordUpgradeRecord(patchInfo.targetVersion, patchInfo.targetMd5, 1)
|
||||
provider?.recordSourceMd5CheckStart()
|
||||
f4 = isPatchAccept(Utils.getApp(), patchInfo.sourceMd5, patchInfo.patchSize.toLong())
|
||||
if (!f4) {
|
||||
Log.d("ApkInstaller", "旧版本apk包的md5与服务端上的md5不匹配...")
|
||||
provider?.recordSourceMd5CheckFailed("旧apk的md5与服务端的md5不一致:[server_md5: ${patchInfo.sourceMd5}, apk_md5: ${AppUtils.getAppApkMd5()}]")
|
||||
} else {
|
||||
provider?.recordSourceMd5CheckSuccess()
|
||||
}
|
||||
}
|
||||
if (f4) {
|
||||
downloadUrl = patchInfo.patchDownloadUrl
|
||||
addPatchInfo(patchInfo)
|
||||
}
|
||||
} else {
|
||||
provider?.recordUpgradeRecord(info.result.versionName, null, 0)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
showUpgradeDialog(downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1), downloadUrl, info.result.installTitle, info.result.installContent, info.result.installType)
|
||||
}
|
||||
val versionName = AppUtils.getAppVersionName()
|
||||
d(SceneConstant.M_BINDING + TAG, "getAppUpgradeInfo mac = $macAddress---type = $type---sn = $sn---versionCode =$versionCode---versionName =$versionName")
|
||||
val request = UpgradeAppRequest(sn, macAddress, type, versionName, "1")
|
||||
val requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request))
|
||||
provider?.recordUpgradeRecord(sn ?: "", macAddress, type)
|
||||
provider?.recordUpgradeRequestStart()
|
||||
val info = mUpgradeApiService.getUpgradeInfo(requestBody)
|
||||
if (info.result != null) {
|
||||
provider?.recordUpgradeRequestSuccess(GsonUtils.toJson(info))
|
||||
doUpgrade(info)
|
||||
} else {
|
||||
deleteApkFile()
|
||||
provider?.recordUpgradeRequestFailed(GsonUtils.toJson(info))
|
||||
}
|
||||
} else {
|
||||
d(SceneConstant.M_BINDING + TAG, "UpgradeAppInfo onNext info == null")
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
provider?.recordUpgradeRequestFailed(t.message ?: "更新接口请求失败")
|
||||
deleteApkFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun doUpgrade(info: UpgradeAppInfo) {
|
||||
if (info.result != null) {
|
||||
val versionCode = AppUtils.getAppVersionCode()
|
||||
d(SceneConstant.M_BINDING + TAG, "UpgradeAppInfo url = " + info.result.appUrl + "----code = " + info.result.versionCode + "--versionCode =" + versionCode + "--info.result = " + info.result)
|
||||
if (info.result.versionCode > versionCode) {
|
||||
val patchInfo = info.result.patchInfo
|
||||
var downloadUrl: String = info.result.appUrl
|
||||
val provider = upgradeProvider()
|
||||
if (patchInfo != null) {
|
||||
val f1 = FunctionBuildConfig.isSupportPatchUpgrade
|
||||
if (!f1) {
|
||||
Log.d("ApkInstaller", "当前版本配置不支持增量升级...")
|
||||
}
|
||||
val f2 = provider != null
|
||||
if (f1 && !f2) {
|
||||
Log.d("ApkInstaller", "provider为空...")
|
||||
}
|
||||
var f3 = true
|
||||
if (f2 && provider != null && !provider.isNeedGoPatchUpgrade()) {
|
||||
Log.d("ApkInstaller", "上次patch升级失败了...")
|
||||
f3 = false
|
||||
}
|
||||
var f4 = true
|
||||
if (f3) {
|
||||
provider?.recordUpgradeRecord(patchInfo.targetVersion, patchInfo.targetMd5, 1)
|
||||
provider?.recordSourceMd5CheckStart()
|
||||
f4 = isPatchAccept(Utils.getApp(), patchInfo.sourceMd5, patchInfo.patchSize.toLong())
|
||||
if (!f4) {
|
||||
Log.d("ApkInstaller", "旧版本apk包的md5与服务端上的md5不匹配...")
|
||||
provider?.recordSourceMd5CheckFailed("旧apk的md5与服务端的md5不一致:[server_md5: ${patchInfo.sourceMd5}, apk_md5: ${AppUtils.getAppApkMd5()}]")
|
||||
} else {
|
||||
provider?.recordSourceMd5CheckSuccess()
|
||||
}
|
||||
}
|
||||
if (f4) {
|
||||
downloadUrl = patchInfo.patchDownloadUrl
|
||||
addPatchInfo(patchInfo)
|
||||
}
|
||||
} else {
|
||||
provider?.recordUpgradeRecord(info.result.versionName, null, 0)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
showUpgradeDialog(downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1), downloadUrl, info.result.installTitle, info.result.installContent, info.result.installType)
|
||||
}
|
||||
} else {
|
||||
deleteApkFile()
|
||||
}
|
||||
} else {
|
||||
d(SceneConstant.M_BINDING + TAG, "UpgradeAppInfo onNext info == null")
|
||||
deleteApkFile()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除APK 相关的文件
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.pm.PackageInstaller
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.eagle.core.function.api.upgrade.IMoGoUpgradeProvider
|
||||
import com.mogo.eagle.core.function.call.base.CallerBase
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.elegant.utils.UiThreadHandler
|
||||
import com.mogo.eagle.core.data.obu.MogoObuConst
|
||||
import com.mogo.eagle.core.function.api.devatools.IMogoDevaToolsUpgradeListener
|
||||
@@ -78,7 +77,7 @@ class UpgradeManager : IDownload {
|
||||
val type = types[downloadUrl]
|
||||
if (type == PATCH || type == APK) {
|
||||
runBlocking {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadStart()
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadStart(downloadUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +113,9 @@ class UpgradeManager : IDownload {
|
||||
if (downloadUrl != null) {
|
||||
val type = types[downloadUrl]
|
||||
if (type == APK || type == PATCH) {
|
||||
runBlocking {
|
||||
upgradeProvider?.recordDownloadSuccess(downloadUrl)
|
||||
}
|
||||
val patchInfo = CallerPatchManager.getPatchInfoByUrl(downloadUrl)
|
||||
if (patchInfo != null) {
|
||||
var isPatchInstallFailed = false
|
||||
@@ -201,7 +203,7 @@ class UpgradeManager : IDownload {
|
||||
|
||||
if (isPatchInstallFailed) {
|
||||
runBlocking {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordInstallFailed(ApkInstaller.INSTALL_CODE_INVLID, patchInstallFailedReason)
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordInstallFailed(ApkInstaller.INSTALL_CODE_INVALID, patchInstallFailedReason)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -247,7 +249,7 @@ class UpgradeManager : IDownload {
|
||||
val type = types[downloadUrl]
|
||||
if (type == APK || type == PATCH) {
|
||||
runBlocking {
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadFailed(errorMsg ?: "下载失败")
|
||||
CallerDevaToolsManager.upgradeProvider()?.recordDownloadFailed(downloadUrl,errorMsg ?: "下载失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,178 +8,164 @@ 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
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.*
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.CheckRecord.Status.*
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.DownloadRecord.Status.*
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.InstallRecord.Status.*
|
||||
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 java.util.TreeMap
|
||||
|
||||
@Route(path = MogoServicePaths.PATH_UPGRADE_TYPE_API)
|
||||
class MoGoUpgradeProviderImpl: IMoGoUpgradeProvider {
|
||||
|
||||
override fun init(context: Context?) {}
|
||||
|
||||
override suspend fun recordUpgradeRecord(newVersion: String, newMd5: String?, type: Int) {
|
||||
UpgradeDbHelper.insertUpgradeRecord(UpgradeRecord(AppUtils.getAppVersionName(), newVersion, AppUtils.getAppApkMd5(), newMd5, if (type == 0) UpgradeType.FULL else UpgradeType.PATCH))
|
||||
override suspend fun recordUpgradeRecord(sn: String, mac: String, type: String?) {
|
||||
UpgradeDbHelper.insertRecord(Record(AppUtils.getAppVersionName(), sn, mac, type))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadStart() {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(version = AppUtils.getAppVersionName(), status = DownloadStatus.DownloadStart))
|
||||
override suspend fun recordUpgradeRequestStart() {
|
||||
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), START))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadFailed(error: String) {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(version = AppUtils.getAppVersionName(), status = DownloadStatus.DownloadFailed, failReason = error))
|
||||
override suspend fun recordUpgradeRequestSuccess(response: String) {
|
||||
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), SUCCESS, response))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadSuccess() {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(version = AppUtils.getAppVersionName(), status = DownloadStatus.DownloadComplete))
|
||||
override suspend fun recordUpgradeRequestFailed(error: String) {
|
||||
UpgradeDbHelper.insertCheckRecord(CheckRecord(AppUtils.getAppVersionName(), FAIL, error))
|
||||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadStart(downloadUrl: String) {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadStart, downloadUrl = downloadUrl))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadFailed(downloadUrl: String, error: String) {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadFailed, failReason = error, downloadUrl = downloadUrl))
|
||||
}
|
||||
|
||||
override suspend fun recordDownloadSuccess(downloadUrl: String) {
|
||||
UpgradeDbHelper.insertDownloadRecord(DownloadRecord(versionName = AppUtils.getAppVersionName(), status = DownloadComplete, downloadUrl = downloadUrl))
|
||||
}
|
||||
|
||||
override suspend fun recordInstallStart() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.InstallStart))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStart))
|
||||
}
|
||||
|
||||
override suspend fun recordSourceMd5CheckStart() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.SourceMd5CheckStart))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckStart))
|
||||
}
|
||||
|
||||
override suspend fun recordSourceMd5CheckFailed(error: String) {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.SourceMd5CheckFailed, failReason = error))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckFailed, failReason = error))
|
||||
}
|
||||
|
||||
override suspend fun recordSourceMd5CheckSuccess() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.SourceMd5CheckSuccess))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = SourceMd5CheckSuccess))
|
||||
}
|
||||
|
||||
override suspend fun recordInstallApplyPatchStart() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.ApplyPatchStart))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchStart))
|
||||
}
|
||||
|
||||
override suspend fun recordInstallApplyPatchFailed(error: String) {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.ApplyPatchFailed, failReason = error))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchFailed, failReason = error))
|
||||
}
|
||||
|
||||
override suspend fun recordInstallApplyPatchSuccess() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.ApplyPatchSuccess))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = ApplyPatchSuccess))
|
||||
}
|
||||
|
||||
override suspend fun recordTargetMd5CheckStart() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.TargetMd5CheckStart))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckStart))
|
||||
}
|
||||
|
||||
override suspend fun recordTargetMd5CheckFailed(error: String) {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.TargetMd5CheckFailed, failReason = error))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckFailed, failReason = error))
|
||||
}
|
||||
|
||||
override suspend fun recordTargetMd5CheckSuccess() {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.TargetMd5CheckSuccess))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = TargetMd5CheckSuccess))
|
||||
}
|
||||
|
||||
override suspend fun recordInstallFailed(code: Int, error: String) {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallStatus.InstallFailed, code = code, failReason = error))
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(version = AppUtils.getAppVersionName(), status = InstallFailed, code = code, failReason = error))
|
||||
}
|
||||
|
||||
override suspend fun isUpgradeSuccessByPatch(): Boolean {
|
||||
val record = UpgradeDbHelper.getUpgradeRecordOnlyByTarget(AppUtils.getAppVersionName())
|
||||
return record?.toVersion == AppUtils.getAppVersionName() && record.type == UpgradeType.PATCH
|
||||
override suspend fun isUpgradeSuccess(type: Int): Boolean {
|
||||
val currentVersion = AppUtils.getAppVersionName()
|
||||
val record = UpgradeDbHelper.getUpgradeRecordFull(currentVersion)
|
||||
val toType = if (type == 0) FULL else PATCH
|
||||
if (record != null) {
|
||||
return (record.upgrades?.find { it.type == toType } != null) && (record.installs?.find { it.status == InstallSuccess } != null)
|
||||
}
|
||||
val records = UpgradeDbHelper.getAllRecords()
|
||||
if (records.isEmpty()) {
|
||||
return false
|
||||
}
|
||||
records.forEach { r ->
|
||||
val oldVersion = r.versionName
|
||||
val q = UpgradeDbHelper.getUpgradeRecordFull(oldVersion)
|
||||
val f = q?.upgrades?.find { it.toVersionName == currentVersion && it.type == toType }
|
||||
if (f != null) {
|
||||
val install = q.installs?.find { it.status == InstallSuccess }
|
||||
if (install == null) {
|
||||
UpgradeDbHelper.insertInstallRecord(InstallRecord(oldVersion, InstallSuccess, 0))
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override suspend fun isUpgradeSuccessByFull(): Boolean {
|
||||
val record = UpgradeDbHelper.getUpgradeRecordOnlyByTarget(AppUtils.getAppVersionName())
|
||||
return record?.toVersion == AppUtils.getAppVersionName() && record.type == UpgradeType.FULL
|
||||
}
|
||||
|
||||
override suspend fun removeRecordByTargetVersion(version: String) {
|
||||
UpgradeDbHelper.deleteRecordByTargetVersion(version)
|
||||
}
|
||||
|
||||
override suspend fun removeRecordBySourceVersion(version: String) {
|
||||
UpgradeDbHelper.deleteRecordBySourceVersion(version)
|
||||
}
|
||||
|
||||
override suspend fun getFullUpgradeFailedReason(): Map<String,List<Pair<Int, String>>>? {
|
||||
if (isUpgradeSuccessByFull()) {
|
||||
override suspend fun getUpgradeRecords(): Map<String, List<Pair<String, String>>>? {
|
||||
val currentVersion = AppUtils.getAppVersionName()
|
||||
val records = UpgradeDbHelper.getAllRecords()
|
||||
if (records.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
if (isUpgradeSuccessByPatch()) {
|
||||
return null
|
||||
val success = records.find { itx -> itx.versionName != currentVersion && (UpgradeDbHelper.getUpgradeRecordFull(itx.versionName)?.upgrades?.find { it.toVersionName == currentVersion } != null) }
|
||||
val fail = records.find { it.versionName == currentVersion }
|
||||
return TreeMap<String, List<Pair<String, String>>>().also { itx ->
|
||||
if (success != null) {
|
||||
val all = UpgradeDbHelper.getUpgradeRecordFull(success.versionName)
|
||||
if (all != null) {
|
||||
itx["step_0"] = listOf("old" to (GsonUtils.toJson(all.record) ?: ""))
|
||||
itx["step_1"] = all.checks?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
|
||||
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()
|
||||
}
|
||||
}
|
||||
if (fail != null) {
|
||||
val all = UpgradeDbHelper.getUpgradeRecordFull(fail.versionName)
|
||||
if (all != null) {
|
||||
itx["step_0"] = listOf("old" to (GsonUtils.toJson(all.record) ?: ""))
|
||||
itx["step_1"] = all.checks?.sortedBy { it.status.ordinal }?.mapIndexed { index, r -> "$index" to GsonUtils.toJson(r) } ?: emptyList()
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
val full = UpgradeDbHelper.getUpgradeRecordFull(AppUtils.getAppVersionName())
|
||||
if (full == null || full.upgrade?.type != UpgradeType.FULL) {
|
||||
return null
|
||||
}
|
||||
val map = HashMap<String, List<Pair<Int, String>>>()
|
||||
full.downloads?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.sortedBy {
|
||||
it.status.ordinal
|
||||
}?.map {
|
||||
it.status.ordinal to (it.failReason ?: "")
|
||||
}?.also {
|
||||
map["download"] = it
|
||||
}
|
||||
full.installs?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.sortedBy {
|
||||
it.status.ordinal
|
||||
}?.map {
|
||||
it.status.ordinal to (it.failReason ?: "")
|
||||
}?.also {
|
||||
map["install"] = it
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
override suspend fun getPatchUpgradeFailedReason(): Map<String,List<Pair<Int, String>>>? {
|
||||
if (isUpgradeSuccessByFull()) {
|
||||
return null
|
||||
}
|
||||
if (isUpgradeSuccessByPatch()) {
|
||||
return null
|
||||
}
|
||||
val full = UpgradeDbHelper.getUpgradeRecordFull(AppUtils.getAppVersionName())
|
||||
if (full == null || full.upgrade?.type != UpgradeType.PATCH) {
|
||||
return null
|
||||
}
|
||||
val map = HashMap<String, List<Pair<Int, String>>>()
|
||||
full.downloads?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.sortedBy {
|
||||
it.status.ordinal
|
||||
}?.map {
|
||||
it.status.ordinal to (it.failReason ?: "")
|
||||
}?.also {
|
||||
map["download"] = it
|
||||
}
|
||||
full.installs?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.sortedBy {
|
||||
it.status.ordinal
|
||||
}?.map {
|
||||
it.status.ordinal to (it.failReason ?: "")
|
||||
}?.also {
|
||||
map["install"] = it
|
||||
}
|
||||
return map
|
||||
}
|
||||
override suspend fun hasUpgradeRecord(): Boolean {
|
||||
return UpgradeDbHelper.hasRecords()
|
||||
}
|
||||
|
||||
override suspend fun isNeedGoPatchUpgrade(): Boolean {
|
||||
val reasons = getPatchUpgradeFailedReason()
|
||||
return reasons?.let { itx ->
|
||||
itx["install"]?.takeIf {
|
||||
it.isNotEmpty()
|
||||
}?.let {
|
||||
val last = it.last()
|
||||
val ordinal = last.first
|
||||
val status = InstallStatus.values().find { v -> v.ordinal == ordinal }
|
||||
if (status != null && status.isReallyFailed()) {
|
||||
val code = UpgradeDbHelper.getUpgradeRecordFull(AppUtils.getAppVersionName())?.installs?.find { s -> s.status == status }?.code
|
||||
code != PackageInstaller.STATUS_FAILURE_INVALID &&
|
||||
code != PackageInstaller.STATUS_FAILURE_CONFLICT &&
|
||||
code != PackageInstaller.STATUS_FAILURE &&
|
||||
code != PackageInstaller.STATUS_FAILURE_STORAGE
|
||||
} else {
|
||||
true
|
||||
}
|
||||
} ?: true
|
||||
} ?: true
|
||||
val currentVersion = AppUtils.getAppVersionName()
|
||||
val record = UpgradeDbHelper.getUpgradeRecordFull(currentVersion) ?: return true
|
||||
val installs = record.installs ?: return true
|
||||
return installs.find {
|
||||
it.version == currentVersion && it.status != SourceMd5CheckFailed && it.status != ApplyPatchFailed && it.status != TargetMd5CheckFailed && it.status == InstallFailed && it.code != PackageInstaller.STATUS_FAILURE_INVALID && it.code != PackageInstaller.STATUS_FAILURE_CONFLICT && it.code != PackageInstaller.STATUS_FAILURE && it.code != PackageInstaller.STATUS_FAILURE_STORAGE
|
||||
} != null
|
||||
}
|
||||
|
||||
private fun getType(type: Int): Type = if (type == 0) FULL else PATCH
|
||||
}
|
||||
@@ -3,15 +3,15 @@ package com.zhjt.mogo_core_function_devatools.upgrade.provider.db
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.dao.IUpgradeRecordDao
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.DownloadRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.InstallRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.*
|
||||
|
||||
@Database(
|
||||
entities = [
|
||||
UpgradeRecord::class,
|
||||
DownloadRecord::class,
|
||||
InstallRecord::class],
|
||||
Record::class,
|
||||
CheckRecord::class,
|
||||
UpgradeRecord::class,
|
||||
DownloadRecord::class,
|
||||
InstallRecord::class],
|
||||
version = 1,
|
||||
exportSchema = false)
|
||||
internal abstract class UpgradeRecordDb: RoomDatabase() {
|
||||
|
||||
@@ -2,10 +2,7 @@ package com.zhjt.mogo_core_function_devatools.upgrade.provider.db
|
||||
|
||||
import androidx.room.Room
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.DownloadRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.InstallRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecord
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.UpgradeRecordFull
|
||||
import com.zhjt.mogo_core_function_devatools.upgrade.provider.db.vo.*
|
||||
|
||||
internal object UpgradeDbHelper {
|
||||
|
||||
@@ -13,6 +10,20 @@ internal object UpgradeDbHelper {
|
||||
Room.databaseBuilder(Utils.getApp(), UpgradeRecordDb::class.java, "upgrade_records").build()
|
||||
}
|
||||
|
||||
suspend fun insertRecord(record: Record): Long = try {
|
||||
db.dao().insertRecord(record)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
-1
|
||||
}
|
||||
|
||||
suspend fun insertCheckRecord(record: CheckRecord): Long = try {
|
||||
db.dao().insertCheckUpgradeRecord(record)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
-1
|
||||
}
|
||||
|
||||
suspend fun insertUpgradeRecord(record: UpgradeRecord): Long = try {
|
||||
db.dao().insertUpgradeRecord(record)
|
||||
} catch (e: Exception) {
|
||||
@@ -41,29 +52,23 @@ internal object UpgradeDbHelper {
|
||||
null
|
||||
}
|
||||
|
||||
suspend fun getUpgradeRecordOnlyByTarget(targetVersion: String): UpgradeRecord? = try {
|
||||
db.dao().getUpgradeRecordOnlyByTarget(targetVersion)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
|
||||
suspend fun deleteRecordBySourceVersion(version: String) = try {
|
||||
db.dao().deleteRecordBySourceVersion(version)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
suspend fun deleteRecordByTargetVersion(version: String) = try {
|
||||
db.dao().deleteRecordByTargetVersion(version)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
suspend fun hasRecords() = try {
|
||||
db.dao().getRecordCount() > 0
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
|
||||
suspend fun getAllRecords(): List<Record> = try {
|
||||
db.dao().getAllRecords()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
emptyList()
|
||||
}
|
||||
|
||||
suspend fun deleteRecord(versionName: String) = try {
|
||||
db.dao().deleteRecord(versionName)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,14 @@ internal interface IUpgradeRecordDao {
|
||||
|
||||
@Insert(onConflict = REPLACE)
|
||||
@Transaction
|
||||
suspend fun insertRecord(record: Record): Long
|
||||
|
||||
@Insert(onConflict = IGNORE)
|
||||
@Transaction
|
||||
suspend fun insertCheckUpgradeRecord(record: CheckRecord): Long
|
||||
|
||||
@Insert(onConflict = IGNORE)
|
||||
@Transaction
|
||||
suspend fun insertUpgradeRecord(record: UpgradeRecord): Long
|
||||
|
||||
@Insert(onConflict = IGNORE)
|
||||
@@ -23,22 +31,17 @@ internal interface IUpgradeRecordDao {
|
||||
@Transaction
|
||||
suspend fun insertInstallRecord(record: InstallRecord): Long
|
||||
|
||||
@Query("SELECT * FROM upgrade_record WHERE f_v = :oldVersion")
|
||||
@Query("SELECT * FROM records WHERE version_name = :versionName")
|
||||
@Transaction
|
||||
suspend fun getUpgradeRecordFull(oldVersion: String): UpgradeRecordFull?
|
||||
suspend fun getUpgradeRecordFull(versionName: String): UpgradeRecordFull?
|
||||
|
||||
@Query("SELECT * FROM upgrade_record WHERE f_v = :oldVersion")
|
||||
suspend fun getUpgradeRecordOnly(oldVersion: String): UpgradeRecord?
|
||||
|
||||
@Query("SELECT * FROM upgrade_record WHERE t_v = :toVersion")
|
||||
suspend fun getUpgradeRecordOnlyByTarget(toVersion: String): UpgradeRecord?
|
||||
|
||||
@Query("DELETE FROM upgrade_record WHERE f_v = :version")
|
||||
suspend fun deleteRecordBySourceVersion(version: String)
|
||||
|
||||
@Query("DELETE FROM upgrade_record WHERE t_v = :version")
|
||||
suspend fun deleteRecordByTargetVersion(version: String)
|
||||
|
||||
@Query("SELECT COUNT(*) FROM upgrade_record")
|
||||
@Query("SELECT COUNT(*) FROM records")
|
||||
suspend fun getRecordCount(): Int
|
||||
|
||||
@Query("DELETE FROM records WHERE version_name = :versionName")
|
||||
@Transaction
|
||||
suspend fun deleteRecord(versionName: String)
|
||||
|
||||
@Query("SELECT * FROM records")
|
||||
suspend fun getAllRecords(): List<Record>
|
||||
}
|
||||
@@ -4,184 +4,266 @@ import androidx.room.*
|
||||
import androidx.room.ForeignKey.CASCADE
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
|
||||
@Entity(tableName = "upgrade_record")
|
||||
data class UpgradeRecord(
|
||||
|
||||
@Entity(tableName = "records")
|
||||
data class Record(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "f_v")
|
||||
var fromVersion: String,
|
||||
|
||||
@ColumnInfo(name = "t_v")
|
||||
var toVersion: String,
|
||||
|
||||
@ColumnInfo(name = "f_m")
|
||||
var fromMD5: String?,
|
||||
|
||||
@ColumnInfo(name = "t_m")
|
||||
var toMD5: String?,
|
||||
|
||||
@field:TypeConverters(UpgradeType::class)
|
||||
var type: UpgradeType
|
||||
@ColumnInfo(name = "version_name")
|
||||
var versionName: String,
|
||||
var sn: String,
|
||||
var mac: String,
|
||||
var type: String?
|
||||
)
|
||||
|
||||
|
||||
enum class UpgradeType {
|
||||
FULL,
|
||||
PATCH;
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(type: UpgradeType?) = type?.ordinal
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Entity(
|
||||
tableName = "download_record",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = UpgradeRecord::class,
|
||||
parentColumns = arrayOf("f_v"),
|
||||
childColumns = arrayOf("d_v"),
|
||||
deferred = true,
|
||||
onDelete = CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = arrayOf("id"), unique = true),
|
||||
Index(value = arrayOf("d_v"))
|
||||
]
|
||||
)
|
||||
data class DownloadRecord(
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
|
||||
@ColumnInfo(name = "d_v")
|
||||
var version: String,
|
||||
|
||||
@field:TypeConverters(DownloadStatus::class)
|
||||
var status: DownloadStatus,
|
||||
|
||||
@ColumnInfo(name = "reason")
|
||||
var failReason: String? = null
|
||||
)
|
||||
|
||||
enum class DownloadStatus {
|
||||
|
||||
DownloadStart,
|
||||
|
||||
DownloadFailed,
|
||||
|
||||
DownloadComplete;
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(type: DownloadStatus?) = type?.ordinal
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(
|
||||
tableName = "install_record",
|
||||
foreignKeys = [ForeignKey(
|
||||
entity = UpgradeRecord::class,
|
||||
parentColumns = arrayOf("f_v"),
|
||||
childColumns = arrayOf("i_v"),
|
||||
@Entity(tableName = "check_upgrade_record",foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Record::class,
|
||||
parentColumns = arrayOf("version_name"),
|
||||
childColumns = arrayOf("from_version_name"),
|
||||
deferred = true,
|
||||
onDelete = CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = arrayOf("id"), unique = true),
|
||||
Index(value = arrayOf("i_v"))
|
||||
Index(value = arrayOf("from_version_name"))
|
||||
])
|
||||
data class CheckRecord(
|
||||
@ColumnInfo(name = "from_version_name")
|
||||
var versionName: String,
|
||||
|
||||
@field:TypeConverters(Status::class)
|
||||
var status: Status,
|
||||
|
||||
var message: String? = null,
|
||||
) {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0L
|
||||
|
||||
enum class Status {
|
||||
START,
|
||||
SUCCESS,
|
||||
FAIL;
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = Status.values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(type: Status?) = type?.ordinal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(tableName = "upgrade_record",foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Record::class,
|
||||
parentColumns = arrayOf("version_name"),
|
||||
childColumns = arrayOf("from_version_name"),
|
||||
deferred = true,
|
||||
onDelete = CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = arrayOf("id"), unique = true),
|
||||
Index(value = arrayOf("from_version_name"))
|
||||
])
|
||||
|
||||
data class UpgradeRecord(
|
||||
|
||||
@ColumnInfo(name = "from_version_name")
|
||||
var fromVersionName: String,
|
||||
|
||||
@ColumnInfo(name = "to_version_name")
|
||||
var toVersionName: String,
|
||||
|
||||
@ColumnInfo(name = "from_md5")
|
||||
var fromMd5: String?,
|
||||
|
||||
@ColumnInfo(name = "to_md5")
|
||||
var toMD5: String?,
|
||||
|
||||
@field:TypeConverters(Type::class)
|
||||
var type: Type
|
||||
) {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0L
|
||||
|
||||
enum class Type {
|
||||
FULL,
|
||||
PATCH;
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(type: Type?) = type?.ordinal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(
|
||||
tableName = "download_record",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Record::class,
|
||||
parentColumns = arrayOf("version_name"),
|
||||
childColumns = arrayOf("from_version_name"),
|
||||
deferred = true,
|
||||
onDelete = CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = arrayOf("id"), unique = true),
|
||||
Index(value = arrayOf("from_version_name"))
|
||||
]
|
||||
)
|
||||
data class DownloadRecord(
|
||||
|
||||
@ColumnInfo(name = "from_version_name")
|
||||
var versionName: String,
|
||||
|
||||
@ColumnInfo(name = "download_url")
|
||||
var downloadUrl: String,
|
||||
|
||||
@field:TypeConverters(Status::class)
|
||||
var status: Status,
|
||||
|
||||
@ColumnInfo(name = "reason")
|
||||
var failReason: String? = null
|
||||
) {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0
|
||||
|
||||
enum class Status {
|
||||
|
||||
DownloadStart,
|
||||
|
||||
DownloadFailed,
|
||||
|
||||
DownloadComplete;
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(type: Status?) = type?.ordinal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Entity(
|
||||
tableName = "install_record",
|
||||
foreignKeys = [ForeignKey(
|
||||
entity = Record::class,
|
||||
parentColumns = arrayOf("version_name"),
|
||||
childColumns = arrayOf("from_version_name"),
|
||||
deferred = true,
|
||||
onDelete = CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = arrayOf("id"), unique = true),
|
||||
Index(value = arrayOf("from_version_name"))
|
||||
]
|
||||
)
|
||||
data class InstallRecord(
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
|
||||
@ColumnInfo(name = "i_v")
|
||||
@ColumnInfo(name = "from_version_name")
|
||||
var version: String,
|
||||
|
||||
@field:TypeConverters(InstallStatus::class)
|
||||
var status: InstallStatus,
|
||||
@field:TypeConverters(Status::class)
|
||||
var status: Status,
|
||||
|
||||
@ColumnInfo(defaultValue = "${ApkInstaller.INSTALL_CODE_INVLID}")
|
||||
@ColumnInfo(defaultValue = "${ApkInstaller.INSTALL_CODE_INVALID}")
|
||||
var code: Int = 0,
|
||||
|
||||
@ColumnInfo(name = "reason")
|
||||
var failReason: String? = null
|
||||
)
|
||||
) {
|
||||
|
||||
enum class InstallStatus {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0
|
||||
|
||||
SourceMd5CheckStart,
|
||||
enum class Status {
|
||||
|
||||
SourceMd5CheckFailed,
|
||||
SourceMd5CheckStart,
|
||||
|
||||
SourceMd5CheckSuccess,
|
||||
SourceMd5CheckFailed,
|
||||
|
||||
ApplyPatchStart,
|
||||
SourceMd5CheckSuccess,
|
||||
|
||||
ApplyPatchFailed,
|
||||
ApplyPatchStart,
|
||||
|
||||
ApplyPatchSuccess,
|
||||
ApplyPatchFailed,
|
||||
|
||||
TargetMd5CheckStart,
|
||||
ApplyPatchSuccess,
|
||||
|
||||
TargetMd5CheckFailed,
|
||||
TargetMd5CheckStart,
|
||||
|
||||
TargetMd5CheckSuccess,
|
||||
TargetMd5CheckFailed,
|
||||
|
||||
InstallStart,
|
||||
TargetMd5CheckSuccess,
|
||||
|
||||
InstallFailed,
|
||||
InstallStart,
|
||||
|
||||
InstallSuccess;
|
||||
InstallFailed,
|
||||
|
||||
companion object {
|
||||
InstallSuccess;
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(status: InstallStatus?) = status?.ordinal
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun to(value: Int?) = values().find { it.ordinal == value }
|
||||
|
||||
@JvmStatic
|
||||
@TypeConverter
|
||||
fun from(status: Status?) = status?.ordinal
|
||||
}
|
||||
}
|
||||
|
||||
fun isReallyFailed() = (this == SourceMd5CheckFailed || this == ApplyPatchFailed || this == TargetMd5CheckFailed)
|
||||
}
|
||||
|
||||
class UpgradeRecordFull {
|
||||
|
||||
@Embedded
|
||||
var upgrade: UpgradeRecord? = null
|
||||
var record: Record? = null
|
||||
|
||||
@Relation(
|
||||
parentColumn = "f_v",
|
||||
entityColumn = "d_v",
|
||||
parentColumn = "version_name",
|
||||
entityColumn = "from_version_name",
|
||||
entity = CheckRecord::class
|
||||
)
|
||||
var checks: List<CheckRecord>? = null
|
||||
|
||||
@Relation(
|
||||
parentColumn = "version_name",
|
||||
entityColumn = "from_version_name",
|
||||
entity = UpgradeRecord::class
|
||||
)
|
||||
var upgrades: List<UpgradeRecord>? = null
|
||||
|
||||
@Relation(
|
||||
parentColumn = "version_name",
|
||||
entityColumn = "from_version_name",
|
||||
entity = DownloadRecord::class
|
||||
)
|
||||
var downloads: List<DownloadRecord>? = null
|
||||
|
||||
|
||||
@Relation(
|
||||
parentColumn = "f_v",
|
||||
entityColumn = "i_v",
|
||||
parentColumn = "version_name",
|
||||
entityColumn = "from_version_name",
|
||||
entity = InstallRecord::class
|
||||
)
|
||||
var installs: List<InstallRecord>? = null
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user