Skip to content

Commit d65982a

Browse files
committed
Remove configuration from start() method
1 parent b82bb0c commit d65982a

12 files changed

Lines changed: 150 additions & 134 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public final class io/sentry/android/replay/ModifierExtensionsKt {
3434
}
3535

3636
public abstract interface class io/sentry/android/replay/Recorder : java/io/Closeable {
37+
public abstract fun onConfigurationChanged (Lio/sentry/android/replay/ScreenshotRecorderConfig;)V
3738
public abstract fun pause ()V
3839
public abstract fun reset ()V
3940
public abstract fun resume ()V
40-
public abstract fun start (Lio/sentry/android/replay/ScreenshotRecorderConfig;)V
41+
public abstract fun start ()V
4142
public abstract fun stop ()V
4243
}
4344

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public interface Recorder : Closeable {
88
* at which the screenshots should be taken, and the screenshots size/resolution, which can
99
* change e.g. in the case of orientation change or window size change
1010
*/
11-
public fun start(recorderConfig: ScreenshotRecorderConfig)
11+
public fun start()
12+
13+
public fun onConfigurationChanged(config: ScreenshotRecorderConfig)
1214

1315
public fun resume()
1416

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ public class ReplayIntegration(
190190
} else {
191191
BufferCaptureStrategy(options, scopes, dateProvider, random, replayExecutor, replayCacheProvider)
192192
}
193+
recorder?.start()
194+
captureStrategy?.start()
195+
193196
registerRootViewListeners()
194197
}
195198
}
@@ -331,9 +334,6 @@ public class ReplayIntegration(
331334
}
332335

333336
recorder?.stop()
334-
335-
// once the window size is determined
336-
// onWindowSizeChanged is triggered and we'll start the actual capturing
337337
}
338338

