Skip to content

Commit c872d8e

Browse files
committed
firebase-perf: TODO pointing at causal-signal alternatives for app-start detection
The timing-window heuristic in resolveIsStartedFromBackground() infers "was this process forked to launch an Activity?" from the ordering of a posted runnable vs the first onActivityCreated callback. That ordering already shifted once on API 34+ (caused the original bug fixed in PR #7281, and the threshold-too-tight follow-up in #8103) and could shift again on future OS versions. Add a TODO documenting two cleaner alternatives so the next maintainer doesn't have to re-derive them: - API 35+: ApplicationStartInfo / getHistoricalProcessStartReasons gives the OS's authoritative start reason (LAUNCHER, SERVICE, CONTENT_PROVIDER, ...). Removes the heuristic entirely on supported devices. - API 34: RunningAppProcessInfo.importanceReasonCode + .importance captured early in FirebasePerfEarly (before our own ContentProvider work mutates the cause), combined with the timing window as a fallback. Comment-only change; no behavior or test surface affected.
1 parent b8f20ea commit c872d8e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,25 @@ private void recordOnDrawFrontOfQueue() {
347347
* before `onActivityCreated`, the
348348
* assumption is that it was called immediately before the activity lifecycle callbacks in a
349349
* foreground start.
350-
* See b/339891952.
350+
* See b/339891952 and https://github.com/firebase/firebase-android-sdk/issues/8103.
351+
*
352+
* <p>TODO(b/339891952): Replace this timing-window heuristic with a causal signal.
353+
* The current approach infers "was the process forked to launch an Activity?" from the
354+
* ordering of a posted runnable vs the first onActivityCreated callback, which is
355+
* inherently fragile (its calibration depends on Android scheduling behavior that has
356+
* already shifted once on API 34+ and could shift again). Better candidates:
357+
* <ul>
358+
* <li>API 35+: use {@code ActivityManager.getHistoricalProcessStartReasons} /
359+
* {@code ApplicationStartInfo}, which authoritatively reports the start reason
360+
* ({@code START_REASON_LAUNCHER}, {@code START_REASON_SERVICE},
361+
* {@code START_REASON_CONTENT_PROVIDER}, etc.). This removes the heuristic
362+
* entirely on supported devices.
363+
* <li>API 34: capture {@code ActivityManager.RunningAppProcessInfo.importanceReasonCode}
364+
* and {@code .importance} once early in {@code FirebasePerfEarly} (before any of
365+
* our own ContentProvider work mutates the cause), and combine with the timing
366+
* window as a fallback for ambiguous cases.
367+
* </ul>
368+
* Adopting either of these would also let the API-34-vs-pre-34 branch below collapse.
351369
*/
352370
private void resolveIsStartedFromBackground() {
353371
// If the mainThreadRunnableTime is null, either the runnable hasn't run, or this check has

0 commit comments

Comments
 (0)