|
25 | 25 | import com.google.android.gms.common.util.VisibleForTesting;
|
26 | 26 | import com.google.firebase.perf.logging.AndroidLogger;
|
27 | 27 | import com.google.firebase.perf.provider.FirebasePerfProvider;
|
| 28 | +import com.google.firebase.perf.session.PerfSession; |
28 | 29 | import com.google.firebase.perf.session.SessionManager;
|
29 | 30 | import com.google.firebase.perf.transport.TransportManager;
|
30 | 31 | import com.google.firebase.perf.util.Clock;
|
@@ -65,6 +66,33 @@ public class AppStartTrace implements ActivityLifecycleCallbacks {
|
65 | 66 | private static volatile AppStartTrace instance;
|
66 | 67 | private static ExecutorService executorService;
|
67 | 68 |
|
| 69 | + private boolean isRegisteredForLifecycleCallbacks = false; |
| 70 | + private final TransportManager transportManager; |
| 71 | + private final Clock clock; |
| 72 | + private Context appContext; |
| 73 | + /** |
| 74 | + * The first time onCreate() of any activity is called, the activity is saved as launchActivity. |
| 75 | + */ |
| 76 | + private WeakReference<Activity> launchActivity; |
| 77 | + /** |
| 78 | + * The first time onResume() of any activity is called, the activity is saved as appStartActivity |
| 79 | + */ |
| 80 | + private WeakReference<Activity> appStartActivity; |
| 81 | + |
| 82 | + /** |
| 83 | + * If the time difference between app starts and creation of any Activity is larger than |
| 84 | + * MAX_LATENCY_BEFORE_UI_INIT, set mTooLateToInitUI to true and we don't send AppStart Trace. |
| 85 | + */ |
| 86 | + private boolean isTooLateToInitUI = false; |
| 87 | + |
| 88 | + private Timer appStartTime = null; |
| 89 | + private Timer onCreateTime = null; |
| 90 | + private Timer onStartTime = null; |
| 91 | + private Timer onResumeTime = null; |
| 92 | + |
| 93 | + private PerfSession startSession; |
| 94 | + private boolean isStartedFromBackground = false; |
| 95 | + |
68 | 96 | /**
|
69 | 97 | * Called from onCreate() method of an activity by instrumented byte code.
|
70 | 98 | *
|
@@ -118,32 +146,6 @@ static AppStartTrace getInstance(TransportManager transportManager, Clock clock)
|
118 | 146 | return instance;
|
119 | 147 | }
|
120 | 148 |
|
121 |
| - private boolean isRegisteredForLifecycleCallbacks = false; |
122 |
| - private final TransportManager transportManager; |
123 |
| - private final Clock clock; |
124 |
| - private Context appContext; |
125 |
| - /** |
126 |
| - * The first time onCreate() of any activity is called, the activity is saved as launchActivity. |
127 |
| - */ |
128 |
| - private WeakReference<Activity> launchActivity; |
129 |
| - /** |
130 |
| - * The first time onResume() of any activity is called, the activity is saved as appStartActivity |
131 |
| - */ |
132 |
| - private WeakReference<Activity> appStartActivity; |
133 |
| - |
134 |
| - /** |
135 |
| - * If the time difference between app starts and creation of any Activity is larger than |
136 |
| - * MAX_LATENCY_BEFORE_UI_INIT, set mTooLateToInitUI to true and we don't send AppStart Trace. |
137 |
| - */ |
138 |
| - private boolean isTooLateToInitUI = false; |
139 |
| - |
140 |
| - private Timer appStartTime = null; |
141 |
| - private Timer onCreateTime = null; |
142 |
| - private Timer onStartTime = null; |
143 |
| - private Timer onResumeTime = null; |
144 |
| - |
145 |
| - private boolean isStartedFromBackground = false; |
146 |
| - |
147 | 149 | AppStartTrace(
|
148 | 150 | @NonNull TransportManager transportManager,
|
149 | 151 | @NonNull Clock clock,
|
@@ -214,6 +216,7 @@ public synchronized void onActivityResumed(Activity activity) {
|
214 | 216 |
|
215 | 217 | onResumeTime = clock.getTime();
|
216 | 218 | this.appStartTime = FirebasePerfProvider.getAppStartTime();
|
| 219 | + this.startSession = SessionManager.getInstance().perfSession(); |
217 | 220 | AndroidLogger.getInstance()
|
218 | 221 | .debug(
|
219 | 222 | "onResume(): "
|
@@ -260,9 +263,7 @@ private void logAppStartTrace() {
|
260 | 263 | .setDurationUs(onStartTime.getDurationMicros(onResumeTime));
|
261 | 264 | subtraces.add(traceMetricBuilder.build());
|
262 | 265 |
|
263 |
| - metric |
264 |
| - .addAllSubtraces(subtraces) |
265 |
| - .addPerfSessions(SessionManager.getInstance().perfSession().build()); |
| 266 | + metric.addAllSubtraces(subtraces).addPerfSessions(this.startSession.build()); |
266 | 267 |
|
267 | 268 | transportManager.log(metric.build(), ApplicationProcessState.FOREGROUND_BACKGROUND);
|
268 | 269 | }
|
|
0 commit comments