[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>

View File

@@ -29,6 +29,7 @@ import com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_FRAGMENT_HMI
import com.mogo.eagle.core.data.deva.bindingcar.IPCUpgradeStateInfo
import com.mogo.eagle.core.data.deva.bizconfig.FuncBizConfig.Companion.BIZ_RTS
import com.mogo.eagle.core.data.deva.bizconfig.FuncBizConfig.Companion.V2I
import com.mogo.eagle.core.data.deva.ota.OtaUpgradeInfo
import com.mogo.eagle.core.data.enums.EventTypeEnumNew
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
import com.mogo.eagle.core.data.map.Infrastructure
@@ -58,7 +59,9 @@ import com.mogo.eagle.core.function.hmi.ui.setting.StatusView
import com.mogo.eagle.core.function.hmi.ui.setting.ToolsView.Companion.toolsView
import com.mogo.eagle.core.function.hmi.ui.tools.AdUpgradeDialog
import com.mogo.eagle.core.function.hmi.ui.tools.ModifyBindingCarDialog
import com.mogo.eagle.core.function.hmi.ui.tools.OTADownloadStatusDialog
import com.mogo.eagle.core.function.hmi.ui.tools.OTAUpgradeDialog
import com.mogo.eagle.core.function.hmi.ui.tools.OTAUpgradeTipView
import com.mogo.eagle.core.function.hmi.ui.tools.ToBindingCarDialog
import com.mogo.eagle.core.function.hmi.ui.tools.UpgradeAppDialog
import com.mogo.eagle.core.function.hmi.ui.utils.HmiActionLog
@@ -660,15 +663,59 @@ class MoGoHmiProvider : IMoGoHmiProvider {
CallerHmiViewControlListenerManager.invokeColdStartProcessView()
}
var otaUpgradeDialog: OTAUpgradeDialog ?= null
var otaDownloadStatusDialog: OTADownloadStatusDialog ?= null
var otaUpgradeTipView: OTAUpgradeTipView ?= null
/**
* 展示OTA升级弹窗
*/
override fun showOTAUpgradeDialog() {
ThreadUtils.runOnUiThread{
if (context != null){
OTAUpgradeDialog.show(context)
context?.let {
if(otaUpgradeDialog == null){
otaUpgradeDialog = OTAUpgradeDialog(it)
}
if(otaUpgradeDialog?.isShowing == false){
otaUpgradeDialog?.show()
}
}
}
}
/**
* 展示OTA升级下载状态弹窗
*/
override fun showOTADownloadStatusDialog(list: List<OtaUpgradeInfo>) {
ThreadUtils.runOnUiThread{
if(otaDownloadStatusDialog?.isShowing == true){
return@runOnUiThread
}
context?.let {
if(otaDownloadStatusDialog == null){
otaDownloadStatusDialog = OTADownloadStatusDialog(it)
}
otaDownloadStatusDialog?.notifyDownloadStatus(list)
}
}
}
/**
* 展示OTA升级提示
* @param visible 设置是否可见
*/
override fun showOTAUpgradeTipView(visible: Boolean) {
ThreadUtils.runOnUiThread{
if(otaUpgradeDialog?.isShowing == true){
return@runOnUiThread
}
if(otaUpgradeTipView == null){
context?.let {
otaUpgradeTipView = OTAUpgradeTipView(it)
}
}
otaUpgradeTipView?.setDisplayStatus(visible)
}
}
}

View File

@@ -0,0 +1,46 @@
package com.mogo.eagle.core.function.hmi.ui.tools
import android.content.Context
import androidx.lifecycle.LifecycleObserver
import androidx.recyclerview.widget.LinearLayoutManager
import com.mogo.eagle.core.data.deva.ota.OtaUpgradeInfo
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.hmi.dialog.BaseFloatDialog
import com.mogo.eagle.core.function.hmi.ui.tools.adapter.OTADownloadStatusAdapter
import kotlinx.android.synthetic.main.dialog_ota_download_status.rvDownloadStatus
/**
* OTA升级下载状态对话框
*/
class OTADownloadStatusDialog(context: Context) :
BaseFloatDialog(context,TAG), LifecycleObserver {
companion object {
private const val TAG = "OTADownloadStatusDialog"
}
private var otaDownloadStatusAdapter: OTADownloadStatusAdapter ?= null
init{
setContentView(R.layout.dialog_ota_download_status)
setCanceledOnTouchOutside(false)
initView()
}
private fun initView(){
val linearLayoutManager = LinearLayoutManager(context)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
otaDownloadStatusAdapter = OTADownloadStatusAdapter(context)
rvDownloadStatus.adapter = otaDownloadStatusAdapter
rvDownloadStatus.layoutManager = linearLayoutManager
}
fun notifyDownloadStatus(list: List<OtaUpgradeInfo>){
if(!this.isShowing){
show()
}
otaDownloadStatusAdapter?.setData(list)
}
}

View File

@@ -1,12 +1,17 @@
package com.mogo.eagle.core.function.hmi.ui.tools
import android.content.Context
import android.os.CountDownTimer
import android.widget.TextView
import androidx.lifecycle.LifecycleObserver
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.hmi.dialog.BaseFloatDialog
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.zhjt.mogo_core_function_devatools.ota.OTAUpgradeConfig
import kotlinx.android.synthetic.main.dialog_ota_upgrade.tv_upgrade_countdown
import kotlinx.android.synthetic.main.dialog_ota_upgrade.tv_upgrade_later
import kotlinx.android.synthetic.main.dialog_ota_upgrade.tv_upgrade_now
import system_master.SsmInfo
/**
@@ -17,26 +22,12 @@ class OTAUpgradeDialog(context: Context) :
companion object {
private const val TAG = "OTAUpgradeDialog"
private var otaUpgradeDialog: OTAUpgradeDialog? = null
fun show(context: Context?) {
context?.let {
if (otaUpgradeDialog == null) {
otaUpgradeDialog = OTAUpgradeDialog(it)
}
otaUpgradeDialog?.let { dialog ->
if (dialog.isShowing) {
return
}
dialog.show()
}
}
}
private const val UPGRADE_WAITING_TIME = 300000L //升级确认等待时间
private const val WAITING_TICK_TIME = 1000L //等待确认间隔时间
}
private var clickListener: ClickListener? = null
private lateinit var tvUpgradeNow: TextView //立即升级
private lateinit var tvUpgradeLater: TextView //稍后升级
private var upgradeWaitingTimer: CountDownTimer ?= null //等待升级确认计时器
init{
setContentView(R.layout.dialog_ota_upgrade)
@@ -45,21 +36,32 @@ class OTAUpgradeDialog(context: Context) :
}
private fun initView(){
tvUpgradeNow = findViewById(R.id.tv_upgrade_now)
tvUpgradeLater = findViewById(R.id.tv_upgrade_later)
//立即升级
tvUpgradeNow.setOnClickListener {
tv_upgrade_now.setOnClickListener {
CallerAutoPilotControlManager.sendSsmFuncOtaDownloadResponse(OTAUpgradeConfig.otaToken,SsmInfo.IfUpgrade.IMMEDIATELY)
dismiss()
}
//稍后升级
tvUpgradeLater.setOnClickListener {
tv_upgrade_later.setOnClickListener {
CallerAutoPilotControlManager.sendSsmFuncOtaDownloadResponse(OTAUpgradeConfig.otaToken,SsmInfo.IfUpgrade.DELAY)
dismiss()
}
}
upgradeWaitingTimer = object: CountDownTimer(UPGRADE_WAITING_TIME,WAITING_TICK_TIME){
override fun onTick(millisUntilFinished: Long) {
ThreadUtils.runOnUiThread {
tv_upgrade_countdown.text = millisUntilFinished.toInt().toString()
}
}
override fun dismiss() {
super.dismiss()
otaUpgradeDialog = null
override fun onFinish() {
CallerAutoPilotControlManager.sendSsmFuncOtaDownloadResponse(OTAUpgradeConfig.otaToken,SsmInfo.IfUpgrade.DELAY)
ThreadUtils.runOnUiThread {
dismiss()
}
}
}
upgradeWaitingTimer?.start()
}
fun setClickListener(clickListener: ClickListener) {
@@ -73,4 +75,13 @@ class OTAUpgradeDialog(context: Context) :
fun upgradeLater()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
upgradeWaitingTimer?.cancel()
}
}

View File

@@ -0,0 +1,57 @@
package com.mogo.eagle.core.function.hmi.ui.tools
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.hmi.R
import kotlinx.android.synthetic.main.view_ota_upgrade_tip.view.btn_upgrade
/**
* OTA升级任务标记提示
*/
class OTAUpgradeTipView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr){
companion object {
private const val TAG = "OTAUpgradeTipView"
}
init {
LayoutInflater.from(context).inflate(R.layout.view_ota_upgrade_tip, this, true)
initView()
}
private fun initView(){
btn_upgrade.setOnClickListener {
//打开升级弹窗
CallerHmiManager.showOTAUpgradeDialog()
}
}
/**
* 设置视图是否可见
* @param visible 是否可见
*/
fun setDisplayStatus(visible: Boolean){
if(visible){
if(this@OTAUpgradeTipView.visibility == View.VISIBLE){
return
}else{
this@OTAUpgradeTipView.visibility = View.VISIBLE
}
}else{
if(this@OTAUpgradeTipView.visibility != View.VISIBLE){
return
}else{
this@OTAUpgradeTipView.visibility = View.GONE
}
}
}
}

