2021-07-11 12:24:35 +00:00
|
|
|
package awaisomereport
|
2020-07-01 17:08:28 +00:00
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
import android.app.Application
|
2020-07-01 17:08:28 +00:00
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
class CrashReporter private constructor(application: Application) : Thread.UncaughtExceptionHandler {
|
2020-07-01 17:08:28 +00:00
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
private val crashHandler: CrashHandler?
|
|
|
|
private var startAttempted = false
|
|
|
|
private var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
2021-03-21 13:50:23 +00:00
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
init {
|
|
|
|
crashHandler = CrashHandler(application)
|
2020-07-01 17:08:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
fun start() {
|
|
|
|
if (startAttempted) return
|
|
|
|
defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
|
|
|
Thread.setDefaultUncaughtExceptionHandler(this)
|
|
|
|
startAttempted = true
|
2020-07-01 17:08:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
override fun uncaughtException(t: Thread, exception: Throwable) {
|
|
|
|
if (crashHandler == null) {
|
|
|
|
defaultExceptionHandler?.uncaughtException(t, exception)
|
|
|
|
return
|
2020-07-01 17:08:28 +00:00
|
|
|
}
|
2021-07-11 12:24:35 +00:00
|
|
|
crashHandler.uncaughtException(t, exception, defaultExceptionHandler ?: return)
|
2020-07-01 17:08:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 12:24:35 +00:00
|
|
|
companion object {
|
|
|
|
@Volatile
|
|
|
|
private var INSTANCE: CrashReporter? = null
|
|
|
|
|
|
|
|
fun getInstance(application: Application): CrashReporter {
|
|
|
|
return INSTANCE ?: synchronized(this) {
|
|
|
|
CrashReporter(application).also { INSTANCE = it }
|
|
|
|
}
|
2020-07-01 17:08:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-11 12:24:35 +00:00
|
|
|
}
|