fix(android): Improve app start type detection with main thread timing#4999
fix(android): Improve app start type detection with main thread timing#4999
Conversation
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e59e22a | 368.02 ms | 432.00 ms | 63.98 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| b3d8889 | 420.46 ms | 453.71 ms | 33.26 ms |
| fcec2f2 | 357.47 ms | 447.32 ms | 89.85 ms |
| d15471f | 304.55 ms | 408.43 ms | 103.87 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
| fc5ccaf | 276.52 ms | 370.46 ms | 93.93 ms |
| 3d205d0 | 352.15 ms | 432.53 ms | 80.38 ms |
| b03edbb | 352.20 ms | 423.69 ms | 71.49 ms |
| a5ab36f | 316.83 ms | 394.54 ms | 77.71 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e59e22a | 1.58 MiB | 2.20 MiB | 635.34 KiB |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| b3d8889 | 1.58 MiB | 2.10 MiB | 535.07 KiB |
| fcec2f2 | 1.58 MiB | 2.12 MiB | 551.50 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
| fc5ccaf | 1.58 MiB | 2.13 MiB | 557.54 KiB |
| 3d205d0 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| b03edbb | 1.58 MiB | 2.13 MiB | 557.32 KiB |
| a5ab36f | 1.58 MiB | 2.12 MiB | 555.26 KiB |
Previous results on branch: fix/app-start-warm-detection
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 376c795 | 307.44 ms | 356.18 ms | 48.74 ms |
| eadb118 | 318.81 ms | 365.04 ms | 46.23 ms |
| d05ca28 | 315.98 ms | 357.10 ms | 41.12 ms |
| 12d79b2 | 324.79 ms | 404.20 ms | 79.41 ms |
| 1911f98 | 335.29 ms | 451.47 ms | 116.18 ms |
| cf6c632 | 283.92 ms | 361.45 ms | 77.53 ms |
| 5a370a1 | 359.02 ms | 429.56 ms | 70.54 ms |
| 28e7b9d | 311.83 ms | 366.94 ms | 55.11 ms |
| a0d0a05 | 303.68 ms | 339.38 ms | 35.70 ms |
| 224c2d6 | 311.50 ms | 361.40 ms | 49.90 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 376c795 | 1.58 MiB | 2.19 MiB | 619.80 KiB |
| eadb118 | 1.58 MiB | 2.19 MiB | 619.66 KiB |
| d05ca28 | 1.58 MiB | 2.19 MiB | 619.66 KiB |
| 12d79b2 | 1.58 MiB | 2.20 MiB | 635.40 KiB |
| 1911f98 | 1.58 MiB | 2.19 MiB | 619.66 KiB |
| cf6c632 | 1.58 MiB | 2.19 MiB | 619.66 KiB |
| 5a370a1 | 1.58 MiB | 2.19 MiB | 619.79 KiB |
| 28e7b9d | 1.58 MiB | 2.19 MiB | 619.78 KiB |
| a0d0a05 | 1.58 MiB | 2.13 MiB | 559.63 KiB |
| 224c2d6 | 1.58 MiB | 2.19 MiB | 619.66 KiB |
|
@sentry review |
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
As firstPost doesn't work on Android 34+ devices
|
@sentry review |
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
sentry-android-integration-tests/sentry-uitest-android-critical/maestro/appStart.yaml
Show resolved
Hide resolved
|
|
||
| // the first activity determines the app start type | ||
| if (activeActivitiesCounter.incrementAndGet() == 1 && !firstDrawDone.get()) { | ||
| final long nowUptimeMs = SystemClock.uptimeMillis(); |
There was a problem hiding this comment.
do we still need this variable given it's just few microseconds apart from activityCreatedUptimeMillis?
romtsn
left a comment
There was a problem hiding this comment.
LGTM, just a couple of comments
- Add support for ApplicationStartInfo API on Android 15+ (API 35) for more accurate cold/warm start detection - Add null safety check for ActivityManager service - Fix detection logic to prevent legacy methods from running when API 35+ already determined start type - Set app start type to WARM when app moves to background (process stays alive) - Add comprehensive test coverage with notification-triggered start scenarios Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
Other
Other
🤖 This preview updates automatically when you update the PR. |
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
...ntry-uitest-android-critical/src/main/java/io/sentry/uitest/android/critical/MainActivity.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
…entry-java into fix/app-start-warm-detection
CHANGELOG.md
Outdated
|
|
||
| ## Unreleased | ||
|
|
||
| ### Fixes |
There was a problem hiding this comment.
we already have the fixes section down here, could you move it?
There was a problem hiding this comment.
that's actually the third one already lol :D
|
|
||
| if (activityManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { | ||
| final List<ApplicationStartInfo> historicalProcessStartReasons = | ||
| activityManager.getHistoricalProcessStartReasons(1); |
There was a problem hiding this comment.
so does this return the current (in-progress) app start?
There was a problem hiding this comment.
Yes, we also double check later to ensure it's the current app launch:
if (info.getStartupState() == ApplicationStartInfo.STARTUP_STATE_STARTED) {
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java
Show resolved
Hide resolved
Add custom SentryShadowActivityManager to mock ApplicationStartInfo for testing cold/warm start detection on Android 15 (API 35). Tests verify the new getHistoricalProcessStartReasons() code path and fallback behavior when the list is empty or invalid. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📜 Description
Improves app start type detection by utilizing the main thread
isIdlecallback andApplicationStartInfoAPIs on API level 35+Fixes #4920
The
firstPostapproach as utilized in the papa library does not seem to work on API level 35+ anymore (See square/papa#63)The changes include:
ApplicationStartInfoAPIs on newer devices,firstIdlemechanism📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps