Skip to content

Commit

Permalink
feat: set min check interval to 1000ms, avoid throwing exception if l…
Browse files Browse the repository at this point in the history
…ower value passed
  • Loading branch information
fractalwrench committed Mar 19, 2019
1 parent c336439 commit fdef465
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
6 changes: 3 additions & 3 deletions sdk/src/androidTest/java/com/bugsnag/android/AnrConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnrConfigTest {
}

/**
* Verifies that attempts to set the ANR threshold below 100ms set the value as 100ms
* Verifies that attempts to set the ANR threshold below 1000ms set the value as 1000ms
*/
@Test
fun testAnrThresholdMs() {
Expand All @@ -24,9 +24,9 @@ class AnrConfigTest {
config.anrThresholdMs = 10000
assertEquals(10000, config.anrThresholdMs)

arrayOf(100, 99, 0, -5, Long.MIN_VALUE).forEach {
arrayOf(1000, 999, 0, -5, Long.MIN_VALUE).forEach {
config.anrThresholdMs = it
assertEquals(100, config.anrThresholdMs)
assertEquals(1000, config.anrThresholdMs)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,4 @@ class BlockedThreadDetectorTest {
fun testInvalidDelegate() {
BlockedThreadDetector(1, 1, looper, null)
}

@Test(expected = IllegalArgumentException::class)
fun testExcessiveCheckInterval() {
BlockedThreadDetector(100, 1000, looper) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
final class BlockedThreadDetector {

private static final int DEFAULT_CHECK_INTERVAL_MS = 1000;
static final int MIN_CHECK_INTERVAL_MS = 1000;

interface Delegate {

Expand All @@ -36,16 +36,15 @@ interface Delegate {
BlockedThreadDetector(long blockedThresholdMs,
Looper looper,
Delegate delegate) {
this(blockedThresholdMs, DEFAULT_CHECK_INTERVAL_MS, looper, delegate);
this(blockedThresholdMs, MIN_CHECK_INTERVAL_MS, looper, delegate);
}

BlockedThreadDetector(long blockedThresholdMs,
long checkIntervalMs,
Looper looper,
Delegate delegate) {
if ((blockedThresholdMs <= 0 || checkIntervalMs <= 0
|| looper == null || delegate == null
|| checkIntervalMs > blockedThresholdMs)) {
|| looper == null || delegate == null)) {
throw new IllegalArgumentException();
}
this.blockedThresholdMs = blockedThresholdMs;
Expand Down
7 changes: 4 additions & 3 deletions sdk/src/main/java/com/bugsnag/android/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,15 @@ public long getAnrThresholdMs() {
* If you wish to disable ANR detection completely, you should set the
* {@link #setDetectAnrs(boolean)} property to false.
* <p/>
* Attempting to set this property to any value below 100ms will result in the anrThresholdMs
* being set as 100ms.
* Attempting to set this property to any value below 1000ms will result in the anrThresholdMs
* being set as 1000ms.
*
* @param anrThresholdMs the threshold in ms at which ANRs should be detected
* @see #setDetectAnrs(boolean)
*/
public void setAnrThresholdMs(long anrThresholdMs) {
this.anrThresholdMs = anrThresholdMs < 100 ? 100 : anrThresholdMs;
this.anrThresholdMs = anrThresholdMs < BlockedThreadDetector.MIN_CHECK_INTERVAL_MS
? BlockedThreadDetector.MIN_CHECK_INTERVAL_MS : anrThresholdMs;
}

/**
Expand Down

0 comments on commit fdef465

Please sign in to comment.