[2.15.0] 添加下载错误的回调

This commit is contained in:
lixiaopeng
2023-04-19 15:26:56 +08:00
parent 570147ca0f
commit 124e21f601
6 changed files with 37 additions and 4 deletions

View File

@@ -60,7 +60,7 @@ class UpgradeAppNetWorkManager private constructor() {
provider?.recordUpgradeRecord(sn ?: "", macAddress, type, FunctionBuildConfig.isSupportPatchUpgrade)
provider?.recordUpgradeRequestStart()
val info = mUpgradeApiService.getUpgradeInfo(requestBody)
SharedPrefsMgr.getInstance(context).putString(SharedPrefsConstants.APP_UPGRADE_CONTENT, if (info.result != null) GsonUtils.toJson(info) + "--mac:$macAddress --type:$type --sn:$sn --versionName:$versionName" else "info.result == null --mac:$macAddress --type:$type --sn:$sn --versionName:$versionName")
SharedPrefsMgr.getInstance(context).putString(SharedPrefsConstants.APP_UPGRADE_CONTENT, if (info.result != null) GsonUtils.toJson(info) + "--mac:$macAddress --type:$type --sn:$sn --versionName:$versionName" else "info.result == null --mac:$macAddress --type:$type --sn:$sn --versionName:$versionName --versionCode:$versionCode")
if (info.result != null) {
provider?.recordUpgradeRequestSuccess(GsonUtils.toJson(info))
doUpgrade(info)

View File

@@ -2,6 +2,7 @@ package com.zhjt.mogo_core_function_devatools.upgrade
import android.content.Context
import android.content.pm.PackageInstaller
import android.util.Log
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
@@ -229,10 +230,17 @@ class UpgradeManager : IDownload {
CallerDevaToolsUpgradeListenerManager.addListener(
TAG,
object : IMogoDevaToolsUpgradeListener {
override fun onStart(url: String?) {}
override fun onPause(url: String?) {}
override fun onStart(url: String?) {
CallerLogger.d("$M_DEVA$TAG", "updateUpgradeProgress onStart ----> ")
}
override fun onPause(url: String?) {
CallerLogger.d("$M_DEVA$TAG", "updateUpgradeProgress onPause ----> ")
}
override fun onProgress(url: String?, length: Int) {
updateStatusBarDownloadView(true, "download", length)
// CallerLogger.d("$M_DEVA$TAG", "updateUpgradeProgress onPause ----> length = $length")
if (length in 1..99) {
updateStatusBarDownloadView(true, "download", length)
}
}
override fun onFinished(url: String?, localPath: String) {
@@ -242,6 +250,10 @@ class UpgradeManager : IDownload {
}
override fun onError(url: String?, errorMsg: String?) {
CallerLogger.d("$M_DEVA$TAG", "updateUpgradeProgress errorMsg = $errorMsg")
Log.e(TAG, "updateUpgradeProgress errorMsg = $errorMsg")
//出错后去掉下载进度ui提示检查网络
updateStatusBarDownloadView(false, "download", 0)
}
})
}

View File

@@ -31,4 +31,10 @@ public interface DownloadCallBack {
* @param localPath
*/
void threadDownLoadFinished(String url, ThreadBean threadBean, String localPath);
/**
* 下载错误
* @param msg
*/
void errorCallBack(String url, String msg);
}

View File

@@ -161,6 +161,14 @@ public class DownloadService implements InitThread.InitCallBack, DownloadCallBac
}
}
@Override
public void errorCallBack(String url, String msg) {
IDownload iDownload = callBacks.get(url);
if (iDownload != null) {
iDownload.onError(url, msg);
}
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
//网络连接已连接

View File

@@ -153,6 +153,11 @@ public class DownloadTask implements DownloadCallBack {
}
}
@Override
public void errorCallBack(String url, String msg) {
UiThreadHandler.post(() -> downloadCallBack.errorCallBack(url, msg));
}
public FileBean getFileBean() {
return fileBean;
}

View File

@@ -82,6 +82,8 @@ public class DownloadThread extends Thread {
DownloadData downloadData = new DownloadData();
downloadData.setUrl(fileBean.getUrl());
downloadData.setMsg(e.getMessage());
UiThreadHandler.post(() -> callback.errorCallBack(this.fileBean.getUrl(), e.getMessage()));
// EventMessage eventMessage = new EventMessage(EventMessage.TYPE_ERROR,downloadData);
// EventBus.getDefault().post(eventMessage);
} finally {