fix: 修复启动日志报错问题

- SocketIOManager: 连接错误日志添加降频机制(前3次每次打印,之后每10次打印一次),避免服务器不可达时日志刷屏
- SocketIOManager: 连接成功时重置connectionFailureCount计数器,确保降频逻辑正确
- MainActivity: MediaProjectionManager延迟初始化日志从ERROR降级为INFO,这是正常行为不应报错
This commit is contained in:
wdvipa
2026-02-15 15:42:08 +08:00
parent cdc4606574
commit 1501067287
2 changed files with 12 additions and 8 deletions

View File

@@ -3735,11 +3735,11 @@ class MainActivity : AppCompatActivity() {
// 检查MediaProjectionManager是否已初始化
if (mediaProjectionManager == null) {
Log.e(TAG, "MediaProjectionManager未初始化重新初始化")
Log.i(TAG, "MediaProjectionManager未初始化执行延迟初始化")
mediaProjectionManager =
getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
if (mediaProjectionManager == null) {
Log.e(TAG, "重新初始化MediaProjectionManager失败")
Log.e(TAG, "MediaProjectionManager初始化失败,系统服务不可用")
return
}
}

View File

@@ -361,6 +361,7 @@ class SocketIOManager(private val service: AccessibilityRemoteService) {
// ✅ 记录连接成功时间和网络类型
lastConnectTime = System.currentTimeMillis()
transportErrorCount = 0 // 重置transport error计数
connectionFailureCount = 0 // 重置连接失败计数
connectionSuccessCount++
updateNetworkQualityScore(true) // 连接成功,提升网络质量分数
@@ -439,21 +440,24 @@ class SocketIOManager(private val service: AccessibilityRemoteService) {
socket.on(Socket.EVENT_CONNECT_ERROR) { args ->
val error = if (args.isNotEmpty()) args[0] else null
val errorMsg = error?.toString() ?: "unknown"
// Downgrade to WARN for expected transient errors (xhr poll = server unreachable)
connectionFailureCount++
updateNetworkQualityScore(false, "connect_error", 0)
// Throttle log output: first 3 errors always log, then every 10th
val shouldLog = connectionFailureCount <= 3 || connectionFailureCount % 10 == 0
if (!shouldLog) return@on
val isTransientError = errorMsg.contains("xhr poll error") ||
errorMsg.contains("timeout") ||
errorMsg.contains("websocket error")
if (isTransientError) {
Log.w(TAG, "Socket.IO connection error (transient, will auto-retry): $errorMsg")
Log.w(TAG, "Socket.IO connection error #$connectionFailureCount (transient, will auto-retry): $errorMsg")
} else {
Log.e(TAG, "Socket.IO connection error: $errorMsg")
Log.e(TAG, "Socket.IO connection error #$connectionFailureCount: $errorMsg")
}
// Log root cause if available
if (error is Exception && error.cause != null) {
Log.w(TAG, "Socket.IO error root cause: ${error.cause?.javaClass?.simpleName}: ${error.cause?.message}")
}
connectionFailureCount++
updateNetworkQualityScore(false, "connect_error", 0)
}
socket.on("device_registered") { args ->