fix(android): Drop inflated app start for background-spawned processes on API 35+ - #5841
Draft
alwx wants to merge 3 commits into
Draft
fix(android): Drop inflated app start for background-spawned processes on API 35+#5841alwx wants to merge 3 commits into
alwx wants to merge 3 commits into
Conversation
…s on API 35+ When the OS spawns the process for background work (FCM push, job, service, broadcast, etc.) and the user opens the app later, the app start stayed anchored at background process creation, inflating the reported cold start by the whole idle gap. On API 35+ we now use ApplicationStartInfo.getReason() to detect background process starts and mark them as not launched in foreground, so the first created activity re-classifies them as a warm start anchored at activity creation.
📲 Install BuildsAndroid
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
On API 35+, use
ApplicationStartInfo.getReason()to detect processes the OS spawned for background work (FCM push, job, service, broadcast, alarm, backup, boot_complete, content_provider) and mark them as not launched in foreground. The first created activity then re-classifies the launch as a warm start re-anchored at activity creation, instead of reporting the whole background idle gap as an inflated cold start.Change is confined to
AppStartMetrics.registerLifecycleCallbacks+ a small privateisBackgroundStartReason(int)helper. Unknown/future reasons are treated as user-initiated (no regression). Behavior for user launches (launcher/recents/start_activity) and pre-API-35 is unchanged.💡 Motivation and Context
When a process is spawned in the background (e.g. by an FCM push) and the user opens the app seconds later,
appLaunchedInForegroundwas only evaluated lazily and the app start span stayed anchored at background process creation. On API 35+ the main-looper idle check that would otherwise mark the launch as headless is skipped once the start type is resolved fromApplicationStartInfo, so the inflated cold start (idle gap up to ~1 min) leaked through intoapp_start_cold.Reported downstream in React Native:
Related prior work on app start (mis)classification: #3608, #4920, #4999.
💚 How did you test it?
Added Robolectric tests in
AppStartMetricsTestApi35:onActivityCreated(even for a sub-1-minute gap)../gradlew :sentry-android-core:testReleaseUnitTest --tests "*AppStartMetrics*"andspotlessCheckpass.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Follow-up: API < 35 has no reliable process start reason, so a narrow race in the main-looper idle check remains there; not addressed here.