Skip to content

Commit 8acddb6

Browse files
committed
ActivityLifecycleIntegration now restart app start in AppStartMetrics in perfv1, too
updated tests
1 parent bb0b52a commit 8acddb6

File tree

6 files changed

+348
-226
lines changed

6 files changed

+348
-226
lines changed

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,16 @@ WeakHashMap<Activity, ITransaction> getActivitiesWithOngoingTransactions() {
671671
return activitiesWithOngoingTransactions;
672672
}
673673

674+
@TestOnly
675+
@NotNull WeakHashMap<Activity, ActivityLifecycleTimeSpan> getActivityLifecycleMap() {
676+
return activityLifecycleMap;
677+
}
678+
679+
@TestOnly
680+
void setFirstActivityCreated(boolean firstActivityCreated) {
681+
this.firstActivityCreated = firstActivityCreated;
682+
}
683+
674684
@TestOnly
675685
@NotNull
676686
ActivityFramesTracker getActivityFramesTracker() {
@@ -697,33 +707,21 @@ WeakHashMap<Activity, ISpan> getTtfdSpanMap() {
697707

698708
private void setColdStart(final @Nullable Bundle savedInstanceState) {
699709
if (!firstActivityCreated) {
700-
// if Activity has savedInstanceState then its a warm start
701-
// https://developer.android.com/topic/performance/vitals/launch-time#warm
702-
// SentryPerformanceProvider sets this already
703-
// pre-performance-v2: back-fill with best guess
704-
if (options != null && !options.isEnablePerformanceV2()) {
710+
final @NotNull TimeSpan appStartSpan = AppStartMetrics.getInstance().getAppStartTimeSpan();
711+
// If the app start span already started and stopped, it means the app restarted without
712+
// killing the process, so we are in a warm start
713+
// If the app has an invalid cold start, it means it was started in the background, like
714+
// via BroadcastReceiver, so we consider it a warm start
715+
if ((appStartSpan.hasStarted() && appStartSpan.hasStopped())
716+
|| (!AppStartMetrics.getInstance().isColdStartValid())) {
717+
AppStartMetrics.getInstance().restartAppStart(lastPausedUptimeMillis);
718+
AppStartMetrics.getInstance().setAppStartType(AppStartMetrics.AppStartType.WARM);
719+
} else {
705720
AppStartMetrics.getInstance()
706721
.setAppStartType(
707722
savedInstanceState == null
708723
? AppStartMetrics.AppStartType.COLD
709724
: AppStartMetrics.AppStartType.WARM);
710-
} else {
711-
final @NotNull TimeSpan appStartSpan = AppStartMetrics.getInstance().getAppStartTimeSpan();
712-
// If the app start span already started and stopped, it means the app restarted without
713-
// killing the process, so we are in a warm start
714-
// If the app has an invalid cold start, it means it was started in the background, like
715-
// via BroadcastReceiver, so we consider it a warm start
716-
if ((appStartSpan.hasStarted() && appStartSpan.hasStopped())
717-
|| (!AppStartMetrics.getInstance().isColdStartValid())) {
718-
AppStartMetrics.getInstance().restartAppStart(lastPausedUptimeMillis);
719-
AppStartMetrics.getInstance().setAppStartType(AppStartMetrics.AppStartType.WARM);
720-
} else {
721-
AppStartMetrics.getInstance()
722-
.setAppStartType(
723-
savedInstanceState == null
724-
? AppStartMetrics.AppStartType.COLD
725-
: AppStartMetrics.AppStartType.WARM);
726-
}
727725
}
728726
}
729727
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,4 @@ synchronized void onAppStartDone() {
232232
}
233233
}
234234
}
235-
236-
@TestOnly
237-
@Nullable
238-
Application.ActivityLifecycleCallbacks getActivityCallback() {
239-
return activityCallback;
240-
}
241235
}

0 commit comments

Comments
 (0)