-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: populate app.isLaunching field in JVM events
- Loading branch information
1 parent
4855410
commit 91d8260
Showing
11 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 35 additions & 2 deletions
37
bugsnag-android-core/src/main/java/com/bugsnag/android/LaunchCrashTracker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
package com.bugsnag.android | ||
|
||
class LaunchCrashTracker { | ||
} | ||
import java.util.concurrent.RejectedExecutionException | ||
import java.util.concurrent.ScheduledThreadPoolExecutor | ||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
/** | ||
* Tracks whether the app is currently in its launch period. This creates a timer of | ||
* configuration.launchDurationMillis, after which which the launch period is considered | ||
* complete. If this value is zero, then the user must manually call markLaunchCompleted(). | ||
*/ | ||
internal class LaunchCrashTracker(config: ImmutableConfig) { | ||
|
||
private val launching = AtomicBoolean(true) | ||
private val executor = ScheduledThreadPoolExecutor(1) | ||
|
||
init { | ||
val delay = config.launchDurationMillis | ||
|
||
if (delay > 0) { | ||
executor.executeExistingDelayedTasksAfterShutdownPolicy = false | ||
try { | ||
executor.schedule({ markLaunchCompleted() }, delay, TimeUnit.MILLISECONDS) | ||
} catch (ignored: RejectedExecutionException) { | ||
// ignore v. unlikely rejection failure on new executor | ||
} | ||
} | ||
} | ||
|
||
fun markLaunchCompleted() { | ||
executor.shutdown() | ||
launching.set(false) | ||
} | ||
|
||
fun isLaunching() = launching.get() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 48 additions & 2 deletions
50
bugsnag-android-core/src/test/java/com/bugsnag/android/LaunchCrashTrackerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
package com.bugsnag.android | ||
|
||
import org.junit.Assert.* | ||
import com.bugsnag.android.BugsnagTestUtils.convert | ||
import com.bugsnag.android.BugsnagTestUtils.generateConfiguration | ||
import com.bugsnag.android.BugsnagTestUtils.generateImmutableConfig | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class LaunchCrashTrackerTest | ||
class LaunchCrashTrackerTest { | ||
|
||
@Test | ||
fun defaultLaunchPeriodManualMark() { | ||
val tracker = LaunchCrashTracker(generateImmutableConfig()) | ||
assertTrue(tracker.isLaunching()) | ||
tracker.markLaunchCompleted() | ||
assertFalse(tracker.isLaunching()) | ||
} | ||
|
||
@Test | ||
fun zeroLaunchPeriodManualMark() { | ||
val tracker = LaunchCrashTracker( | ||
convert( | ||
generateConfiguration().apply { | ||
launchDurationMillis = 0 | ||
} | ||
) | ||
) | ||
assertTrue(tracker.isLaunching()) | ||
|
||
java.lang.Thread.sleep(10) | ||
assertTrue(tracker.isLaunching()) | ||
tracker.markLaunchCompleted() | ||
assertFalse(tracker.isLaunching()) | ||
} | ||
|
||
@Test | ||
fun smallLaunchPeriodAutomatic() { | ||
val tracker = LaunchCrashTracker( | ||
convert( | ||
generateConfiguration().apply { | ||
launchDurationMillis = 1 | ||
} | ||
) | ||
) | ||
assertTrue(tracker.isLaunching()) | ||
|
||
java.lang.Thread.sleep(10) | ||
assertFalse(tracker.isLaunching()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters