XuqmGroup-AndroidSDK/sdk-bugcollect/src/main/java/com/xuqm/sdk/bugcollect/CrashCapture.kt
XuqmGroup 77fef3a38b refactor(bugcollect): 注册与 URL 完全解耦
注册 UncaughtExceptionHandler 不需要 URL:
- CrashCapture.start 移除 logApiUrl 参数,只需 appContext + appKey
- LogStorage.saveCrash 移除 logApiUrl,崩溃文件不再存储 URL
- LogQueue.uploadPendingCrashes 上传时直接取 XuqmSDK.bugCollectApiUrl,
  URL 为 null 则跳过(下次启动重试),不依赖崩溃文件里的历史 URL
- BugCollect.startCrashCapture 移除 URL 构造逻辑
- BugCollectInitProvider Phase 1 纯粹只注册,彻底消除对 platformUrl 的依赖,
  版本兼容问题从根本上消失

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 10:18:08 +08:00

21 行
700 B
Kotlin

package com.xuqm.sdk.bugcollect
import android.content.Context
import com.xuqm.sdk.bugcollect.internal.LogStorage
internal object CrashCapture {
@Volatile private var started = false
/** 注册全局崩溃拦截器,只需 appContext + appKey,不依赖上传 URL。 */
fun start(appContext: Context, appKey: String, getUserId: () -> String?) {
if (started) return
started = true
val prev = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
LogStorage.saveCrash(appContext, throwable, appKey, getUserId())
prev?.uncaughtException(thread, throwable)
}
}
}