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