调试升级接口

This commit is contained in:
lixiaopeng
2023-02-23 14:43:00 +08:00
parent de352596af
commit 2efb14e5f5
9 changed files with 72 additions and 27 deletions

View File

@@ -162,8 +162,10 @@ class BindingCarManager : IMoGoAutopilotCarConfigListener {
* 查询app是否需要升级
*/
fun queryAppUpgrade() {
UpgradeAppNetWorkManager.getInstance()
.getAppUpgradeInfo(mContext, mAddress, role.toString() + "")
// UpgradeAppNetWorkManager.getInstance()
// .getAppUpgradeInfo(mContext, mAddress, role.toString() + "")
ObuUpgradeAppNetWorkManager.getInstance().getObuUpgradeInfo(mContext, "")
}
/**
@@ -171,7 +173,7 @@ class BindingCarManager : IMoGoAutopilotCarConfigListener {
*
*/
private fun queryObuUpgrade(macAddress: String) {
ObuUpgradeAppNetWorkManager.getInstance().getObuUpgradeInfo(mContext, macAddress)
// ObuUpgradeAppNetWorkManager.getInstance().getObuUpgradeInfo(mContext, macAddress)
}
}

View File

@@ -3,17 +3,16 @@ 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 android.util.Log;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.constants.HostConst;
import com.mogo.eagle.core.data.bindingcar.UpgradeAppInfo;
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager;
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 com.mogo.eagle.core.utilcode.util.AppUtils;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
@@ -50,16 +49,23 @@ public class ObuUpgradeAppNetWorkManager {
/**
* 获取obu升级信息obu升级服务端使用app升级接口根据screenType区分类型
* mac 工控机mac地址
* screenType 类型
* mac 工控机mac地址 TODO 立即升级,还是
* screenType 类型 liyz
*/
public void getObuUpgradeInfo(Context context, String mac) {
// String sn = "X20202203105S688HZ";
// String mac = "48:b0:2d:3a:bc:78";
// MogoObuManager().getInstance().readSystemBConfig(context, obuIp, listener)
//obuIp
// MogoObuManager().getInstance().uploadUpgradePackage(obuIp, upgradePackage, listener)
Log.e("liyz", "ObuUpgradeAppNetWorkManager getObuUpgradeInfo -----------> ");
String mac1 = "48:b0:2d:4d:33:40";
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
String obuVersionName = String.valueOf(AppUtils.getAppVersionCode()); // TODO 获取obu的版本号, string和int 服务端处理
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo mac = " + mac + "---sn = " + sn + "---obuVersionName =" + obuVersionName);
UpgradeAppRequest request = new UpgradeAppRequest(sn, mac, "7");
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo mac = " + mac1 + " ---sn = " + sn + " ---obuVersionName = " + obuVersionName);
UpgradeAppRequest request = new UpgradeAppRequest(sn, mac1, "7");
RequestBody requestBody = RequestBody.create(MediaType.get("application/json;charset=UTF-8"), GsonUtil.jsonFromObject(request));
mUpgradeApiService.getUpgradeInfo(requestBody)
.subscribeOn(Schedulers.io())
@@ -72,11 +78,11 @@ public class ObuUpgradeAppNetWorkManager {
@Override
public void onNext(@NonNull UpgradeAppInfo info) {
if (info != null && info.result != null) {
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo url = " + info.result.getAppUrl() + "----name = " + info.result.getVersionName() + "--obuVersionName =" + obuVersionName + "--info.result = " + info.result);
if (!String.valueOf(info.result.getVersionName()).equals(obuVersionName)) {
//下载 TAG和文件名 TODO
CallerDevaToolsManager.INSTANCE.downLoadPackage("OBU", info.result.getAppUrl());
}
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo appFileName = " + info.result.getAppFileName() + " ----url = " + info.result.getAppUrl() + " ----name = " + info.result.getVersionName() + " --obuVersionName =" + obuVersionName + " ---info.result = " + info.result);
Log.d("liyz", "getObuUpgradeInfo appFileName = " + info.result.getAppFileName() + " ----url = " + info.result.getAppUrl() + " ----name = " + info.result.getVersionName() + " --obuVersionName =" + obuVersionName + " ---info.result = " + info.result);
// if (!String.valueOf(info.result.getVersionName()).equals(obuVersionName)) { //判断是否下载,当文件名称不一致的时候,就下载 TODO
CallerDevaToolsManager.INSTANCE.downLoadPackage(info.result.getAppFileName(), info.result.getAppUrl());
// }
} else {
CallerLogger.INSTANCE.d(M_BINDING + TAG, "getObuUpgradeInfo onNext info == null");
}

View File

@@ -2,6 +2,7 @@ package com.zhjt.mogo_core_function_devatools.upgrade
import android.app.NotificationManager
import android.content.Context
import android.util.Log
import androidx.core.app.NotificationCompat
import com.elegant.utils.UiThreadHandler
import com.mogo.eagle.core.function.api.devatools.IMogoDevaToolsUpgradeListener
@@ -29,12 +30,18 @@ class UpgradeManager : IDownload {
}
private var map: Map<String, String>? = null
private var mDownloadFileName: String? = null
fun downLoadPackage(context: Context, downloadKey: String,downloadUrl: String) {
Log.d("liyz", "UpgradeManager downLoadPackage = " + downloadUrl?.contains(".zip") + "----downloadKey = $downloadKey ---downloadUrl = $downloadUrl")
if (downloadUrl?.contains(".zip")) {
mDownloadFileName = downloadKey
}
DownloadUtils.downLoad(
context,
downloadUrl,
Config.downLoadPath,
if (downloadUrl?.contains(".zip")) Config.downLoadObuPath else Config.downLoadPath,
downloadKey,
5,
this
@@ -81,13 +88,15 @@ class UpgradeManager : IDownload {
}
override fun onFinished(downloadUrl: String?, threadBean: ThreadBean?) {
if (downloadUrl != null) {
if (downloadUrl != null) { //TODO 需要判断是否是apk文件
AppUtils.installApp(Config.downLoadPath + downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1))
}
if (downloadUrl != null) {
if (map.isNullOrEmpty()) {
Log.d("liyz", "onFinished ----1------")
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(downloadUrl)
} else {
Log.d("liyz", "onFinished ----2------")
findKey(downloadUrl) {
CallerDevaToolsUpgradeListenerManager.invokeUpgradeFinish(it)
}
@@ -97,6 +106,7 @@ class UpgradeManager : IDownload {
override fun onError(downloadUrl: String?, errorMsg: String?) {
CallerLogger.d("$M_DEVA$TAG","onError downloadUrl : $downloadUrl , errorMsg : $errorMsg")
Log.e("liyz","onError downloadUrl : $downloadUrl , errorMsg : $errorMsg")
if (downloadUrl != null) {
if (map.isNullOrEmpty()) {
CallerDevaToolsUpgradeListenerManager.invokeUpgradeError(downloadUrl, errorMsg ?: "未知错误")
@@ -111,6 +121,7 @@ class UpgradeManager : IDownload {
private fun findKey(downloadUrl: String?, findResult: (downloadUrl: String) -> Unit) {
downloadUrl?.let { url ->
map?.iterator()?.forEach {
Log.d("liyz", "findKey it.value = ${it.value} ----url = $url")
if (it.value == url) {
findResult.invoke(it.key)
}
@@ -119,7 +130,7 @@ class UpgradeManager : IDownload {
}
/**
* 鹰眼app下载监听
* 鹰眼app下载监听 liyz
*/
fun updateUpgradeProgress(context: Context) {
val builder = NotificationCompat.Builder(context)
@@ -153,7 +164,7 @@ class UpgradeManager : IDownload {
}
/**
* obu升级包下载监听
* obu升级包下载监听 liyz
*/
fun updateObuUpgradeStatus(context: Context) {
CallerDevaToolsUpgradeListenerManager.addListener(
@@ -162,23 +173,29 @@ class UpgradeManager : IDownload {
override fun onStart(url: String?) {}
override fun onPause(url: String?) {}
override fun onProgress(url: String?, length: Int) {
}
override fun onFinished(url: String?) {
//下载完成,解压文件 TODO
//下载完成,解压文件
try {
val files = ZipUtils.unzipFile("", "")
//传给obu升级
///storage/emulated/0/obu/MOGO_OBUAPPS_V503A_PACK.zip
Log.d("liyz", " onFinished file = ${Config.downLoadObuPath + mDownloadFileName} ")
val files = ZipUtils.unzipFile(Config.downLoadObuPath + mDownloadFileName, Config.downLoadUnzipObuPath)
Log.d("liyz", " onFinished files = $files ")
//1传给obu升级,升级成功2需要删除相应文件夹 TODO
// onFinished files = [/storage/emulated/0/obuunzip/MOGO_OBUAPPS_V503A_PATCH.tar.gz, /storage/emulated/0/obuunzip/README.txt, /storage/emulated/0/obuunzip/version.json]
} catch (e: IOException) {
//解压失败
Log.e("liyz", "unzip failed -----> ")
e.printStackTrace()
}
}
override fun onError(url: String?, errorMsg: String?) {}
override fun onError(url: String?, errorMsg: String?) {
Log.d("liyz", " onProgress errorMsg = $errorMsg ")
}
})
}

View File

@@ -54,7 +54,7 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
clearMessageBoxTable();
CallerMsgBoxManager.INSTANCE.queryAllMessages(this);
}
CallerDevaToolsManager.INSTANCE.updateUpgradeProgress();
// CallerDevaToolsManager.INSTANCE.updateUpgradeProgress();
CallerDevaToolsManager.INSTANCE.updateObuUpgradeStatus();
}

View File

@@ -17,6 +17,7 @@ public class AppInfo implements Serializable {
private String installType; // 升级类型 1:提示升级 2:静默升级 3:强制升级
private String beginTime;
private String endTime;
private String appFileName;
public String getAppUrl() {
return appUrl;
@@ -90,6 +91,14 @@ public class AppInfo implements Serializable {
this.endTime = endTime;
}
public String getAppFileName() {
return appFileName;
}
public void setAppFileName(String appFileName) {
this.appFileName = appFileName;
}
@Override
public String toString() {
return "AppInfo{" +
@@ -102,6 +111,7 @@ public class AppInfo implements Serializable {
", installType='" + installType + '\'' +
", beginTime='" + beginTime + '\'' +
", endTime='" + endTime + '\'' +
", appFileName='" + appFileName + '\'' +
'}';
}
}

View File

@@ -16,5 +16,8 @@ public class Config {
public final static String downLoadObuPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/obu/";
public final static String downLoadUnzipObuPath = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/obuunzip/";
public final static String DOWN_LOAD_TAG = "Package-DownLoad";
}

View File

@@ -75,6 +75,7 @@ public class DownloadTask implements DownloadCallBack {
}
downloadCallBack.startDownload(fileBean.getUrl());
Log.d(DOWN_LOAD_TAG, " 开始下载:" + finishedProgress);
Log.d("liyz", " DownloadTask 开始下载:" + finishedProgress + "---fileBean.getUrl() = " + fileBean.getUrl());
}
/**
@@ -144,6 +145,7 @@ public class DownloadTask implements DownloadCallBack {
}
if (threads.size() == 0) {//如果列表size为0 则所有线程已下载完成
Log.d(DOWN_LOAD_TAG, " DownloadTask threadDownLoadFinished 下载完成----->");
Log.d("liyz", "threadDownLoadFinished ------------ 下载完成-----> ");
//删除数据库中的信息
dao.deleteThread(fileBean.getUrl());
//发送下载完成事件

View File

@@ -51,11 +51,13 @@ public class DownloadThread extends Thread {
int start = threadBean.getStart() + threadBean.getFinished();
connection.setRequestProperty("Range","bytes="+start+"-"+threadBean.getEnd());
//设置写入位置
File file = new File(Config.downLoadPath,fileBean.getFileName());
Log.d("liyz", "fileBean.getFileName() = " + fileBean.getFileName() + "---Config.downLoadPath = " + Config.downLoadPath);
File file = new File(fileBean.getFileName().contains(".zip") ? Config.downLoadObuPath : Config.downLoadPath,fileBean.getFileName());
raf = new RandomAccessFile(file,"rwd");
raf.seek(start);
//开始下载
Log.d(DOWN_LOAD_TAG, "DownloadThread connection.getResponseCode() = " + connection.getResponseCode() + "---threadBean.getUrl() =" + threadBean.getUrl());
Log.d("liyz", "DownloadThread connection.getResponseCode() = " + connection.getResponseCode() + "---threadBean.getUrl() =" + threadBean.getUrl());
if(connection.getResponseCode() == HttpURLConnection.HTTP_PARTIAL){
inputStream = connection.getInputStream();
byte[] bytes = new byte[1024];
@@ -77,6 +79,7 @@ public class DownloadThread extends Thread {
}
} catch (Exception e) {
Log.e("liyz", "DownloadThread ---1---- e = " + e);
e.printStackTrace();
DownloadData downloadData = new DownloadData();
downloadData.setUrl(fileBean.getUrl());

View File

@@ -2,6 +2,7 @@ package com.mogo.eagle.core.utilcode.breakpoint.utils;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.mogo.eagle.core.utilcode.breakpoint.bean.FileBean;
import com.mogo.eagle.core.utilcode.breakpoint.callback.IDownload;
@@ -11,6 +12,7 @@ import com.mogo.eagle.core.utilcode.breakpoint.services.DownloadService;
public class DownloadUtils {
public static void downLoad(Context context, String url, String savePath, String fileName, int downloadThreadCount, IDownload iDownload) {
Log.d("liyz", "---DownloadUtils fileName = " + fileName);
FileBean fileBean = new FileBean(0, savePath, fileName, url, 0);
fileBean.setThreadCount(downloadThreadCount);
Intent startIntent = new Intent(context, DownloadService.class);