@@ -2,15 +2,12 @@ package io.sentry.android.replay
22
33import android.annotation.TargetApi
44import android.graphics.Point
5- import android.os.Build
6- import android.util.Log
75import android.view.View
86import android.view.ViewTreeObserver
97import io.sentry.SentryLevel.DEBUG
108import io.sentry.SentryLevel.ERROR
119import io.sentry.SentryLevel.WARNING
1210import io.sentry.SentryOptions
13- import io.sentry.android.replay.screenshot.FrameTimingsTracker
1411import io.sentry.android.replay.util.MainLooperHandler
1512import io.sentry.android.replay.util.addOnPreDrawListenerSafe
1613import io.sentry.android.replay.util.hasSize
@@ -27,29 +24,24 @@ internal class WindowRecorder(
2724 private val windowCallback : WindowCallback ,
2825 private val mainLooperHandler : MainLooperHandler ,
2926 private val replayExecutor : ScheduledExecutorService ,
30- private val frameTimingsTracker : FrameTimingsTracker
3127) : Recorder, OnRootViewsChangedListener {
3228
3329 private val isRecording = AtomicBoolean (false )
3430 private val rootViews = ArrayList <WeakReference <View >>()
3531 private var lastKnownWindowSize: Point = Point ()
3632 private val rootViewsLock = AutoClosableReentrantLock ()
3733 private val capturerLock = AutoClosableReentrantLock ()
38- @Volatile
39- private var capturer: Capturer ? = null
34+ @Volatile private var capturer: Capturer ? = null
4035
4136 private class Capturer (
4237 private val options : SentryOptions ,
4338 private val mainLooperHandler : MainLooperHandler ,
44- private val frameTimingsTracker : FrameTimingsTracker ,
4539 ) : Runnable {
4640
4741 var recorder: ScreenshotRecorder ? = null
4842 var config: ScreenshotRecorderConfig ? = null
4943 private val isRecording = AtomicBoolean (true )
5044
51- private val maxCaptureDelayMs = 166L // ~10 frames @ 60fps
52-
5345 private var currentCaptureDelay = 0L
5446
5547 private var rootView = WeakReference <View >(null )
@@ -91,48 +83,22 @@ internal class WindowRecorder(
9183 return
9284 }
9385
94- var delay = 1000L / (config?.frameRate ? : 1 )
95-
96- val rootView = rootView.get()
97- val isViewIdle =
98- if (rootView != null ) {
99- ! rootView.isDirty && ! rootView.isLayoutRequested && ! rootView.isInLayout
100- } else {
101- false
102- }
103-
104- Log .d(" TAG" , " View is idle: $isViewIdle " )
105- val frameTrackerIdle = frameTimingsTracker.isIdle()
106-
10786 try {
108- if ((isViewIdle) || currentCaptureDelay > maxCaptureDelayMs) {
109- if (options.sessionReplay.isDebug) {
110- Log .d(" TAG" , " Capturing a frame." )
111- }
112- currentCaptureDelay = 0L
113- recorder?.capture()
114- } else {
115- delay = 16
116- currentCaptureDelay + = delay
117- if (options.sessionReplay.isDebug) {
118- Log .d(" TAG" , " Skipping capture of this frame, app is not idle." )
119- }
120- }
121- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
122- android.os.Trace .setCounter(" sentry.capture_delay" , currentCaptureDelay)
87+ if (options.sessionReplay.isDebug) {
88+ options.logger.log(DEBUG , " Capturing a frame." )
12389 }
90+ recorder?.capture()
12491 } catch (e: Throwable ) {
12592 options.logger.log(ERROR , " Failed to capture a frame" , e)
12693 }
12794
128-
12995 if (options.sessionReplay.isDebug) {
13096 options.logger.log(
13197 DEBUG ,
13298 " Posting the capture runnable again, frame rate is ${config?.frameRate ? : 1 } fps." ,
13399 )
134100 }
135- val posted = mainLooperHandler.postDelayed(this , delay )
101+ val posted = mainLooperHandler.postDelayed(this , 1000L / (config?.frameRate ? : 1 ) )
136102 if (! posted) {
137103 options.logger.log(
138104 WARNING ,
@@ -211,7 +177,7 @@ internal class WindowRecorder(
211177 capturerLock.acquire().use {
212178 if (capturer == null ) {
213179 // don't recreate runnable for every config change, just update the config
214- capturer = Capturer (options, mainLooperHandler, frameTimingsTracker )
180+ capturer = Capturer (options, mainLooperHandler)
215181 }
216182 }
217183 }
@@ -223,7 +189,7 @@ internal class WindowRecorder(
223189 options,
224190 mainLooperHandler,
225191 replayExecutor,
226- screenshotRecorderCallback
192+ screenshotRecorderCallback,
227193 )
228194
229195 val newRoot = rootViews.lastOrNull()?.get()
0 commit comments