Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
AppStartMetrics stops appStartProfiler only if no activity ever started
  • Loading branch information
stefanosiano committed Aug 8, 2024
commit 8ede882a3b8fe31c32f192f5c731589dff683b75
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ public void registerApplicationForegroundCheck(final @NotNull Application applic
// if no activity has ever been created, app was launched in background
if (onCreateTime == null) {
appLaunchedInForeground = false;

// we stop the app start profiler, as it's useless and likely to timeout
if (appStartProfiler != null && appStartProfiler.isRunning()) {
appStartProfiler.close();
appStartProfiler = null;
}
}
application.unregisterActivityLifecycleCallbacks(instance);
// we stop the app start profiler, as it's useless and likely to timeout
if (appStartProfiler != null && appStartProfiler.isRunning()) {
appStartProfiler.close();
appStartProfiler = null;
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ class AppStartMetricsTest {
verify(profiler).close()
}

@Test
fun `if activity is started, does not stop app start profiler if running`() {
val profiler = mock<ITransactionProfiler>()
whenever(profiler.isRunning).thenReturn(true)
AppStartMetrics.getInstance().appStartProfiler = profiler
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())

AppStartMetrics.getInstance().registerApplicationForegroundCheck(mock())
// Job on main thread checks if activity was launched
Shadows.shadowOf(Looper.getMainLooper()).idle()

verify(profiler, never()).close()
}

@Test
fun `if app start span is longer than 1 minute, appStartTimeSpanWithFallback returns an empty span`() {
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
Expand Down