Skip to content

fix(breadcrumbs): Unregister SystemEventsBroadcastReceiver when entering background #4338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 17, 2025

Conversation

romtsn
Copy link
Member

@romtsn romtsn commented Apr 15, 2025

📜 Description

Some background

Android 14 introduced new behavior for broadcast receivers, and our SystemEvents receiver (used to add breadcrumbs like screen on/off, airplane mode change, etc.) is falling under this. What's happening is the process gets cached for some period of time (can be hours or days) and after getting uncached it receives all those pending broadcasts in a quick succession which most likely causes ANRs. This also correlates with the numbers we see in SDKCD where the biggest number of ANRs is coming from Android 14+.

I did some tests locally and it is indeed happening as described on the screenshot.


  • SystemEventsBreadcrumbsIntegration is now lifecycle-aware:
    • When an app enters background we unregister the receiver
    • When it enters foreground back, we enqueue a task to register the receiver again
    • This way we avoid being registered in the OS for all those broadcasts and do not receive all the pending ones after the app gets uncached

💡 Motivation and Context

Closes #4294
Internal customer case

💚 How did you test it?

Manually + automated

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

SentryLevel.INFO,
"androidx.lifecycle is not available, AppLifecycleIntegration won't be installed",
e);
SentryLevel.WARNING,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but I just noticed while testing no androidx.lifecycle case that it's noisy and decided to change that

Copy link
Contributor

github-actions bot commented Apr 15, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 407.86 ms 446.78 ms 38.92 ms
Size 1.58 MiB 2.08 MiB 506.55 KiB

Previous results on branch: rz/fix/system-events-receiver-anrs

Startup times

Revision Plain With Sentry Diff
70f2879 392.29 ms 428.98 ms 36.69 ms
1c3deaf 398.74 ms 423.76 ms 25.02 ms

App size

Revision Plain With Sentry Diff
70f2879 1.58 MiB 2.08 MiB 506.59 KiB
1c3deaf 1.58 MiB 2.08 MiB 506.58 KiB

Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I left two small comments!

@romtsn romtsn merged commit d9ab996 into main Apr 17, 2025
39 checks passed
@romtsn romtsn deleted the rz/fix/system-events-receiver-anrs branch April 17, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SystemEventsBroadcastReceiver may produce ANR when receiving android.intent.action.SCREEN_OFF
2 participants