From fc20d26ee9aa7cb1d5dfd91916a3b41237a8fe30 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 14 Nov 2022 16:04:19 +0100 Subject: [PATCH] Fix do not add screenshots if should not apply scope data, make setCurrentActivity public --- .../android/core/ScreenshotEventProcessor.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java index 48e99e7ad3..500b8d7872 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java @@ -17,6 +17,7 @@ import io.sentry.Hint; import io.sentry.SentryEvent; import io.sentry.SentryLevel; +import io.sentry.util.HintUtils; import io.sentry.util.Objects; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -51,10 +52,18 @@ public ScreenshotEventProcessor( application.registerActivityLifecycleCallbacks(this); } + public void setCurrentActivity(@NonNull Activity activity) { + if (currentActivity != null && currentActivity.get() == activity) { + return; + } + currentActivity = new WeakReference<>(activity); + } + @SuppressWarnings("NullAway") @Override public @NotNull SentryEvent process(final @NotNull SentryEvent event, @NotNull Hint hint) { - if (!lifecycleCallbackInstalled) { + if (!lifecycleCallbackInstalled + || !HintUtils.shouldApplyScopeData(hint)) { return event; } if (!options.isAttachScreenshot()) { @@ -167,13 +176,6 @@ private void cleanCurrentActivity(@NonNull Activity activity) { } } - private void setCurrentActivity(@NonNull Activity activity) { - if (currentActivity != null && currentActivity.get() == activity) { - return; - } - currentActivity = new WeakReference<>(activity); - } - @SuppressLint("NewApi") private boolean isActivityValid(@Nullable Activity activity) { if (activity == null) {