Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Jan 9, 2025
1 parent 1b03de7 commit 85bdbf5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open class BaseActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PreFirebaseProvider.initialize()
FirebaseApp.initializeApp(this)
Log.i(TAG, "onCreate - ${getProcessName()} - ${getImportance()}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,33 @@ class PreFirebaseProvider : ContentProvider(), UncaughtExceptionHandler {
private var defaultUncaughtExceptionHandler: UncaughtExceptionHandler? = null

companion object {
var expectedMessage: String? = null
private var defaultUncaughtExceptionHandler: UncaughtExceptionHandler? = null

/**
* Set an expected exception message. If the uncaught exception contains the given string, then
* the app will exit cleanly. Otherwise, it will propagate up to the default exception handler.
* Initializes the PreFirebaseProvider manually.
*/
var expectedMessage: String? = null
}
fun initialize() {
if (defaultUncaughtExceptionHandler == null) {
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(object : UncaughtExceptionHandler {
override fun uncaughtException(thread: Thread, throwable: Throwable) {
if (isExpected(throwable)) {
// Exit cleanly
exitProcess(0)
} else {
// Propagate up to the default exception handler
defaultUncaughtExceptionHandler?.uncaughtException(thread, throwable)
}
}

private fun isExpected(throwable: Throwable): Boolean =
expectedMessage?.let { throwable.message?.contains(it) } ?: false
})
}
}
}
override fun onCreate(): Boolean {
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(this)

return false
}

Expand Down

0 comments on commit 85bdbf5

Please sign in to comment.