[6.8.4][Opt]新增云端下发指令拉取logcat日志的功能

This commit is contained in:
chenfufeng
2024-12-26 18:54:21 +08:00
parent 5b487440ea
commit a0dc1973af
2 changed files with 52 additions and 2 deletions

View File

@@ -49,5 +49,10 @@ class MogoLogCatchConst {
* 关闭高精地图每个瓦片数据文件下载、删除的日志
*/
const val CLOSE_HD_MAP_TILE_FILE_LOG = 9
/**
* 上传Logcat日志
*/
const val UPLOAD_LOG_CAT_FILE = 10
}
}

View File

@@ -22,7 +22,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_DEVA
import com.mogo.commons.storage.SharedPrefsMgr
import com.mogo.eagle.core.data.deva.chain.ChainConstant
import com.mogo.core.log.record.LogcatManager
import com.mogo.eagle.core.data.deva.chain.ChainLogParam
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast
import com.mogo.eagle.core.utilcode.util.ThreadUtils
@@ -31,6 +31,7 @@ import com.zhidao.loglib.bean.RemoteLogPushContent
import com.zhidao.loglib.call.LogInfoManagerFactory
import com.zhidao.loglib.core.ILogListener
import com.zhidao.loglib.core.LogInfoManager
import com.zhjt.mogo_core_function_devatools.logcat.config.LogRecordConfig
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.CACHE_MAP_UPLOAD
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.CACHE_TRACE_UPLOAD
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.CLOSE_HD_MAP_TILE_FILE_LOG
@@ -41,10 +42,16 @@ import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companio
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.OPEN_HD_MAP_TILE_FILE_LOG
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.START_CATCH_LOG
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.STOP_CATCH_LOG
import com.zhjt.mogo_core_function_devatools.trace.TraceManager
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.UPLOAD_LOG_CAT_FILE
import com.zhjt.mogo_core_function_devatools.trace.TraceManager.Companion.traceManager
import com.zhjt.service_biz.BizConfig
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import java.io.File
import java.util.concurrent.TimeUnit.MINUTES
import java.util.concurrent.atomic.AtomicLong
@SuppressLint("StaticFieldLeak")
object MogoLogCatchManager : IMogoOnMessageListener<RemoteLogPushContent>, Handler.Callback,
@@ -62,6 +69,12 @@ object MogoLogCatchManager : IMogoOnMessageListener<RemoteLogPushContent>, Handl
private var logInfoManager: LogInfoManager? = null
private var mapCacheUpload = false
private val scope by lazy { CoroutineScope(Dispatchers.IO + SupervisorJob()) }
private val uploadThreshold by lazy { MINUTES.toMillis(1) } //全量日志的上传的安全时间,在此时间内,上传任务只会触发一次
private val lastUploadTime by lazy { AtomicLong(0) }
fun init(context: Context) {
mContext = context
MogoAiCloudSocketManager.getInstance(AbsMogoApplication.getApp().applicationContext)
@@ -159,6 +172,9 @@ object MogoLogCatchManager : IMogoOnMessageListener<RemoteLogPushContent>, Handl
}
}
}
UPLOAD_LOG_CAT_FILE -> {
uploadLogcat(obj.cmd.toIntOrNull())
}
else -> {
}
}
@@ -283,6 +299,35 @@ object MogoLogCatchManager : IMogoOnMessageListener<RemoteLogPushContent>, Handl
CallerAutoPilotControlManager.setEnableLog(false)
}
private fun uploadLogcat(timeType: Int?) {
if (timeType == null) return
val endTime = System.currentTimeMillis()
val startTime = when(timeType) {
LogRecordConfig.ALL_LOG_15_MINUTES -> endTime - MINUTES.toMillis(15)
LogRecordConfig.ALL_LOG_30_MINUTES -> endTime - MINUTES.toMillis(30)
LogRecordConfig.ALL_LOG_45_MINUTES -> endTime - MINUTES.toMillis(45)
LogRecordConfig.ALL_LOG_60_MINUTES -> endTime - MINUTES.toMillis(60)
LogRecordConfig.ALL_LOG_120_MINUTES -> endTime - MINUTES.toMillis(120)
LogRecordConfig.ALL_LOG_SAME_DAY -> endTime - (endTime % 86400000)
LogRecordConfig.ALL_LOG -> 0
else -> endTime
}
if (startTime < endTime) {
val now = System.currentTimeMillis()
val last = lastUploadTime.get()
if (last <= 0) {
lastUploadTime.set(System.currentTimeMillis())
}
if (last > 0 && (now - last) <= uploadThreshold) {
return
}
lastUploadTime.set(System.currentTimeMillis())
scope.launch {
LogcatManager.upload(startTime, endTime)
}
}
}
override fun onError(errorCount: Int) {
ThreadUtils.runOnUiThread {
TipToast.shortTip("日志抓取出现错误,出错数量:$errorCount")