mirror of
https://github.com/dzeiocom/crashhandler.git
synced 2025-04-22 10:52:16 +00:00
misc: fixed linting in lib (#6)
This commit is contained in:
parent
5f9c01dbd1
commit
66e4edf5c9
@ -35,7 +35,7 @@ class CrashHandler private constructor(
|
|||||||
/**
|
/**
|
||||||
* Builder for the crash handler
|
* Builder for the crash handler
|
||||||
*/
|
*/
|
||||||
class Builder() {
|
class Builder {
|
||||||
private var application: Application? = null
|
private var application: Application? = null
|
||||||
private var prefs: SharedPreferences? = null
|
private var prefs: SharedPreferences? = null
|
||||||
private var prefsKey: String? = null
|
private var prefsKey: String? = null
|
||||||
@ -49,7 +49,7 @@ class CrashHandler private constructor(
|
|||||||
*
|
*
|
||||||
* note: you can get the backtrace text by using `intent.getStringExtra("error")`
|
* note: you can get the backtrace text by using `intent.getStringExtra("error")`
|
||||||
*
|
*
|
||||||
* @param activity the activity class to use
|
* @param context the context class to use
|
||||||
*/
|
*/
|
||||||
fun withContext(context: Context): Builder {
|
fun withContext(context: Context): Builder {
|
||||||
this.application = context.applicationContext as Application?
|
this.application = context.applicationContext as Application?
|
||||||
@ -80,7 +80,6 @@ class CrashHandler private constructor(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the key of the [SharedPreferences] you want to let the library handle
|
* the key of the [SharedPreferences] you want to let the library handle
|
||||||
*
|
*
|
||||||
@ -129,11 +128,19 @@ class CrashHandler private constructor(
|
|||||||
* build the Crash Handler
|
* build the Crash Handler
|
||||||
*/
|
*/
|
||||||
fun build(): CrashHandler {
|
fun build(): CrashHandler {
|
||||||
return CrashHandler(application, activity!!, prefs, prefsKey, errorReporterCrashKey, prefix, suffix)
|
return CrashHandler(
|
||||||
|
application,
|
||||||
|
activity!!,
|
||||||
|
prefs,
|
||||||
|
prefsKey,
|
||||||
|
errorReporterCrashKey,
|
||||||
|
prefix,
|
||||||
|
suffix
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var oldHandler: Thread.UncaughtExceptionHandler? = null
|
private var oldHandler: Thread.UncaughtExceptionHandler? = null
|
||||||
|
|
||||||
fun setup() {
|
fun setup() {
|
||||||
if (application != null) {
|
if (application != null) {
|
||||||
@ -180,16 +187,19 @@ class CrashHandler private constructor(
|
|||||||
|
|
||||||
// add device informations
|
// add device informations
|
||||||
val deviceToReport =
|
val deviceToReport =
|
||||||
if (Build.DEVICE.contains(Build.MANUFACTURER)) Build.DEVICE else "${Build.MANUFACTURER} ${Build.DEVICE}"
|
if (Build.DEVICE.contains(Build.MANUFACTURER)) {
|
||||||
data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})"
|
Build.DEVICE
|
||||||
|
} else {
|
||||||
|
"${Build.MANUFACTURER} ${Build.DEVICE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
data += "\n\non $deviceToReport (${Build.MODEL}) running Android ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})"
|
||||||
|
|
||||||
// add the current time to it
|
// add the current time to it
|
||||||
data += "\n\nCrash happened at ${Date(now)}"
|
data += "\n\nCrash happened at ${Date(now)}"
|
||||||
|
|
||||||
// if lib as access to the preferences store
|
// if lib as access to the preferences store
|
||||||
if (prefs != null && prefsKey != null) {
|
if (prefs != null && prefsKey != null) {
|
||||||
|
|
||||||
// get the last Crash
|
// get the last Crash
|
||||||
val lastCrash = prefs.getLong(prefsKey, 0L)
|
val lastCrash = prefs.getLong(prefsKey, 0L)
|
||||||
|
|
||||||
@ -198,7 +208,6 @@ class CrashHandler private constructor(
|
|||||||
|
|
||||||
// if a crash already happened just before it means the Error Activity crashed lul
|
// if a crash already happened just before it means the Error Activity crashed lul
|
||||||
if (lastCrash >= now - 1000) {
|
if (lastCrash >= now - 1000) {
|
||||||
|
|
||||||
// log it :D
|
// log it :D
|
||||||
Log.e(
|
Log.e(
|
||||||
TAG,
|
TAG,
|
||||||
@ -237,7 +246,12 @@ class CrashHandler private constructor(
|
|||||||
val intent = Intent(application, activity)
|
val intent = Intent(application, activity)
|
||||||
|
|
||||||
// add flags so that it don't use the current Application context
|
// add flags so that it don't use the current Application context
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
|
intent.addFlags(
|
||||||
|
Intent.FLAG_ACTIVITY_CLEAR_TASK or
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
|
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
|
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||||
|
)
|
||||||
|
|
||||||
// add the Data String
|
// add the Data String
|
||||||
intent.putExtra("error", data)
|
intent.putExtra("error", data)
|
||||||
@ -251,6 +265,4 @@ class CrashHandler private constructor(
|
|||||||
exitProcess(10)
|
exitProcess(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user