View File

@@ -0,0 +1,63 @@
package com.mogo.eagle.core.function.hmi.ui.tools.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mogo.eagle.core.data.deva.ota.OtaUpgradeInfo
import com.mogo.eagle.core.function.hmi.R
/**
* OTA升级下载状态适配器
*/
class OTADownloadStatusAdapter(private val context: Context): RecyclerView.Adapter<OTADownloadStatusAdapter.DownloadStatusHolder>() {
private var data: List<OtaUpgradeInfo> ?= null
fun setData(list: List<OtaUpgradeInfo>){
this.data = list
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DownloadStatusHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_ota_download_status, parent, false)
return DownloadStatusHolder(view)
}
override fun onBindViewHolder(holder: DownloadStatusHolder, position: Int) {
data?.let {
val otaUpgradeInfo = it[position]
holder.pbDownloadProgress.progress = (otaUpgradeInfo.cur_size*100/otaUpgradeInfo.total_size).toInt()
// 0:默认(未开始), 1:下载中, 2:下载完成, 3:升级完成, 4:升级失败
holder.tvDownloadStatus.text = when (otaUpgradeInfo.status) {
1 -> {
"下载中"
}
2 -> {
"下载完成"
}
3 -> {
"升级完成"
}
4 -> {
"升级失败"
}
else -> {
"默认(未开始)"
}
}
}
}
override fun getItemCount() = data?.size ?: 0
class DownloadStatusHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
var pbDownloadProgress: ProgressBar = itemView.findViewById(R.id.pbDownloadProgress)
var tvDownloadStatus: TextView = itemView.findViewById(R.id.tvDownloadStatus)
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDownloadStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -21,6 +21,18 @@
android:layout_marginTop="50dp"
/>
<TextView
android:id="@+id/tv_upgrade_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/tv_upgrade_title"
app:layout_constraintBottom_toBottomOf="@id/tv_upgrade_title"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="@dimen/dp_50"
android:textSize="@dimen/sp_30"
android:textColor="@color/white"
/>
<TextView
android:id="@+id/tv_upgrade_content"
android:layout_width="0dp"

View File

@@ -141,6 +141,15 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.mogo.eagle.core.function.hmi.ui.tools.OTAUpgradeTipView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="@dimen/dp_39"
/>
<!-- 事件弹框 -->
<com.mogo.eagle.core.function.hmi.ui.v2n.RoadV2NEventWindowView
android:id="@+id/roadV2NEventWindowView"

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_upgrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OTA升级"
/>
</LinearLayout>