Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.sentry.SentryLevel;
import io.sentry.android.core.BuildInfoProvider;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.util.ExceptionUtils;
import io.sentry.util.thread.IThreadChecker;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -183,7 +184,9 @@ public final class ScreenshotUtils {
final boolean completed = latch.await(CAPTURE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
success = completed && copyResultCode.get() == PixelCopy.SUCCESS;
} catch (Throwable e) {
// ignored
// PixelCopy reads the window's surface through the system compositor, so we can't know
// what it throws. No screenshot is attached.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Taking screenshot using PixelCopy failed.", e);
} finally {
thread.quit();
Expand All @@ -206,6 +209,9 @@ public final class ScreenshotUtils {
try {
view.draw(canvas);
} catch (Throwable e) {
// draw() runs the app's own views, so we can't know what it throws. No screenshot is
// attached.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Taking screenshot failed (view.draw).", e);
} finally {
latch.countDown();
Expand All @@ -219,6 +225,9 @@ public final class ScreenshotUtils {
}
return bitmap;
} catch (Throwable e) {
// On the main thread, draw() runs the app's own views, so we can't know what it throws. No
// screenshot is attached.
ExceptionUtils.rethrowIfFatal(e);
logger.log(SentryLevel.ERROR, "Taking screenshot failed.", e);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.sentry.android.replay.screenshot.ScreenshotStrategy
import io.sentry.android.replay.util.DebugOverlayDrawable
import io.sentry.android.replay.util.addOnDrawListenerSafe
import io.sentry.android.replay.util.removeOnDrawListenerSafe
import io.sentry.util.ExceptionUtils
import java.io.File
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -92,6 +93,9 @@ internal class ScreenshotRecorder(
contentChanged.set(false)
screenshotStrategy.capture(root)
} catch (e: Throwable) {
// Capturing draws the app's own views and goes through the device's graphics stack, so we
// can't know what it throws. The frame is skipped.
ExceptionUtils.rethrowIfFatal(e)
options.logger.log(WARNING, "Failed to capture replay recording", e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.sentry.android.replay.util.addOnPreDrawListenerSafe
import io.sentry.android.replay.util.hasSize
import io.sentry.android.replay.util.removeOnPreDrawListenerSafe
import io.sentry.util.AutoClosableReentrantLock
import io.sentry.util.ExceptionUtils
import java.lang.ref.WeakReference
import java.util.WeakHashMap
import java.util.concurrent.ScheduledExecutorService
Expand Down Expand Up @@ -96,6 +97,9 @@ internal class WindowRecorder(
}
recorder?.capture()
} catch (e: Throwable) {
// Capturing draws the app's own views and goes through the device's graphics stack, so we
// can't know what it throws. This frame is skipped, and the next one is still scheduled.
ExceptionUtils.rethrowIfFatal(e)
options.logger.log(ERROR, "Failed to capture a frame", e)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.sentry.android.replay.ScreenshotRecorderCallback
import io.sentry.android.replay.ScreenshotRecorderConfig
import io.sentry.android.replay.util.ReplayRunnable
import io.sentry.util.AutoClosableReentrantLock
import io.sentry.util.ExceptionUtils
import io.sentry.util.IntegrationUtils
import java.util.WeakHashMap
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -144,6 +145,9 @@ internal class CanvasStrategy(
executor.getBackgroundHandler(),
)
} catch (t: Throwable) {
// Drawing into the hardware surface and PixelCopy go through the device's graphics stack,
// so we can't know what they throw. The frame is skipped.
ExceptionUtils.rethrowIfFatal(t)
// if the request itself threw, no callback will clear the flag
pixelCopyInFlight = false
options.logger.log(SentryLevel.ERROR, "Canvas Strategy: picture render failed", t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.sentry.android.replay.util.MaskRenderer
import io.sentry.android.replay.util.ReplayRunnable
import io.sentry.android.replay.util.traverse
import io.sentry.android.replay.viewhierarchy.ViewHierarchyNode
import io.sentry.util.ExceptionUtils
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import kotlin.LazyThreadSafetyMode.NONE
Expand Down Expand Up @@ -177,6 +178,9 @@ internal class PixelCopyStrategy(
mainLooperHandler.handler,
)
} catch (e: Throwable) {
// PixelCopy goes through the device's graphics stack, so we can't know what it throws. The
// frame is skipped, and the frame gate is released for the next one.
ExceptionUtils.rethrowIfFatal(e)
options.logger.log(WARNING, "Failed to capture replay recording", e)
unstableCaptures.set(0)
lastCaptureSuccessful.set(false)
Expand Down Expand Up @@ -294,6 +298,9 @@ internal class PixelCopyStrategy(
// double-recycle if the recycle paths above already ran.
svBitmap = null
} catch (e: Throwable) {
// PixelCopy goes through the device's graphics stack, so we can't know what it throws.
// This SurfaceView is left out of the frame.
ExceptionUtils.rethrowIfFatal(e)
options.logger.log(WARNING, "Failed to capture SurfaceView", e)
svBitmap?.recycle()
onCaptureComplete()
Expand Down
Loading