Skip to content

Commit bd1914c

Browse files
romtsncodex
andcommitted
fix(replay): Ignore foreground before registration
A foreground callback can run before ReplayIntegration registers and initializes its options. Ignore lifecycle callbacks until the integration is enabled to avoid crashing during SDK initialization. Refs JAVA-325 Co-Authored-By: Codex <noreply@openai.com>
1 parent 05bdcbc commit bd1914c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public class ReplayIntegration(
168168

169169
override fun onAppForegrounded(startNewSession: Boolean) {
170170
enqueueOnMainThread {
171+
if (!isEnabled.get()) {
172+
return@enqueueOnMainThread
173+
}
171174
if (startNewSession) {
172175
val isFullSession = sample(options.sessionReplay.sessionSampleRate)
173176
if (!isFullSession && !options.sessionReplay.isSessionReplayForErrorsEnabled) {

sentry-android-replay/src/test/java/io/sentry/android/replay/ReplayIntegrationTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ class ReplayIntegrationTest {
225225
verify(captureStrategy, never()).start(any(), any(), anyOrNull())
226226
}
227227

228+
@Test
229+
fun `foreground before register does nothing`() {
230+
val replay = fixture.getSut(context)
231+
232+
replay.onAppForegrounded(true)
233+
234+
assertThat(replay.isRecording).isFalse()
235+
}
236+
228237
@Test
229238
fun `start sets isRecording to true`() {
230239
val captureStrategy = mock<CaptureStrategy>()

0 commit comments

Comments
 (0)