Skip to content

Commit ee833e6

Browse files
romtsnclaude
andcommitted
refactor: Rename getScreenshotOptions() to getScreenshot() to match getSessionReplay() pattern
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9db3b83 commit ee833e6

File tree

6 files changed

+25
-39
lines changed

6 files changed

+25
-39
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
354354
public fun getFrameMetricsCollector ()Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;
355355
public fun getNativeSdkName ()Ljava/lang/String;
356356
public fun getNdkHandlerStrategy ()I
357-
public fun getScreenshotOptions ()Lio/sentry/android/core/SentryScreenshotOptions;
357+
public fun getScreenshot ()Lio/sentry/android/core/SentryScreenshotOptions;
358358
public fun getStartupCrashDurationThresholdMillis ()J
359359
public fun isAnrEnabled ()Z
360360
public fun isAnrReportInDebug ()Z

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,10 @@ static void applyMetadata(
666666

667667
// Screenshot masking options (default to false for backwards compatibility)
668668
options
669-
.getScreenshotOptions()
669+
.getScreenshot()
670670
.setMaskAllText(readBool(metadata, logger, SCREENSHOT_MASK_ALL_TEXT, false));
671671
options
672-
.getScreenshotOptions()
672+
.getScreenshot()
673673
.setMaskAllImages(readBool(metadata, logger, SCREENSHOT_MASK_ALL_IMAGES, false));
674674
}
675675
options

sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ScreenshotEventProcessor(
6262

6363
if (options.isAttachScreenshot()) {
6464
addIntegrationToSdkVersion("Screenshot");
65-
if (!isReplayAvailable && !options.getScreenshotOptions().getMaskViewClasses().isEmpty()) {
65+
if (!isReplayAvailable && !options.getScreenshot().getMaskViewClasses().isEmpty()) {
6666
options
6767
.getLogger()
6868
.log(SentryLevel.WARNING, "Screenshot masking requires sentry-android-replay module");
@@ -71,7 +71,7 @@ public ScreenshotEventProcessor(
7171
}
7272

7373
private boolean isMaskingEnabled() {
74-
return !options.getScreenshotOptions().getMaskViewClasses().isEmpty() && isReplayAvailable;
74+
return !options.getScreenshot().getMaskViewClasses().isEmpty() && isReplayAvailable;
7575
}
7676

7777
@Override
@@ -193,8 +193,8 @@ private boolean isMaskingEnabled() {
193193
}
194194

195195
final ViewHierarchyNode rootNode =
196-
ViewHierarchyNode.Companion.fromView(rootView, null, 0, options.getScreenshotOptions());
197-
ViewsKt.traverse(rootView, rootNode, options.getScreenshotOptions(), options.getLogger());
196+
ViewHierarchyNode.Companion.fromView(rootView, null, 0, options.getScreenshot());
197+
ViewsKt.traverse(rootView, rootNode, options.getScreenshot(), options.getLogger());
198198
return rootNode;
199199
}
200200

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public interface BeforeCaptureCallback {
250250
* <p>Note: Screenshot masking requires the {@code sentry-android-replay} module to be present at
251251
* runtime. If the replay module is not available, screenshots will be captured without masking.
252252
*/
253-
private final @NotNull SentryScreenshotOptions screenshotOptions = new SentryScreenshotOptions();
253+
private final @NotNull SentryScreenshotOptions screenshot = new SentryScreenshotOptions();
254254

255255
public SentryAndroidOptions() {
256256
setSentryClientName(BuildConfig.SENTRY_ANDROID_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
@@ -691,8 +691,8 @@ public void setEnableSystemEventBreadcrumbsExtras(
691691
*
692692
* @return the screenshot masking options
693693
*/
694-
public @NotNull SentryScreenshotOptions getScreenshotOptions() {
695-
return screenshotOptions;
694+
public @NotNull SentryScreenshotOptions getScreenshot() {
695+
return screenshot;
696696
}
697697

698698
static class AndroidUserFeedbackIDialogHandler implements SentryFeedbackOptions.IDialogHandler {

sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,9 +2302,7 @@ class ManifestMetadataReaderTest {
23022302
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
23032303

23042304
// Assert
2305-
assertTrue(
2306-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.TextView")
2307-
)
2305+
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.widget.TextView"))
23082306
}
23092307

23102308
@Test
@@ -2317,9 +2315,7 @@ class ManifestMetadataReaderTest {
23172315
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
23182316

23192317
// Assert
2320-
assertTrue(
2321-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.ImageView")
2322-
)
2318+
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.widget.ImageView"))
23232319
}
23242320

23252321
@Test
@@ -2331,9 +2327,7 @@ class ManifestMetadataReaderTest {
23312327
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
23322328

23332329
// Assert
2334-
assertFalse(
2335-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.TextView")
2336-
)
2330+
assertFalse(fixture.options.screenshot.maskViewClasses.contains("android.widget.TextView"))
23372331
}
23382332

23392333
@Test
@@ -2345,9 +2339,7 @@ class ManifestMetadataReaderTest {
23452339
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
23462340

23472341
// Assert
2348-
assertFalse(
2349-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.ImageView")
2350-
)
2342+
assertFalse(fixture.options.screenshot.maskViewClasses.contains("android.widget.ImageView"))
23512343
}
23522344

23532345
@Test
@@ -2364,13 +2356,9 @@ class ManifestMetadataReaderTest {
23642356
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
23652357

23662358
// Assert
2367-
assertTrue(
2368-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.TextView")
2369-
)
2370-
assertTrue(
2371-
fixture.options.screenshotOptions.maskViewClasses.contains("android.widget.ImageView")
2372-
)
2359+
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.widget.TextView"))
2360+
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.widget.ImageView"))
23732361
// maskAllImages should also add WebView
2374-
assertTrue(fixture.options.screenshotOptions.maskViewClasses.contains("android.webkit.WebView"))
2362+
assertTrue(fixture.options.screenshot.maskViewClasses.contains("android.webkit.WebView"))
23752363
}
23762364
}

sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class ScreenshotEventProcessorTest {
326326
@Test
327327
fun `when masking is configured and VH capture fails, no screenshot is attached`() {
328328
val sut = fixture.getSut(attachScreenshot = true, isReplayAvailable = true)
329-
fixture.options.screenshotOptions.setMaskAllText(true)
329+
fixture.options.screenshot.setMaskAllText(true)
330330
val hint = Hint()
331331

332332
// No activity set, so VH capture will return null (no rootView)
@@ -341,7 +341,7 @@ class ScreenshotEventProcessorTest {
341341
@Test
342342
fun `when masking is configured but replay is not available, screenshot is still captured without masking`() {
343343
val sut = fixture.getSut(attachScreenshot = true, isReplayAvailable = false)
344-
fixture.options.screenshotOptions.setMaskAllText(true)
344+
fixture.options.screenshot.setMaskAllText(true)
345345
val hint = Hint()
346346

347347
CurrentActivityHolder.getInstance().setActivity(fixture.activity)
@@ -354,7 +354,7 @@ class ScreenshotEventProcessorTest {
354354

355355
@Test
356356
fun `when masking is configured from background thread, VH is captured on main thread`() {
357-
fixture.options.screenshotOptions.setMaskAllText(true)
357+
fixture.options.screenshot.setMaskAllText(true)
358358
val sut = fixture.getSut(attachScreenshot = true, isReplayAvailable = true)
359359
whenever(fixture.threadChecker.isMainThread).thenReturn(false)
360360

@@ -379,25 +379,23 @@ class ScreenshotEventProcessorTest {
379379
@Test
380380
fun `snapshot - screenshot with text masking enabled`() {
381381
val bytes =
382-
processEventForSnapshots("screenshot_mask_text") { it.screenshotOptions.setMaskAllText(true) }
382+
processEventForSnapshots("screenshot_mask_text") { it.screenshot.setMaskAllText(true) }
383383
assertNotNull(bytes)
384384
}
385385

386386
@Test
387387
fun `snapshot - screenshot with image masking enabled`() {
388388
val bytes =
389-
processEventForSnapshots("screenshot_mask_images") {
390-
it.screenshotOptions.setMaskAllImages(true)
391-
}
389+
processEventForSnapshots("screenshot_mask_images") { it.screenshot.setMaskAllImages(true) }
392390
assertNotNull(bytes)
393391
}
394392

395393
@Test
396394
fun `snapshot - screenshot with all masking enabled`() {
397395
val bytes =
398396
processEventForSnapshots("screenshot_mask_all") {
399-
it.screenshotOptions.setMaskAllText(true)
400-
it.screenshotOptions.setMaskAllImages(true)
397+
it.screenshot.setMaskAllText(true)
398+
it.screenshot.setMaskAllImages(true)
401399
}
402400
assertNotNull(bytes)
403401
}
@@ -407,7 +405,7 @@ class ScreenshotEventProcessorTest {
407405
val bytes =
408406
processEventForSnapshots("screenshot_mask_custom_view") {
409407
// CustomView draws white, so masking it should draw black on top
410-
it.screenshotOptions.addMaskViewClass(CustomView::class.java.name)
408+
it.screenshot.addMaskViewClass(CustomView::class.java.name)
411409
}
412410
assertNotNull(bytes)
413411
}

0 commit comments

Comments
 (0)