Skip to content
Next Next commit
Fix don't register any full drawn listeners if feature is not enabled
  • Loading branch information
markushi committed Oct 8, 2024
commit d7e2ffc57d245a7cf01565b1e452cf6a997404e4
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public synchronized void onActivityCreated(

firstActivityCreated = true;

if (fullyDisplayedReporter != null) {
if (performanceEnabled && ttfdSpan != null && fullyDisplayedReporter != null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this, as otherwise we'd add a new listener inside FullyDisplayedReporter without ever clearing that list.

fullyDisplayedReporter.registerFullyDrawnListener(() -> onFullFrameDrawn(ttfdSpan));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class ActivityLifecycleIntegrationTest {
}
val bundle = mock<Bundle>()
val activityFramesTracker = mock<ActivityFramesTracker>()
val fullyDisplayedReporter = FullyDisplayedReporter.getInstance()
val transactionFinishedCallback = mock<TransactionFinishedCallback>()
lateinit var shadowActivityManager: ShadowActivityManager

Expand Down Expand Up @@ -619,11 +618,30 @@ class ActivityLifecycleIntegrationTest {
sut.onActivityCreated(activity, mock())
val ttfdSpan = sut.ttfdSpanMap[activity]
sut.ttidSpanMap.values.first().finish()
fixture.fullyDisplayedReporter.reportFullyDrawn()
fixture.options.fullyDisplayedReporter.reportFullyDrawn()
assertTrue(ttfdSpan!!.isFinished)
assertNotEquals(SpanStatus.CANCELLED, ttfdSpan.status)
}

@Test
fun `if ttfd is disabled, no listener is registered for FullyDisplayedReporter`() {
val ttfdReporter = mock<FullyDisplayedReporter>()

val sut = fixture.getSut()
fixture.options.apply {
tracesSampleRate = 1.0
isEnableTimeToFullDisplayTracing = false
fullyDisplayedReporter = ttfdReporter
}

sut.register(fixture.hub, fixture.options)

val activity = mock<Activity>()
sut.onActivityCreated(activity, mock())

verify(ttfdReporter, never()).registerFullyDrawnListener(any())
}

@Test
fun `App start is Cold when savedInstanceState is null`() {
val sut = fixture.getSut()
Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,7 @@ public class io/sentry/SentryOptions {
public fun setEnvironment (Ljava/lang/String;)V
public fun setExecutorService (Lio/sentry/ISentryExecutorService;)V
public fun setFlushTimeoutMillis (J)V
public fun setFullyDisplayedReporter (Lio/sentry/FullyDisplayedReporter;)V
public fun setGestureTargetLocators (Ljava/util/List;)V
public fun setIdleTimeout (Ljava/lang/Long;)V
public fun setIgnoredCheckIns (Ljava/util/List;)V
Expand Down
9 changes: 8 additions & 1 deletion sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public class SentryOptions {
private boolean enableTimeToFullDisplayTracing = false;

/** Screen fully displayed reporter, used for time-to-full-display spans. */
private final @NotNull FullyDisplayedReporter fullyDisplayedReporter =
private @NotNull FullyDisplayedReporter fullyDisplayedReporter =
FullyDisplayedReporter.getInstance();

private @NotNull IConnectionStatusProvider connectionStatusProvider =
Expand Down Expand Up @@ -2097,6 +2097,13 @@ public void setEnableTimeToFullDisplayTracing(final boolean enableTimeToFullDisp
return fullyDisplayedReporter;
}

@ApiStatus.Internal
@TestOnly
public void setFullyDisplayedReporter(
final @NotNull FullyDisplayedReporter fullyDisplayedReporter) {
this.fullyDisplayedReporter = fullyDisplayedReporter;
}

/**
* Whether OPTIONS requests should be traced.
*
Expand Down