Skip to content

Commit

Permalink
Merge pull request #2039 from bugsnag/lemnik/safe-set-unwind
Browse files Browse the repository at this point in the history
Only set ANR unwind function if the bugsnag-plugin-android-anr.so was loaded successfully
  • Loading branch information
lemnik authored Jun 19, 2024
2 parents 02dfd6e + 3f93a04 commit b9f5560
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 @@ -11,6 +11,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 b9f5560

Please sign in to comment.