[6.9.0]OTA升级

This commit is contained in:
xuxinchao
2024-12-04 16:50:49 +08:00
parent a706c59ac0
commit c9e0f1e4f4
14 changed files with 486 additions and 37 deletions

View File

@@ -2,6 +2,7 @@ package com.zhjt.mogo_core_function_devatools.ota
import android.content.Context
import android.util.Log
import com.mogo.eagle.core.data.deva.ota.OtaUpgradeInfo
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.api.datacenter.IDataCenterBizListener
import com.mogo.eagle.core.function.api.devatools.IOTAListener
@@ -9,7 +10,9 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.datacenter.CallerDataCenterBizListener
import com.mogo.eagle.core.function.call.devatools.CallerOTAManager
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import org.json.JSONArray
import org.json.JSONObject
import system_master.SsmInfo
/**
@@ -50,11 +53,74 @@ object OTAUpgradeManager: IMoGoAutopilotStatusListener, IDataCenterBizListener,
}
/**
* SSM发送OTA升级提示请求
* SSM发送OTA升级提示请求,主动触发
* @param request SSM发送OTA升级提示内容
*/
override fun onOtaDownloadRequest(request: SsmInfo.OtaDownloadRequest) {
super.onOtaDownloadRequest(request)
Log.i(TAG,"onOtaDownloadRequest otaToken"+request.otaToken)
Log.i(TAG,"onOtaDownloadRequest productName"+request.productName)
if(request.otaToken.isNotEmpty()){
if(OTAUpgradeConfig.otaToken != request.otaToken){
OTAUpgradeConfig.otaToken = request.otaToken
//触发升级提示
CallerHmiManager.showOTAUpgradeDialog()
}else{
//展示OTA升级提示
CallerHmiManager.showOTAUpgradeTipView(true)
}
}else{
//隐藏OTA升级提示
CallerHmiManager.showOTAUpgradeTipView(false)
}
//解析JSON
var upgradeComplete = true
val otaUpgradeList = ArrayList<OtaUpgradeInfo>()
val productArray = JSONArray(request.productName)
if(productArray.length() > 0){
for(index in 0 until productArray.length()){
val productInfo = productArray[index] as JSONObject
val token = productInfo.optString("token")
val productStatus = productInfo.optInt("status")
val failReason = productInfo.optString("fail_reason")
val upgradeReason = productInfo.optString("upgrade_reason")
val taskId = productInfo.optInt("task_id")
val taskItemId = productInfo.optInt("task_item_id")
val otaType = productInfo.optInt("ota_type")
val productName = productInfo.optString("product_name")
val needRestart = productInfo.optBoolean("need_restart")
val isDelay = productInfo.optBoolean("is_delay")
val curSize = productInfo.optDouble("cur_size")
val totalSize = productInfo.optDouble("total_size")
Log.i(TAG, "index=$index")
Log.i(TAG, "token=$token")
Log.i(TAG, "status=$productStatus")
Log.i(TAG, "fail_reason=$failReason")
Log.i(TAG, "upgrade_reason=$upgradeReason")
Log.i(TAG, "task_id=$taskId")
Log.i(TAG, "task_item_id=$taskItemId")
Log.i(TAG, "ota_type=$otaType")
Log.i(TAG, "product_name=$productName")
Log.i(TAG, "need_restart=$needRestart")
Log.i(TAG, "is_delay=$isDelay")
Log.i(TAG, "cur_size=$curSize")
Log.i(TAG, "total_size=$totalSize")
//// 状态 0:默认(未开始), 1:下载中, 2:下载完成, 3:升级完成, 4:升级失败
if(productStatus == 0 || productStatus == 1 || productStatus == 2){
upgradeComplete = false
}
val otaUpgradeInfo = OtaUpgradeInfo(token, productStatus,failReason,upgradeReason,
taskId,taskItemId,otaType,productName,needRestart,isDelay,curSize,totalSize)
otaUpgradeList.add(otaUpgradeInfo)
}
CallerHmiManager.showOTADownloadStatusDialog(otaUpgradeList)
if(upgradeComplete){
OTAUpgradeConfig.otaToken = ""
}
}
}
@@ -68,15 +134,69 @@ object OTAUpgradeManager: IMoGoAutopilotStatusListener, IDataCenterBizListener,
*/
override fun onOtaStatus(status: SsmInfo.OtaStatus) {
super.onOtaStatus(status)
OTAUpgradeConfig.otaToken = status.otaInfo.otaToken
Log.i(TAG,"onOtaStatus status.otaInfo.otaToken"+status.otaInfo.otaToken)
Log.i(TAG,"onOtaStatus status.otaInfo.productName"+status.otaInfo.productName)
Log.i(TAG,"status.otaInfo.otaToken"+status.otaInfo.otaToken)
Log.i(TAG,"status.otaInfo.productName"+status.otaInfo.productName)
if(status.otaInfo.otaToken.isNotEmpty()){
if(OTAUpgradeConfig.otaToken != status.otaInfo.otaToken){
OTAUpgradeConfig.otaToken = status.otaInfo.otaToken
//触发升级提示
CallerHmiManager.showOTAUpgradeDialog()
}else{
//展示OTA升级提示
CallerHmiManager.showOTAUpgradeTipView(true)
}
}else{
//隐藏OTA升级提示
CallerHmiManager.showOTAUpgradeTipView(false)
}
//解析JSON
val otaUpgradeList = ArrayList<OtaUpgradeInfo>()
val productArray = JSONArray(status.otaInfo.productName)
var upgradeComplete = true
if(productArray.length() > 0){
for(index in 0 until productArray.length()){
val productInfo = productArray[index] as JSONObject
val token = productInfo.optString("token")
val productStatus = productInfo.optInt("status")
val failReason = productInfo.optString("fail_reason")
val upgradeReason = productInfo.optString("upgrade_reason")
val taskId = productInfo.optInt("task_id")
val taskItemId = productInfo.optInt("task_item_id")
val otaType = productInfo.optInt("ota_type")
val productName = productInfo.optString("product_name")
val needRestart = productInfo.optBoolean("need_restart")
val isDelay = productInfo.optBoolean("is_delay")
val curSize = productInfo.optDouble("cur_size")
val totalSize = productInfo.optDouble("total_size")
Log.i(TAG, "index=$index")
Log.i(TAG, "token=$token")
Log.i(TAG, "status=$productStatus")
Log.i(TAG, "fail_reason=$failReason")
Log.i(TAG, "upgrade_reason=$upgradeReason")
Log.i(TAG, "task_id=$taskId")
Log.i(TAG, "task_item_id=$taskItemId")
Log.i(TAG, "ota_type=$otaType")
Log.i(TAG, "product_name=$productName")
Log.i(TAG, "need_restart=$needRestart")
Log.i(TAG, "is_delay=$isDelay")
Log.i(TAG, "cur_size=$curSize")
Log.i(TAG, "total_size=$totalSize")
//// 状态 0:默认(未开始), 1:下载中, 2:下载完成, 3:升级完成, 4:升级失败
if(productStatus == 0 || productStatus == 1 || productStatus == 2){
upgradeComplete = false
}
val otaUpgradeInfo = OtaUpgradeInfo(token, productStatus,failReason,upgradeReason,
taskId,taskItemId,otaType,productName,needRestart,isDelay,curSize,totalSize)
otaUpgradeList.add(otaUpgradeInfo)
}
CallerHmiManager.showOTADownloadStatusDialog(otaUpgradeList)
if(upgradeComplete){
OTAUpgradeConfig.otaToken = ""
}
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ProgressBar
android:id="@+id/pbDownloadProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="?android:attr/progressBarStyleHorizontal"
/>
<TextView
android:id="@+id/tvDownloadStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/pbDownloadProgress"
android:textSize="@dimen/sp_30"
/>
</androidx.constraintlayout.widget.ConstraintLayout>