[6.0.0][全量日志] 全量日志添加状态记录,日志中心由【导出全量日志】改为【上传全量日志】

This commit is contained in:
renwj
2023-08-28 19:47:08 +08:00
parent 7a7593933b
commit b1e6d79b9f
6 changed files with 98 additions and 31 deletions

View File

@@ -215,7 +215,7 @@ ext {
btrace : "com.bytedance.btrace:rhea-core:2.0.0",
mofang_runtime : "com.mogo.eagle.core.mofang:runtime:2.0.6",
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.8",
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.9",
// 安全证书
passport_secret : "com.zhidaoauto:sdk-java:1.0.5-SNAPSHOT",

View File

@@ -1,6 +1,7 @@
package com.zhjt.mogo_core_function_devatools.logcat
import android.content.*
import android.os.Build
import android.os.Process
import android.os.SystemClock
import android.util.Log
@@ -10,6 +11,9 @@ import com.mogo.commons.AbsMogoApplication
import com.mogo.core.log.record.*
import com.mogo.core.log.record.config.*
import com.mogo.core.log.record.config.crash.*
import com.mogo.core.log.record.config.state.IStateProvider
import com.mogo.core.log.record.model.UploadError
import com.mogo.eagle.core.data.app.AppConfigInfo
import com.mogo.eagle.core.function.api.devatools.logcat.*
import com.zhidao.loglib.bean.RemoteLogPushContent
import com.zhjt.mogo_core_function_devatools.logcat.config.LogRecordConfig
@@ -43,6 +47,62 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider,
.recordDir(File(context.getExternalFilesDir(null), "logcat"))
.pid(Process.myPid())
.generateZipDir(zipDir.absolutePath)
.stateProvider(object : IStateProvider {
override fun provide(divider:String?): Map<String, Any?> {
return mutableMapOf<String, Any?>().also { itx ->
itx["build_sdk_version"] = Build.VERSION.SDK_INT
itx["build_device"] = Build.DEVICE
itx["build_host"] = Build.HOST
itx["build_id"] = Build.ID
itx["build_host"] = Build.HOST
itx["build_brand"] = Build.BRAND
itx["build_model"] = Build.MODEL
itx["build_product"] = Build.PRODUCT
itx["build_board"] = Build.BOARD
itx["build_bootloader"] = Build.BOOTLOADER
itx["${divider}-1"] = divider
itx["应用名称"] = AppConfigInfo.appName
itx["应用版本名称"] = AppConfigInfo.appVersionName
itx["应用版本号"] = AppConfigInfo.appVersionCode
itx["渠道"] = AppConfigInfo.flavor
itx["GIT分支"] = AppConfigInfo.workingBranchName
itx["GIT分支HASH"] = AppConfigInfo.workingBranchHash
itx["${divider}-2"] = divider
itx["MAP-SDK版本"] = AppConfigInfo.mapSdkVersion
itx["MAP-OPT-SDK版本"] = AppConfigInfo.mapSdkOptVersion
itx["ADAS-SDK版本"] = AppConfigInfo.adasSdkVersion
itx["${divider}-3"] = divider
itx["OBU-SDk版本"] = AppConfigInfo.obuSdkVersion
itx["OBU-INFO"] = AppConfigInfo.obuInfo
itx["${divider}-4"] = divider
itx["数字版权ID"] = AppConfigInfo.widevineIDMd5
itx["设备唯一标识"] = AppConfigInfo.uniqueDeviceId
itx["中台分配的SN"] = AppConfigInfo.mogoSN
itx["中台分配的令牌"] = AppConfigInfo.mogoToken
itx["当前网络连接模式"] = AppConfigInfo.netMode
itx["网络是否正常"] = AppConfigInfo.isConnectNet
itx["Socket是否正常"] = AppConfigInfo.isConnectSocket
itx["ADAS连接是否正常"] = AppConfigInfo.isConnectAutopilot
itx["OBU连接是否正常"] = AppConfigInfo.isConnectObu
itx["连接工控机状态描述"] = AppConfigInfo.connectStatusDescribe
itx["${divider}-5"] = divider
itx["是否司机端"] = AppConfigInfo.isDriver
itx["是否是乘客端"] = !AppConfigInfo.isDriver
if (!AppConfigInfo.isDriver) {
itx["当前车机是乘客屏对应的司机屏SN"] = AppConfigInfo.serverSn
}
itx["司乘屏连接状态"] = AppConfigInfo.isConnectedNetty
itx["${divider}-6"] = divider
itx["车牌号"] = AppConfigInfo.plateNumber
itx["mac"] = AppConfigInfo.iPCMacAddress
itx["docker版本"] = AppConfigInfo.dockerVersion
itx["协议版本号"] = AppConfigInfo.protocolVersionNumber
itx["${divider}-7"] = divider
itx["角色"] = AppConfigInfo.role
}
}
})
.crashConfig(CrashConfig.Builder()
.enabled(true)
.crashDir(File(context.getExternalFilesDir(null), "logcat/crash"))
@@ -119,6 +179,13 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider,
return LogcatManager.export()
}
override fun upload(): Unit = runBlocking {
val state = LogcatManager.upload(0, System.currentTimeMillis())
if (state is UploadError) {
throw AssertionError(state.toString())
}
}
override fun testJavaCrash(runOnNewThread: Boolean) {
LogcatManager.testJavaCrash(runOnNewThread)
}

View File

@@ -8,10 +8,11 @@ import com.zhidao.cosupload.callback.CosStatusCallback
import com.zhidao.cosupload.callback.CosStatusCallbackManager
import com.zhidao.cosupload.model.CallbackData
import com.zhidao.loglib.upload.UploadManager
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
internal class LogRecordUploader : ILogcatUploader {
@@ -20,10 +21,10 @@ internal class LogRecordUploader : ILogcatUploader {
private const val TAG = "LogRecordUploader"
}
@OptIn(ExperimentalCoroutinesApi::class)
override suspend fun upload(startTime: Long, endTime: Long, generatedZipPath: String): UploadState =
channelFlow {
flow {
Log.d(TAG, "---- 开始上传 --- 1 ---")
val channel = Channel<UploadState>()
CosStatusCallbackManager.getInstance().register(object : CosStatusCallback {
override fun onStartUpload(data: CallbackData?) {
@@ -35,7 +36,7 @@ internal class LogRecordUploader : ILogcatUploader {
override fun uploadCosCompleted(data: CallbackData?) {
if (data?.localPath == generatedZipPath) {
Log.d(TAG, "---- uploadCosCompleted ---: $data")
trySend(UploadSuccess)
channel.trySend(UploadSuccess)
CosStatusCallbackManager.getInstance().unregister(this)
}
}
@@ -43,7 +44,7 @@ internal class LogRecordUploader : ILogcatUploader {
override fun uploadCosFailed(data: CallbackData?) {
if (data?.localPath == generatedZipPath) {
Log.d(TAG, "---- uploadCosFailed ---: $data")
trySend(UploadError(Reason(data.exception)))
channel.trySend(UploadError(Reason(data.exception)))
CosStatusCallbackManager.getInstance().unregister(this)
}
}
@@ -58,8 +59,13 @@ internal class LogRecordUploader : ILogcatUploader {
UploadManager.getInstance().uploadSingleFile(generatedZipPath)
} catch (t: Throwable) {
Log.d(TAG, "---- 上传失败 ---: ${t.message}")
trySend(UploadError(Reason(t.message ?: "")))
channel.send(UploadError(Reason(t.message ?: "")))
}
}.flowOn(ThreadUtils.getIoPool().asCoroutineDispatcher()).firstOrNull() ?: UploadError(Reason("UnKnown reason"))
val iterator = channel.iterator()
while (iterator.hasNext()) {
val next = iterator.next()
emit(next)
}
}.flowOn(ThreadUtils.getIoPool().asCoroutineDispatcher()).filter { it is UploadError || it == UploadSuccess }.first()
}

View File

@@ -1381,27 +1381,19 @@ internal class DebugSettingView @JvmOverloads constructor(
v.visibility = View.INVISIBLE
logLoadingView?.visibility = View.VISIBLE
v.scope.launch(Dispatchers.IO) {
val file = CallerDevaToolsManager.logcat()?.export()
if (file != null && file.exists()) {
withContext(Dispatchers.Main) {
var activity = AppStateManager.currentActivity()
while (activity == null) {
delay(2000)
activity = AppStateManager.currentActivity()
if (activity != null) {
break
}
}
activity?.startActivity(Intent.createChooser(Intent().also {
it.action = Intent.ACTION_SEND
it.type = "application/zip"
it.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(activity, "${activity.packageName}.fileProvider", file))
}, "分享全量日志压缩包到"))
}
} else {
ToastUtils.showShort("全量日志压缩文件生成失败")
var isUploadSuccess = false
try {
CallerDevaToolsManager.logcat()?.upload()
isUploadSuccess = true
} catch (t: Throwable) {
t.printStackTrace()
}
withContext(Dispatchers.Main) {
if (isUploadSuccess) {
ToastUtils.showShort("上传成功")
} else {
ToastUtils.showShort("上传失败")
}
logLoadingView?.visibility = View.INVISIBLE
exportAllLogs?.visibility = View.VISIBLE
}

View File

@@ -2246,7 +2246,7 @@
android:layout_gravity="center">
<TextView
android:text="正在压缩全量日志,请稍候"
android:text="正在上传,请稍侯..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
@@ -2265,7 +2265,7 @@
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="20dip"
android:text="导出全量日志"
android:text="上传全量日志"
android:gravity="center"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip" />

View File

@@ -13,6 +13,8 @@ interface IMoGoLogRecordProvider {
fun export(): File?
fun upload()
fun testJavaCrash(runOnNewThread: Boolean)
fun testNativeCrash(runOnNewThread: Boolean)