Skip to content

Commit b72ae83

Browse files
romtsncodex
andcommitted
ref(android): Use thread checker for replay close
Use the configured thread checker for replay shutdown decisions so tests can control main-thread behavior through the existing abstraction. Co-Authored-By: Codex <noreply@openai.com>
1 parent e170e95 commit b72ae83

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.graphics.Bitmap
55
import android.graphics.BitmapFactory
66
import android.os.Build
7-
import android.os.Looper
87
import android.view.MotionEvent
98
import io.sentry.Breadcrumb
109
import io.sentry.DataCategory.All
@@ -460,7 +459,7 @@ public class ReplayIntegration(
460459
return
461460
}
462461

463-
val isMainThread = Looper.myLooper() == Looper.getMainLooper()
462+
val isMainThread = options.threadChecker.isMainThread
464463
val closeCompleted = if (isMainThread) null else CountDownLatch(1)
465464
if (isMainThread) {
466465
closeInternal()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import io.sentry.rrweb.RRWebVideoEvent
5050
import io.sentry.transport.CurrentDateProvider
5151
import io.sentry.transport.ICurrentDateProvider
5252
import io.sentry.transport.RateLimiter
53+
import io.sentry.util.thread.IThreadChecker
5354
import java.io.ByteArrayOutputStream
5455
import java.io.File
5556
import java.util.Date
@@ -90,6 +91,10 @@ class ReplayIntegrationTest {
9091
internal class Fixture {
9192
val options =
9293
SentryOptions().apply {
94+
threadChecker =
95+
mock<IThreadChecker> {
96+
on { isMainThread }.thenAnswer { Looper.myLooper() == Looper.getMainLooper() }
97+
}
9398
setReplayController(
9499
mock { on { breadcrumbConverter }.thenReturn(DefaultReplayBreadcrumbConverter()) }
95100
)

0 commit comments

Comments
 (0)