diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ScreenshotUtils.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ScreenshotUtils.java index 1b17f28d5e..39ecae3253 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ScreenshotUtils.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/ScreenshotUtils.java @@ -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; @@ -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(); @@ -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(); @@ -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; diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt index ce987c24ce..bbbdf3e146 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt @@ -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 @@ -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) } } diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt index 8ee0041f8b..52ce2af4c7 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt @@ -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 @@ -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) } diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt index dfb8ec0f26..2b24f984be 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt @@ -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 @@ -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) diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/PixelCopyStrategy.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/PixelCopyStrategy.kt index 72c355a5a7..3a2da50cb8 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/PixelCopyStrategy.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/PixelCopyStrategy.kt @@ -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 @@ -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) @@ -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()