From 72a27c6e78850dcaade9be8b04d567a8ae2835a8 Mon Sep 17 00:00:00 2001 From: yangyakun Date: Wed, 25 Sep 2024 11:17:21 +0800 Subject: [PATCH] =?UTF-8?q?[6.6.1]=20[fix]=20[=E4=BF=AE=E5=A4=8D=20session?= =?UTF-8?q?=20=E8=B6=85=E6=97=B6=E6=9C=AA=E6=B8=85=E7=90=86]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autopilot/OchAutoPilotManager.kt | 40 +++++++++++----- .../autopilot/OchAutopilotAnalytics.kt | 48 +++++++++++-------- .../autopilot/bean/SessionWithTime.kt | 3 ++ 3 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/bean/SessionWithTime.kt diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutoPilotManager.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutoPilotManager.kt index 0cfb8c4f7f..3aa3f95b19 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutoPilotManager.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutoPilotManager.kt @@ -14,19 +14,22 @@ import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger import com.mogo.eagle.core.utilcode.util.ToastUtils import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager +import com.mogo.och.common.module.manager.autopilot.autopilot.bean.SessionWithTime import com.mogo.och.common.module.manager.autopilot.line.LineManager import com.mogo.och.common.module.manager.distance.TrajectoryAndDistanceManager +import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager import com.zhjt.mogo.adas.common.MessageType import com.zhjt.mogo.adas.data.bean.ReceivedAck import com.zhjt.mogo.adas.data.bean.ReceivedAck.Status import fsm.Fsm2024 import java.util.concurrent.atomic.AtomicLong +import java.util.concurrent.atomic.AtomicReference object OchAutoPilotManager : IMoGoReceiveReceivedAckListener, IMoGoFsm2024Listener { const val TAG = "OchAutoPilotManager" - private val globalSessionId = AtomicLong(-1) + private val globalSessionId = AtomicReference() private val fsmBackSessionId = AtomicLong(-1L) init { @@ -51,18 +54,27 @@ object OchAutoPilotManager : IMoGoReceiveReceivedAckListener, IMoGoFsm2024Listen * 启动自驾中禁止再次启动自驾 */ @JvmStatic - fun canStartAutopilotBySessionId():Boolean{ - return (globalSessionId.get()==-1L).apply { - if(!this) { + fun canStartAutopilotBySessionId(): Boolean { + val sessionInfo = globalSessionId.get() + val currentTimeMillis = System.currentTimeMillis() + if(sessionInfo==null){ + return true + }else{ + if(currentTimeMillis-sessionInfo.setTime>=OchAutopilotAnalytics.LOOP_PERIOD_16S){ + clearGlobalSessionId("检测session 自带的时间 ${currentTimeMillis}_${sessionInfo.setTime}_${sessionInfo.sessionId}") + return true + }else{ ToastUtils.showLong("自驾启动中,请勿重复点击") OchAutopilotAnalytics.triggerCanStartAutopilotBySessionId(globalSessionId.get()) + return false } } } @JvmStatic fun canStartAutopilotBySessionIdInner():Boolean{ - return (globalSessionId.get()==-1L) + OchChainLogManager.writeChainLogAutopilot("自驾流程","清理SessiongId") + return (globalSessionId.get()==null) } @JvmStatic @@ -88,14 +100,15 @@ object OchAutoPilotManager : IMoGoReceiveReceivedAckListener, IMoGoFsm2024Listen return true } - fun clearGlobalSessionId(){ - globalSessionId.set(-1) + fun clearGlobalSessionId(log:String){ + OchChainLogManager.writeChainLogAutopilot("自驾流程","清理SessiongId${globalSessionId}_${fsmBackSessionId}_${log}") + globalSessionId.set(null) } @JvmStatic fun startAutoPilot(controlParameters: AutopilotControlParameters?): Long { val sessionId = CallerAutoPilotControlManager.startAutoPilot(controlParameters) - globalSessionId.set(sessionId) + globalSessionId.set(SessionWithTime(sessionId,System.currentTimeMillis())) fsmBackSessionId.set(-1L) OchAutopilotAnalytics.triggerStartAutopilotParameters(controlParameters, sessionId) return sessionId @@ -120,9 +133,14 @@ object OchAutoPilotManager : IMoGoReceiveReceivedAckListener, IMoGoFsm2024Listen * 启动自驾失败切 FSM返回的Session和启动SessionId 不同 */ fun checkStartSessionAndFailSessionId(){ - if(globalSessionId.get() != fsmBackSessionId.get()){ - OchAutopilotAnalytics.triggerStartAutopilotFailCheckSessionDiff(globalSessionId.get(), - fsmBackSessionId.get()) + val sessionInfo = globalSessionId.get() + if(sessionInfo!=null) { + if (sessionInfo.sessionId != fsmBackSessionId.get()) { + OchAutopilotAnalytics.triggerStartAutopilotFailCheckSessionDiff( + sessionInfo, + fsmBackSessionId.get() + ) + } } } } \ No newline at end of file diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutopilotAnalytics.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutopilotAnalytics.kt index e1a4591ad8..8e18aedf1b 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutopilotAnalytics.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/OchAutopilotAnalytics.kt @@ -11,8 +11,11 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant import com.mogo.eagle.core.utilcode.util.DateTimeUtils import com.mogo.och.common.module.manager.autopilot.OCHAdasAbilityManager +import com.mogo.och.common.module.manager.autopilot.autopilot.bean.SessionWithTime import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager import com.mogo.och.common.module.manager.loop.BizLoopManager +import com.mogo.och.common.module.utils.RxUtils +import io.reactivex.disposables.Disposable object OchAutopilotAnalytics { @@ -49,6 +52,7 @@ object OchAutopilotAnalytics { private const val EVENT_PARAM_VEHICLE_START_AUTOPILOT_CMD_SESSION_ID_FSM_RETURN = "cmd_session_id_fsm_return" private val LOOP_PERIOD_15S = 15 * 1000L + val LOOP_PERIOD_16S = 16 * 1000L private var mStartAutopilotKey: String? = null @@ -94,34 +98,36 @@ object OchAutopilotAnalytics { /** * 等待底盘返回的间隙 重复启动自驾 */ - fun triggerCanStartAutopilotBySessionId(globalSessionId : Long){ + fun triggerCanStartAutopilotBySessionId(globalSessionId : SessionWithTime){ val map = hashMapOf() map[EVENT_PARAM_AUTOPILOTANALYTICS_GROUP] = EVENT_PARAM_AUTOPILOTANALYTICS_GROUP - OchChainLogManager.writeChainLog("启动自驾Session判断","已有globalSessionId:${globalSessionId}", eventID = EVENT_KEY_VEHICLE_START_AUTOPILOT_CMD_SESSION_DUPLICATED, patch = map) + OchChainLogManager.writeChainLog("启动自驾Session判断","已有globalSessionId:${globalSessionId.sessionId}_创建时间:${globalSessionId.setTime}", eventID = EVENT_KEY_VEHICLE_START_AUTOPILOT_CMD_SESSION_DUPLICATED, patch = map) } /** * 启动失败后 对比两个session是否相同 */ - fun triggerStartAutopilotFailCheckSessionDiff(globalSessionId: Long, fsmBackSessionId: Long){ + fun triggerStartAutopilotFailCheckSessionDiff(globalSessionId: SessionWithTime, fsmBackSessionId: Long){ val map = hashMapOf() map[EVENT_PARAM_AUTOPILOTANALYTICS_GROUP] = EVENT_PARAM_AUTOPILOTANALYTICS_GROUP - map[EVENT_PARAM_VEHICLE_START_AUTOPILOT_CMD_SESSION_ID_START] = globalSessionId + map[EVENT_PARAM_VEHICLE_START_AUTOPILOT_CMD_SESSION_ID_START] = "${globalSessionId.sessionId}_${globalSessionId.setTime}" map[EVENT_PARAM_VEHICLE_START_AUTOPILOT_CMD_SESSION_ID_FSM_RETURN] = fsmBackSessionId OchChainLogManager.writeChainLog("启动自驾失败且SessionId不同","globalSessionId:${globalSessionId}——————fsmBackSessionId:${fsmBackSessionId}", eventID = EVENT_KEY_VEHICLE_START_AUTOPILOT_CMD_SESSION_DIFF, patch = map) } - - private val timeOutRunnable = Runnable { - // 15s内未开启,上报失败埋点 - triggerStartAutopilotFailureEvent("", "15s后app等待超时", System.currentTimeMillis()) - } + private var timeOutDisposable: Disposable?=null /** * 底盘明确告知启动自驾失败 */ fun triggerStartAutopilotFailureEventByAdas(failCode: String, failMsg: String, startFailDate: Long) { - BizLoopManager.removeCallback(timeOutRunnable) + OchChainLogManager.writeChainLogAutopilot("自驾流程","启动自驾失败回调${failCode}_${failMsg}") + if(OchAutoPilotManager.canStartAutopilotBySessionIdInner()){ + CallerLogger.e(SceneConstant.M_OCHCOMMON + "triggerStartAutopilotFailureEvent canStartAutopilotBySessionIdInner == false") + OchChainLogManager.writeChainLogAutopilot("自驾流程","异常情况 启动自驾失败回调${failCode}_${failMsg}_sessiong为空") + return + } + RxUtils.disposeSubscribe(timeOutDisposable) // 判断Session 是否相同 OchAutoPilotManager.checkStartSessionAndFailSessionId() triggerStartAutopilotFailureEvent(failCode, failMsg, startFailDate) @@ -132,12 +138,10 @@ object OchAutopilotAnalytics { } private fun triggerStartAutopilotFailureEvent(failCode: String, failMsg: String, startFailDate: Long) { - if(OchAutoPilotManager.canStartAutopilotBySessionIdInner()){ - CallerLogger.e(SceneConstant.M_OCHCOMMON + "triggerStartAutopilotFailureEvent canStartAutopilotBySessionIdInner == false") + OchAutoPilotManager.clearGlobalSessionId("$failMsg _ ${failCode}") + if (mStartAutopilotParams.isEmpty()) { return } - OchAutoPilotManager.clearGlobalSessionId() - if (mStartAutopilotParams.isEmpty()) return CallerLogger.e(SceneConstant.M_OCHCOMMON + "triggerStartAutopilotFailureEvent", failMsg) if (CallerAutoPilotStatusListenerManager.getState() != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) { mStartAutopilotParams[EVENT_PARAM_START_FAILURE_CODE] = failCode @@ -170,15 +174,19 @@ object OchAutopilotAnalytics { triggerDate: Long, source:Int = 0 ) { + OchChainLogManager.writeChainLogAutopilot("自驾流程","send:${send}_${restart}_${startName}_${endName}_${lineId}_${orderId}_${source}_${triggerDate}") mStartAutopilotKey = if (restart) getEventKeyRestartService() else getEventKeyStartService() if (send) { if(OchAutoPilotManager.canStartAutopilotBySessionIdInner()){ CallerLogger.e(SceneConstant.M_OCHCOMMON + "triggerStartAutopilotEvent canStartAutopilotBySessionIdInner == false") + OchChainLogManager.writeChainLogAutopilot("自驾流程","异常情况 启动自驾成功_sessiong为空") + return + } + OchAutoPilotManager.clearGlobalSessionId("启动自驾成功") + RxUtils.disposeSubscribe(timeOutDisposable) + if (mStartAutopilotParams.isEmpty()) { return } - OchAutoPilotManager.clearGlobalSessionId() - BizLoopManager.removeCallback(timeOutRunnable) - if (mStartAutopilotParams.isEmpty()) return // 开启成功,上报埋点 mStartAutopilotParams[EVENT_PARAM_START_FAILURE_CODE] = "" mStartAutopilotParams[EVENT_PARAM_START_FAILURE_MSG] = "" @@ -198,8 +206,10 @@ object OchAutopilotAnalytics { mStartAutopilotParams[EVENT_PARAM_END_NAME] = endName mStartAutopilotParams[EVENT_PARAM_LINE_ID] = lineId mStartAutopilotParams[EVENT_PARAM_ORDER_NUMBER] = orderId?:"" - BizLoopManager.removeCallback(timeOutRunnable) - BizLoopManager.postDelayed(timeOutRunnable,LOOP_PERIOD_15S) + RxUtils.disposeSubscribe(timeOutDisposable) + timeOutDisposable = RxUtils.createSubscribe(LOOP_PERIOD_15S) { + triggerStartAutopilotFailureEvent("", "15s后app等待超时", System.currentTimeMillis()) + } } } diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/bean/SessionWithTime.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/bean/SessionWithTime.kt new file mode 100644 index 0000000000..7a3e97167f --- /dev/null +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/manager/autopilot/autopilot/bean/SessionWithTime.kt @@ -0,0 +1,3 @@ +package com.mogo.och.common.module.manager.autopilot.autopilot.bean + +data class SessionWithTime(val sessionId:Long,val setTime:Long)