Skip to content

Commit

Permalink
Merge fa29303 into 1730704
Browse files Browse the repository at this point in the history
  • Loading branch information
bengourley committed May 20, 2019
2 parents 1730704 + fa29303 commit 4fb7384
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Enhancements

* Disable ANR detection by default [#484](https://github.com/bugsnag/bugsnag-android/pull/484)

## 4.14.1 (2019-05-17)

### Bug fixes
Expand Down Expand Up @@ -85,7 +91,7 @@

* Fix cached error deserialisation where the Throwable has a cause
[#418](https://github.com/bugsnag/bugsnag-android/pull/418)

* Refactor error report deserialisation
[#419](https://github.com/bugsnag/bugsnag-android/pull/419)

Expand Down
4 changes: 4 additions & 0 deletions features/detect_anr.feature
Expand Up @@ -25,3 +25,7 @@ Scenario: Test ANR wait time can be set to under default time
Scenario: Test ANR wait time can be set to over default time
When I run "AppNotRespondingLongerThresholdScenario"
Then I should receive 0 requests

Scenario: Test does not capture ANRs by default
When I run "AppNotRespondingDefaultsScenario"
Then I should receive 0 requests
Expand Up @@ -42,10 +42,15 @@ class MainActivity : Activity() {
}

private fun prepareConfig(): Configuration {
val eventType = intent.getStringExtra("EVENT_TYPE")
val config = Configuration(intent.getStringExtra("BUGSNAG_API_KEY"))
val port = intent.getStringExtra("BUGSNAG_PORT")
config.setEndpoints("${findHostname()}:$port", "${findHostname()}:$port")
config.detectAnrs = false

// Added to stop override of the default ANR state
if (eventType != "AppNotRespondingDefaultsScenario") {
config.detectAnrs = false
}
return config
}

Expand Down
@@ -0,0 +1,21 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration

/**
* Stops the app from responding for a time period
*/
internal class AppNotRespondingDefaultsScenario(config: Configuration,
context: Context) : Scenario(config, context) {
init {
config.setAutoCaptureSessions(false)
}

override fun run() {
super.run()
Thread.sleep(6000)
}

}
4 changes: 2 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/AnrConfigTest.kt
@@ -1,7 +1,7 @@
package com.bugsnag.android

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.assertFalse
import org.junit.Test

class AnrConfigTest {
Expand All @@ -10,7 +10,7 @@ class AnrConfigTest {

@Test
fun testDetectAnrDefault() {
assertTrue(config.detectAnrs)
assertFalse(config.detectAnrs)
}

/**
Expand Down
13 changes: 6 additions & 7 deletions sdk/src/main/java/com/bugsnag/android/Configuration.java
Expand Up @@ -48,7 +48,7 @@ public class Configuration extends Observable implements Observer {
private boolean autoCaptureSessions = true;
private boolean automaticallyCollectBreadcrumbs = true;

private boolean detectAnrs = !Debug.isDebuggerConnected();
private boolean detectAnrs = false;
private long anrThresholdMs = 5000;

@NonNull
Expand Down Expand Up @@ -657,11 +657,10 @@ public boolean getDetectAnrs() {

/**
* Sets whether <a href="https://developer.android.com/topic/performance/vitals/anr">ANRs</a>
* should be reported to Bugsnag. By default, Bugsnag will record an ANR whenever the main
* thread has been blocked for 5000 milliseconds or longer, when no debugger is attached to
* the app.
* should be reported to Bugsnag. When enabled, Bugsnag will record an ANR whenever the main
* thread has been blocked for 5000 milliseconds or longer.
* <p/>
* If you wish to disable ANR detection, you should set this property to false; if you wish to
* If you wish to enable ANR detection, you should set this property to true; if you wish to
* configure the time threshold required to capture an ANR, you should use the
* {@link #setAnrThresholdMs(long)} property.
*
Expand All @@ -686,8 +685,8 @@ public long getAnrThresholdMs() {
* by Bugsnag. By default, Bugsnag will record an ANR whenever the main thread has been blocked
* for 5000 milliseconds or longer.
* <p/>
* If you wish to disable ANR detection completely, you should set the
* {@link #setDetectAnrs(boolean)} property to false.
* If you wish to enable ANR detection, you should set the {@link #setDetectAnrs(boolean)}
* property to true.
* <p/>
* Attempting to set this property to any value below 1000ms will result in the anrThresholdMs
* being set as 1000ms.
Expand Down

0 comments on commit 4fb7384

Please sign in to comment.