Skip to content

Commit

Permalink
fix(anr): only set ANR unwind function if the bugsnag-plugin-android-…
Browse files Browse the repository at this point in the history
…anr.so was loaded successfully
  • Loading branch information
lemnik committed Jun 13, 2024
1 parent d5ac07d commit 6185b9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Corrected the behavior when `Bugsnag.startSession` is called when `config.autoTrackSessions=true`, the first automatic session will now be correctly discarded
[#2033](https://github.com/bugsnag/bugsnag-android/pull/2033)
* Avoid a possible crash in the ANR plugin when the native ANR library failed to load.
[#2039](https://github.com/bugsnag/bugsnag-android/pull/2039)

## 6.5.0 (2024-05-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,25 @@ internal class AnrPlugin : Plugin {
}

private fun performOneTimeSetup(client: Client) {
libraryLoader.loadLibrary("bugsnag-plugin-android-anr", client) {
val isLoaded = libraryLoader.loadLibrary("bugsnag-plugin-android-anr", client) {
val error = it.errors[0]
error.errorClass = "AnrLinkError"
error.errorMessage = LOAD_ERR_MSG
true
}
@Suppress("UNCHECKED_CAST")
val clz = loadClass("com.bugsnag.android.NdkPlugin") as Class<Plugin>?
if (clz != null) {
val ndkPlugin = client.getPlugin(clz)
if (ndkPlugin != null) {
val method = ndkPlugin.javaClass.getMethod("getSignalUnwindStackFunction")

@Suppress("UNCHECKED_CAST")
val function = method.invoke(ndkPlugin) as Long
setUnwindFunction(function)

if (isLoaded) {
@Suppress("UNCHECKED_CAST")
val clz = loadClass("com.bugsnag.android.NdkPlugin") as Class<Plugin>?
if (clz != null) {
val ndkPlugin = client.getPlugin(clz)
if (ndkPlugin != null) {
val method = ndkPlugin.javaClass.getMethod("getSignalUnwindStackFunction")

@Suppress("UNCHECKED_CAST")
val function = method.invoke(ndkPlugin) as Long
setUnwindFunction(function)
}
}
}
}
Expand Down

0 comments on commit 6185b9f

Please sign in to comment.