339339
override fun onConnectionStatusChanged(status: ConnectionStatus) {
@@ -470,18 +470,9 @@ public class ReplayIntegration(
470470
return
471471
}
472472

473-
recorder?.stop()
474-
475473
val recorderConfig = recorderConfigProvider?.invoke(true) ?: ScreenshotRecorderConfig.fromSize(context, options.sessionReplay, width, height)
476-
477-
captureStrategy?.let { capture ->
478-
if (capture.currentReplayId == SentryId.EMPTY_ID) {
479-
capture.start(recorderConfig)
480-
} else {
481-
capture.onConfigurationChanged(recorderConfig)
482-
}
483-
}
484-
recorder?.start(recorderConfig)
474+
captureStrategy?.onConfigurationChanged(recorderConfig)
475+
recorder?.onConfigurationChanged(recorderConfig)
485476

486477
// we have to restart recorder with a new config and pause immediately if the replay is paused
487478
if (lifecycle.currentState == PAUSED) {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ internal class WindowRecorder(
9292
}
9393
}
9494

95-
override fun start(recorderConfig: ScreenshotRecorderConfig) {
96-
if (isRecording.getAndSet(true)) {
95+
override fun start() {
96+
isRecording.getAndSet(true)
97+
}
98+
99+
override fun onConfigurationChanged(recorderConfig: ScreenshotRecorderConfig) {
100+
if (!isRecording.get()) {
97101
return
98102
}
99103

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal abstract class BaseCaptureStrategy(
6161

6262
protected val isTerminating = AtomicBoolean(false)
6363
protected var cache: ReplayCache? = null
64-
protected var recorderConfig: ScreenshotRecorderConfig by persistableAtomic { _, _, newValue ->
64+
protected var recorderConfig: ScreenshotRecorderConfig? by persistableAtomic { _, _, newValue ->
6565
if (newValue == null) {
6666
// recorderConfig is only nullable on init, but never after
6767
return@persistableAtomic
@@ -85,7 +85,6 @@ internal abstract class BaseCaptureStrategy(
8585
protected val currentEvents: Deque<RRWebEvent> = ConcurrentLinkedDeque()
8686

8787
override fun start(
88-
recorderConfig: ScreenshotRecorderConfig,
8988
segmentId: Int,
9089
replayId: SentryId,
9190
replayType: ReplayType?
@@ -95,7 +94,6 @@ internal abstract class BaseCaptureStrategy(
9594
this.currentReplayId = replayId
9695
this.currentSegment = segmentId
9796
this.replayType = replayType ?: (if (this is SessionCaptureStrategy) SESSION else BUFFER)
98-
this.recorderConfig = recorderConfig
9997

10098
segmentTimestamp = DateUtils.getCurrentDateTime()
10199
replayStartTimestamp.set(dateProvider.currentTimeMillis)
@@ -122,10 +120,10 @@ internal abstract class BaseCaptureStrategy(
122120
segmentId: Int,
123121
height: Int,
124122
width: Int,
123+
frameRate: Int,
124+
bitRate: Int,
125125
replayType: ReplayType = this.replayType,
126126
cache: ReplayCache? = this.cache,
127-
frameRate: Int = recorderConfig.frameRate,
128-
bitRate: Int = recorderConfig.bitRate,
129127
screenAtStart: String? = this.screenAtStart,
130128
breadcrumbs: List<Breadcrumb>? = null,
131129
events: Deque<RRWebEvent> = this.currentEvents
@@ -153,9 +151,11 @@ internal abstract class BaseCaptureStrategy(
153151
}
154152

155153
override fun onTouchEvent(event: MotionEvent) {
156-
val rrwebEvents = gestureConverter.convert(event, recorderConfig)
157-
if (rrwebEvents != null) {
158-
currentEvents += rrwebEvents
154+
recorderConfig?.let { config ->
155+
val rrwebEvents = gestureConverter.convert(event, config)
156+
if (rrwebEvents != null) {
157+
currentEvents += rrwebEvents
158+
}
159159
}
160160
}
161161

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal class BufferCaptureStrategy(
131131
}
132132
// we hand over replayExecutor to the new strategy to preserve order of execution
133133
val captureStrategy = SessionCaptureStrategy(options, scopes, dateProvider, replayExecutor)
134-
captureStrategy.start(recorderConfig, segmentId = currentSegment, replayId = currentReplayId, replayType = BUFFER)
134+
captureStrategy.start(segmentId = currentSegment, replayId = currentReplayId, replayType = BUFFER)
135135
return captureStrategy
136136
}
137137

@@ -189,24 +189,33 @@ internal class BufferCaptureStrategy(
189189
}
190190

191191
private fun createCurrentSegment(taskName: String, onSegmentCreated: (ReplaySegment) -> Unit) {
192-
val errorReplayDuration = options.sessionReplay.errorReplayDuration
193-
val now = dateProvider.currentTimeMillis
194-
val currentSegmentTimestamp = if (cache?.frames?.isNotEmpty() == true) {
195-
// in buffer mode we have to set the timestamp of the first frame as the actual start
196-
DateUtils.getDateTime(cache!!.frames.first().timestamp)
197-
} else {
198-
DateUtils.getDateTime(now - errorReplayDuration)
199-
}
200-
val segmentId = currentSegment
201-
val duration = now - currentSegmentTimestamp.time
202-
val replayId = currentReplayId
203-
val height = this.recorderConfig.recordingHeight
204-
val width = this.recorderConfig.recordingWidth
205-
206-
replayExecutor.submitSafely(options, "$TAG.$taskName") {
207-
val segment =
208-
createSegmentInternal(duration, currentSegmentTimestamp, replayId, segmentId, height, width)
209-
onSegmentCreated(segment)
192+
recorderConfig?.let { config ->
193+
val errorReplayDuration = options.sessionReplay.errorReplayDuration
194+
val now = dateProvider.currentTimeMillis
195+
val currentSegmentTimestamp = if (cache?.frames?.isNotEmpty() == true) {
196+
// in buffer mode we have to set the timestamp of the first frame as the actual start
197+
DateUtils.getDateTime(cache!!.frames.first().timestamp)
198+
} else {
199+
DateUtils.getDateTime(now - errorReplayDuration)
200+
}
201+
val segmentId = currentSegment
202+
val duration = now - currentSegmentTimestamp.time
203+
val replayId = currentReplayId
204+
205+
replayExecutor.submitSafely(options, "$TAG.$taskName") {
206+
val segment =
207+
createSegmentInternal(
208+
duration,
209+
currentSegmentTimestamp,
210+
replayId,
211+
segmentId,
212+
config.recordingHeight,
213+
config.recordingWidth,
214+
config.frameRate,
215+
config.bitRate
216+
)
217+
onSegmentCreated(segment)
218+
}
210219
}
211220
}
212221
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ internal interface CaptureStrategy {
3131
var segmentTimestamp: Date?
3232

3333
fun start(
34-
recorderConfig: ScreenshotRecorderConfig,
3534
segmentId: Int = 0,
3635
replayId: SentryId = SentryId(),
3736
replayType: ReplayType? = null

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

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ internal class SessionCaptureStrategy(
2929
}
3030

3131
override fun start(
32-
recorderConfig: ScreenshotRecorderConfig,
3332
segmentId: Int,
3433
replayId: SentryId,
3534
replayType: ReplayType?
3635
) {
37-
super.start(recorderConfig, segmentId, replayId, replayType)
36+
super.start(segmentId, replayId, replayType)
3837
// only set replayId on the scope if it's a full session, otherwise all events will be
3938
// tagged with the replay that might never be sent when we're recording in buffer mode
4039
scopes?.configureScope {
@@ -80,8 +79,6 @@ internal class SessionCaptureStrategy(
8079
// have to do it before submitting, otherwise if the queue is busy, the timestamp won't be
8180
// reflecting the exact time of when it was captured
8281
val frameTimestamp = dateProvider.currentTimeMillis
83-
val height = recorderConfig.recordingHeight
84-
val width = recorderConfig.recordingWidth
8582
replayExecutor.submitSafely(options, "$TAG.add_frame") {
8683
cache?.store(frameTimestamp)
8784

@@ -98,20 +95,24 @@ internal class SessionCaptureStrategy(
9895

9996
val now = dateProvider.currentTimeMillis
10097
if ((now - currentSegmentTimestamp.time >= options.sessionReplay.sessionSegmentDuration)) {
101-
val segment =
102-
createSegmentInternal(
103-
options.sessionReplay.sessionSegmentDuration,
104-
currentSegmentTimestamp,
105-
currentReplayId,
106-
currentSegment,
107-
height,
108-
width
109-
)
110-
if (segment is ReplaySegment.Created) {
111-
segment.capture(scopes)
112-
currentSegment++
113-
// set next segment timestamp as close to the previous one as possible to avoid gaps
114-
segmentTimestamp = segment.replay.timestamp
98+
recorderConfig?.let { config ->
99+
val segment =
100+
createSegmentInternal(
101+
options.sessionReplay.sessionSegmentDuration,
102+
currentSegmentTimestamp,
103+
currentReplayId,
104+
currentSegment,
105+
config.recordingHeight,
106+
config.recordingWidth,
107+
config.frameRate,
108+
config.bitRate
109+
)
110+
if (segment is ReplaySegment.Created) {
111+
segment.capture(scopes)
112+
currentSegment++
113+
// set next segment timestamp as close to the previous one as possible to avoid gaps
114+
segmentTimestamp = segment.replay.timestamp
115+
}
115116
}
116117
}
117118

@@ -140,17 +141,26 @@ internal class SessionCaptureStrategy(
140141
override fun convert(): CaptureStrategy = this
141142

142143
private fun createCurrentSegment(taskName: String, onSegmentCreated: (ReplaySegment) -> Unit) {
143-
val now = dateProvider.currentTimeMillis
144-
val currentSegmentTimestamp = segmentTimestamp ?: return
145-
val segmentId = currentSegment
146-
val duration = now - currentSegmentTimestamp.time
147-
val replayId = currentReplayId
148-
val height = recorderConfig.recordingHeight
149-
val width = recorderConfig.recordingWidth
150-
replayExecutor.submitSafely(options, "$TAG.$taskName") {
151-
val segment =
152-
createSegmentInternal(duration, currentSegmentTimestamp, replayId, segmentId, height, width)
153-
onSegmentCreated(segment)
144+
recorderConfig?.let { config ->
145+
val now = dateProvider.currentTimeMillis
146+
val currentSegmentTimestamp = segmentTimestamp ?: return
147+
val segmentId = currentSegment
148+
val duration = now - currentSegmentTimestamp.time
149+
val replayId = currentReplayId
150+
replayExecutor.submitSafely(options, "$TAG.$taskName") {
151+
val segment =
152+
createSegmentInternal(
153+
duration,
154+
currentSegmentTimestamp,
155+
replayId,
156+
segmentId,
157+
config.recordingHeight,
158+
config.recordingWidth,
159+
config.frameRate,
160+
config.bitRate
161+
)
162+
onSegmentCreated(segment)
163+
}
154164
}
155165
}
156166
}

0 commit comments

Comments
 (0)