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) } } }