Skip to content

Commit 1110c3e

Browse files
committed
more
1 parent 85bdbf5 commit 1110c3e

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

firebase-crashlytics/test-app/src/main/kotlin/com/google/firebase/testing/crashlytics/PreFirebaseProvider.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,27 @@ class PreFirebaseProvider : ContentProvider(), UncaughtExceptionHandler {
3030
var expectedMessage: String? = null
3131
private var defaultUncaughtExceptionHandler: UncaughtExceptionHandler? = null
3232

33-
/**
34-
* Initializes the PreFirebaseProvider manually.
35-
*/
3633
fun initialize() {
37-
if (defaultUncaughtExceptionHandler == null) {
34+
if (defaultUncaughtExceptionHandler == null ||
35+
defaultUncaughtExceptionHandler !is PreFirebaseExceptionHandler) {
3836
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
39-
Thread.setDefaultUncaughtExceptionHandler(object : UncaughtExceptionHandler {
40-
override fun uncaughtException(thread: Thread, throwable: Throwable) {
41-
if (isExpected(throwable)) {
42-
// Exit cleanly
43-
exitProcess(0)
44-
} else {
45-
// Propagate up to the default exception handler
46-
defaultUncaughtExceptionHandler?.uncaughtException(thread, throwable)
47-
}
48-
}
37+
Thread.setDefaultUncaughtExceptionHandler(PreFirebaseExceptionHandler(defaultUncaughtExceptionHandler))
38+
}
39+
}
4940

50-
private fun isExpected(throwable: Throwable): Boolean =
51-
expectedMessage?.let { throwable.message?.contains(it) } ?: false
52-
})
41+
private class PreFirebaseExceptionHandler(
42+
private val delegate: UncaughtExceptionHandler?
43+
) : UncaughtExceptionHandler {
44+
override fun uncaughtException(thread: Thread, throwable: Throwable) {
45+
if (expectedMessage != null && throwable.message?.contains(expectedMessage!!) == true) {
46+
exitProcess(0)
47+
} else {
48+
delegate?.uncaughtException(thread, throwable)
49+
}
5350
}
5451
}
5552
}
53+
5654
override fun onCreate(): Boolean {
5755
return false
5856
}

0 commit comments

Comments
 (0)