Skip to content

fix(android): Remove AndroidRuntimeManager to prevent ANRs during SDK init#5127

Open
romtsn wants to merge 3 commits intomainfrom
rz/fix/strict-mode-anrs
Open

fix(android): Remove AndroidRuntimeManager to prevent ANRs during SDK init#5127
romtsn wants to merge 3 commits intomainfrom
rz/fix/strict-mode-anrs

Conversation

@romtsn
Copy link
Member

@romtsn romtsn commented Feb 27, 2026

📜 Description

Removes AndroidRuntimeManager, IRuntimeManager, and NeutralRuntimeManager entirely. All operations previously wrapped in runWithRelaxedPolicy() are now called directly (inlined).

Also removes the runtimeManager field, getter, and setter from SentryOptions.

💡 Motivation and Context

AndroidRuntimeManager.runWithRelaxedPolicy() temporarily disables Android's StrictMode policies around disk I/O during SDK init. However, the StrictMode.setVmPolicy() / StrictMode.setThreadPolicy() calls themselves trigger binder IPC under the hood, causing ANRs on the main thread.

Sentry evidence: 3 major ANR issues across versions 8.24.0–8.32.0, affecting devices on Android 11–16:

All stack traces point to runWithRelaxedPolicy() during SentryAndroid.init().

Why removal is safe: StrictMode only logs warnings in production by default. Apps that configure StrictMode with penaltyDeath() do so consciously and accept the consequences. ANRs are far worse than StrictMode violations.

💚 How did you test it?

  • ./gradlew :sentry:test — passes
  • ./gradlew :sentry-android-core:testDebugUnitTest — passes
  • ./gradlew spotlessApply apiDump — formatting and API dump regenerated
  • rg "IRuntimeManager|RuntimeManager|runWithRelaxedPolicy|runtimeManager" — returns no matches in source

📝 Checklist

  • I added GH Issue ID & Linear ID
  • 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

Monitor SDK crash dashboards to confirm the 3 ANR issues (SDK-CRASHES-JAVA-32FQ, SDK-CRASHES-JAVA-32PH, SDK-CRASHES-JAVA-32Q9) stop appearing in new versions.

… init

StrictMode.setVmPolicy()/setThreadPolicy() calls inside
runWithRelaxedPolicy() triggered binder IPC on the main thread, causing
ANRs (SDK-CRASHES-JAVA-32FQ 34k+, SDK-CRASHES-JAVA-32PH 21k+,
SDK-CRASHES-JAVA-32Q9 18k+ events). StrictMode only logs warnings in
production by default, so relaxing it is unnecessary and harmful.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (screenshot) Add screenshot masking using view hierarchy by romtsn in #5077

Bug Fixes 🐛

  • (android) Remove AndroidRuntimeManager to prevent ANRs during SDK init by romtsn in #5127
  • Safe unregister SystemEventsBroadcastReceiver by kollesnica1337 in #5106

Internal Changes 🔧

Deps

  • Bump github/codeql-action from 4.32.2 to 4.32.4 by dependabot in #5109
  • Bump getsentry/craft from 2.21.2 to 2.21.7 by dependabot in #5110

🤖 This preview updates automatically when you update the PR.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 321.02 ms 368.40 ms 47.37 ms
Size 1.58 MiB 2.29 MiB 720.30 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
e59e22a 329.74 ms 383.31 ms 53.57 ms
fc5ccaf 270.49 ms 363.90 ms 93.41 ms
d15471f 361.89 ms 378.07 ms 16.18 ms
d15471f 322.58 ms 396.08 ms 73.50 ms
abfcc92 304.04 ms 370.33 ms 66.29 ms
91bb874 310.68 ms 359.24 ms 48.56 ms
ab8a72d 316.24 ms 356.38 ms 40.14 ms
d15471f 286.65 ms 314.68 ms 28.03 ms
6727e14 337.22 ms 373.94 ms 36.71 ms
f064536 329.00 ms 395.62 ms 66.62 ms

App size

Revision Plain With Sentry Diff
e59e22a 1.58 MiB 2.20 MiB 635.34 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
ab8a72d 1.58 MiB 2.12 MiB 551.55 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
6727e14 1.58 MiB 2.28 MiB 718.64 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB

Previous results on branch: rz/fix/strict-mode-anrs

Startup times

Revision Plain With Sentry Diff
a708db7 319.54 ms 368.96 ms 49.42 ms
0d20f00 322.96 ms 422.59 ms 99.63 ms

App size

Revision Plain With Sentry Diff
a708db7 1.58 MiB 2.29 MiB 720.29 KiB
0d20f00 1.58 MiB 2.29 MiB 720.29 KiB

@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

@romtsn romtsn force-pushed the rz/fix/strict-mode-anrs branch from 715e286 to 5518ab9 Compare February 27, 2026 14:00
This test validated that StrictMode with penaltyDeath() didn't crash
during SDK init. Since we removed the RuntimeManager that relaxed
StrictMode, this test is no longer applicable — the SDK no longer
attempts to suppress StrictMode violations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@romtsn romtsn force-pushed the rz/fix/strict-mode-anrs branch from 5518ab9 to 57b2561 Compare February 27, 2026 14:01
@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

1 similar comment
@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

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.

Multiple ANRs on Init after upgrading from 8.18.0 to 8.25.0

1 participant