Skip to content

Commit c6b16ed

Browse files
committed
Expose replayCacheDir
1 parent 32fb5f0 commit c6b16ed

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

sentry-android-replay/api/sentry-android-replay.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class io/sentry/android/replay/ReplayIntegration : android/content/
4242
public fun <init> (Landroid/content/Context;Lio/sentry/transport/ICurrentDateProvider;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
4343
public synthetic fun <init> (Landroid/content/Context;Lio/sentry/transport/ICurrentDateProvider;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
4444
public fun close ()V
45+
public final fun getReplayCacheDir ()Ljava/io/File;
4546
public fun getReplayId ()Lio/sentry/protocol/SentryId;
4647
public fun isRecording ()Z
4748
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ReplayIntegration(
5252
private val isEnabled = AtomicBoolean(false)
5353
private val isRecording = AtomicBoolean(false)
5454
private var captureStrategy: CaptureStrategy? = null
55+
public val replayCacheDir: File? get() = captureStrategy?.replayCacheDir
5556

5657
private lateinit var recorderConfig: ScreenshotRecorderConfig
5758

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ internal abstract class BaseCaptureStrategy(
4646
protected val replayStartTimestamp = AtomicLong()
4747
override val currentReplayId = AtomicReference(SentryId.EMPTY_ID)
4848
override val currentSegment = AtomicInteger(0)
49+
override val replayCacheDir: File? get() = cache?.replayCacheDir
4950

5051
protected val replayExecutor: ScheduledExecutorService by lazy {
5152
executor ?: Executors.newSingleThreadScheduledExecutor(ReplayExecutorServiceThreadFactory())

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/CaptureStrategy.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import io.sentry.SentryEvent
55
import io.sentry.android.replay.ReplayCache
66
import io.sentry.android.replay.ScreenshotRecorderConfig
77
import io.sentry.protocol.SentryId
8+
import java.io.File
89
import java.util.concurrent.atomic.AtomicInteger
910
import java.util.concurrent.atomic.AtomicReference
1011

1112
internal interface CaptureStrategy {
1213
val currentSegment: AtomicInteger
1314
val currentReplayId: AtomicReference<SentryId>
15+
val replayCacheDir: File?
1416

1517
fun start(segmentId: Int = 0, replayId: SentryId = SentryId(), cleanupOldReplays: Boolean = true)
1618

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class ReplayIntegrationWithRecorderTest {
184184
// start again and capture some frames
185185
replay.start()
186186

187-
val flutterCacheDir =
188-
File(fixture.options.cacheDirPath!!, "flutter_replay").also { it.mkdirs() }
189-
val screenshot = File(flutterCacheDir, "1.jpg").also { it.createNewFile() }
187+
// have to access 'replayCacheDir' after calling replay.start(), BUT can already be accessed
188+
// inside recorder.start()
189+
val screenshot = File(replay.replayCacheDir, "1.jpg").also { it.createNewFile() }
190190

191191
screenshot.outputStream().use {
192192
Bitmap.createBitmap(1, 1, ARGB_8888).compress(JPEG, 80, it)

0 commit comments

Comments
 (0)