Skip to content

Commit cb9e7f6

Browse files
committed
Cleanup
1 parent 4bd6fbb commit cb9e7f6

File tree

6 files changed

+14
-122
lines changed

6 files changed

+14
-122
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import io.sentry.android.replay.capture.CaptureStrategy.ReplaySegment
3030
import io.sentry.android.replay.capture.SessionCaptureStrategy
3131
import io.sentry.android.replay.gestures.GestureRecorder
3232
import io.sentry.android.replay.gestures.TouchRecorderCallback
33-
import io.sentry.android.replay.screenshot.FrameTimingsTracker
3433
import io.sentry.android.replay.util.MainLooperHandler
3534
import io.sentry.android.replay.util.appContext
3635
import io.sentry.android.replay.util.gracefullyShutdown
@@ -103,8 +102,6 @@ public class ReplayIntegration(
103102
private var gestureRecorder: GestureRecorder? = null
104103
private val random by lazy { Random() }
105104
internal val rootViewsSpy by lazy { RootViewsSpy.install() }
106-
107-
private val framesTracker = FrameTimingsTracker(context)
108105
private val replayExecutor by lazy {
109106
Executors.newSingleThreadScheduledExecutor(ReplayExecutorServiceThreadFactory())
110107
}
@@ -142,7 +139,7 @@ public class ReplayIntegration(
142139
this.scopes = scopes
143140
recorder =
144141
recorderProvider?.invoke()
145-
?: WindowRecorder(options, this, this, mainLooperHandler, replayExecutor, framesTracker)
142+
?: WindowRecorder(options, this, this, mainLooperHandler, replayExecutor)
146143
gestureRecorder = gestureRecorderProvider?.invoke() ?: GestureRecorder(options, this)
147144
isEnabled.set(true)
148145

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import android.annotation.SuppressLint
44
import android.annotation.TargetApi
55
import android.content.Context
66
import android.graphics.Bitmap
7-
import android.os.SystemClock
8-
import android.util.Log
97
import android.view.View
108
import android.view.ViewTreeObserver
119
import io.sentry.ScreenshotStrategyType
@@ -95,10 +93,7 @@ internal class ScreenshotRecorder(
9593

9694
try {
9795
contentChanged.set(false)
98-
val start = SystemClock.uptimeMillis()
9996
screenshotStrategy.capture(root)
100-
val duration = SystemClock.uptimeMillis() - start
101-
Log.d("TAG", "Canvas.capture took ${duration}ms")
10297
} catch (e: Throwable) {
10398
options.logger.log(WARNING, "Failed to capture replay recording", e)
10499
}

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

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ package io.sentry.android.replay
22

33
import android.annotation.TargetApi
44
import android.graphics.Point
5-
import android.os.Build
6-
import android.util.Log
75
import android.view.View
86
import android.view.ViewTreeObserver
97
import io.sentry.SentryLevel.DEBUG
108
import io.sentry.SentryLevel.ERROR
119
import io.sentry.SentryLevel.WARNING
1210
import io.sentry.SentryOptions
13-
import io.sentry.android.replay.screenshot.FrameTimingsTracker
1411
import io.sentry.android.replay.util.MainLooperHandler
1512
import io.sentry.android.replay.util.addOnPreDrawListenerSafe
1613
import 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()

sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import android.media.Image
2626
import android.media.ImageReader
2727
import android.os.Handler
2828
import android.os.HandlerThread
29-
import android.os.Trace
3029
import android.view.View
3130
import io.sentry.SentryLevel
3231
import io.sentry.SentryOptions
@@ -111,7 +110,6 @@ internal class CanvasStrategy(
111110

112111
@SuppressLint("UnclosedTrace")
113112
override fun capture(root: View) {
114-
Trace.beginSection("Canvas.capture")
115113
val holder: PictureReaderHolder? =
116114
synchronized(freePictures) {
117115
when {
@@ -134,7 +132,6 @@ internal class CanvasStrategy(
134132
synchronized(unprocessedPictures) { unprocessedPictures.add(holder) }
135133

136134
executor.submitSafely(options, "screenshot_recorder.canvas", pictureRenderTask)
137-
Trace.endSection()
138135
}
139136

140137
override fun onContentChanged() {

sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/FrameTimingsTracker.kt

Lines changed: 0 additions & 66 deletions
This file was deleted.

sentry/src/main/java/io/sentry/SentryReplayOptions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ public enum SentryReplayQuality {
141141

142142
/**
143143
* The screenshot strategy to use for capturing screenshots during replay recording. Defaults to
144-
* PIXEL_COPY for better performance and quality.
144+
* {@link ScreenshotStrategyType#PIXEL_COPY}. If set to {@link ScreenshotStrategyType#CANVAS}, the
145+
* SDK will use the Canvas API to capture screenshots, which will always mask all Texts and
146+
* Bitmaps drawn on the screen, causing {@link #addMaskViewClass} and {@link #addUnmaskViewClass}
147+
* to be ignored.
145148
*/
146-
@ApiStatus.Internal
147-
private ScreenshotStrategyType screenshotStrategy = ScreenshotStrategyType.CANVAS;
149+
@ApiStatus.Experimental
150+
private @NotNull ScreenshotStrategyType screenshotStrategy = ScreenshotStrategyType.PIXEL_COPY;
148151

149152
public SentryReplayOptions(final boolean empty, final @Nullable SdkVersion sdkVersion) {
150153
if (!empty) {

0 commit comments

Comments
 (0)