Skip to content

Commit

Permalink
fix(log): disable ndk and anr warning message when plugins are excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
YYChen01988 committed Apr 18, 2023
2 parents 95fedbc + 24caf73 commit 300fcf5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Enhancements

* ANR or NDR detection warnings can be suppressed (using `enabledErrorTypes`) when plugin is excluded.
[#1832](https://github.com/bugsnag/bugsnag-android/pull/1832)

* Example app demonstrates global metadata.
[#1827](https://github.com/bugsnag/bugsnag-android/pull/1827)

Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
multi_test (0.1.2)
nokogiri (1.14.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.2-x86_64-darwin)
racc (~> 1.4)
optimist (3.0.1)
Expand Down Expand Up @@ -121,7 +119,6 @@ GEM
rexml

PLATFORMS
arm64-darwin-22
x86_64-darwin-20

DEPENDENCIES
Expand Down
2 changes: 1 addition & 1 deletion bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<ID>SwallowedException:DeviceDataCollector.kt$DeviceDataCollector$catch (exception: Exception) { logger.w("Could not get locationStatus") }</ID>
<ID>SwallowedException:DeviceIdFilePersistence.kt$DeviceIdFilePersistence$catch (exc: OverlappingFileLockException) { Thread.sleep(FILE_LOCK_WAIT_MS) }</ID>
<ID>SwallowedException:JsonHelperTest.kt$JsonHelperTest$catch (e: IllegalArgumentException) { didThrow = true }</ID>
<ID>SwallowedException:PluginClient.kt$PluginClient$catch (exc: ClassNotFoundException) { logger.d("Plugin '$clz' is not on the classpath - functionality will not be enabled.") null }</ID>
<ID>SwallowedException:PluginClient.kt$PluginClient$catch (exc: ClassNotFoundException) { if (isWarningEnabled) { logger.d("Plugin '$clz' is not on the classpath - functionality will not be enabled.") } null }</ID>
<ID>ThrowsCount:JsonHelper.kt$JsonHelper$ fun jsonToLong(value: Any?): Long?</ID>
<ID>TooManyFunctions:ConfigInternal.kt$ConfigInternal : CallbackAwareMetadataAwareUserAwareFeatureFlagAware</ID>
<ID>TooManyFunctions:DeviceDataCollector.kt$DeviceDataCollector</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal class PluginClient(
}

private val plugins: Set<Plugin>

private val ndkPlugin = instantiatePlugin(NDK_PLUGIN, immutableConfig.enabledErrorTypes.ndkCrashes)
private val anrPlugin = instantiatePlugin(ANR_PLUGIN, immutableConfig.enabledErrorTypes.anrs)
private val rnPlugin = instantiatePlugin(RN_PLUGIN, immutableConfig.enabledErrorTypes.unhandledRejections)
Expand All @@ -32,70 +31,68 @@ internal class PluginClient(
plugins = set.toSet()
}

private fun instantiatePlugin(clz: String, isWarningEnable: Boolean): Plugin? {
private fun instantiatePlugin(clz: String, isWarningEnabled: Boolean): Plugin? {
return try {
val pluginClz = Class.forName(clz)
pluginClz.newInstance() as Plugin
} catch (exc: ClassNotFoundException) {
if (isWarningEnable) {
if (isWarningEnabled) {
logger.d("Plugin '$clz' is not on the classpath - functionality will not be enabled.")
}
null

} catch (exc: Throwable) {
logger.e("Failed to load plugin '$clz'", exc)
null
}
}

fun getNdkPlugin(): Plugin? = ndkPlugin

fun getNdkPlugin(): Plugin? = ndkPlugin

fun loadPlugins(client: Client) {
plugins.forEach { plugin ->
try {
loadPluginInternal(plugin, client)
} catch (exc: Throwable) {
logger.e("Failed to load plugin $plugin, continuing with initialisation.", exc)
fun loadPlugins(client: Client) {
plugins.forEach { plugin ->
try {
loadPluginInternal(plugin, client)
} catch (exc: Throwable) {
logger.e("Failed to load plugin $plugin, continuing with initialisation.", exc)
}
}
}
}

fun setAutoNotify(client: Client, autoNotify: Boolean) {
setAutoDetectAnrs(client, autoNotify)
fun setAutoNotify(client: Client, autoNotify: Boolean) {
setAutoDetectAnrs(client, autoNotify)

if (autoNotify) {
ndkPlugin?.load(client)
} else {
ndkPlugin?.unload()
if (autoNotify) {
ndkPlugin?.load(client)
} else {
ndkPlugin?.unload()
}
}
}

fun setAutoDetectAnrs(client: Client, autoDetectAnrs: Boolean) {
if (autoDetectAnrs) {
anrPlugin?.load(client)
} else {
anrPlugin?.unload()
fun setAutoDetectAnrs(client: Client, autoDetectAnrs: Boolean) {
if (autoDetectAnrs) {
anrPlugin?.load(client)
} else {
anrPlugin?.unload()
}
}
}

fun findPlugin(clz: Class<*>): Plugin? = plugins.find { it.javaClass == clz }
fun findPlugin(clz: Class<*>): Plugin? = plugins.find { it.javaClass == clz }

private fun loadPluginInternal(plugin: Plugin, client: Client) {
val name = plugin.javaClass.name
val errorTypes = immutableConfig.enabledErrorTypes
private fun loadPluginInternal(plugin: Plugin, client: Client) {
val name = plugin.javaClass.name
val errorTypes = immutableConfig.enabledErrorTypes

// only initialize NDK/ANR plugins if automatic detection enabled
if (name == NDK_PLUGIN) {
if (errorTypes.ndkCrashes) {
plugin.load(client)
}
} else if (name == ANR_PLUGIN) {
if (errorTypes.anrs) {
// only initialize NDK/ANR plugins if automatic detection enabled
if (name == NDK_PLUGIN) {
if (errorTypes.ndkCrashes) {
plugin.load(client)
}
} else if (name == ANR_PLUGIN) {
if (errorTypes.anrs) {
plugin.load(client)
}
} else {
plugin.load(client)
}
} else {
plugin.load(client)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ open class BaseCrashyActivity : AppCompatActivity() {
anrFromCXX()
showSnackbar()
}

}

override fun onResume() {
Expand Down

0 comments on commit 300fcf5

Please sign in to comment.