Skip to content

fix(android): [Data Collection 15] Scope device info cache to SDK options#5831

Draft
adinauer wants to merge 1 commit into
feat/data-collection-user-infofrom
fix/data-collection-device-info-options
Draft

fix(android): [Data Collection 15] Scope device info cache to SDK options#5831
adinauer wants to merge 1 commit into
feat/data-collection-user-infofrom
fix/data-collection-device-info-options

Conversation

@adinauer

@adinauer adinauer commented Jul 24, 2026

Copy link
Copy Markdown
Member

PR Stack (Data Collection)


📜 Description

Scope DeviceInfoUtil to each SentryAndroidOptions instance instead of keeping one process-global singleton.

The existing DeviceInfoUtil.getInstance(context, options) entry point remains, but now delegates to a lazily initialized utility owned by the supplied options. Repeated calls with the same options reuse cached device information, while different SDK initializations keep their collection policy, logger, connection provider, root-check setting, and additional-context settings isolated.

Remove the test-only global reset because fresh options now provide test isolation naturally.

💡 Motivation and Context

The user information policy introduced in the preceding stack PR exposed a pre-existing lifecycle problem: Android auto-init followed by manual init could continue reading the first initialization's options from the process-global DeviceInfoUtil. That could attach device.id despite the active initialization setting dataCollection.userInfo=false, and could also retain stale additional-context and root-check behavior.

Owning the cache from SentryAndroidOptions gives every SDK initialization one internally consistent utility without a static map or process-lifetime references to old options.

Refs #5666

💚 How did you test it?

  • ./gradlew spotlessApply apiDump
  • ./gradlew :sentry-android-core:testDebugUnitTest --tests='io.sentry.android.core.DeviceInfoUtilTest' --tests='io.sentry.android.core.DefaultAndroidEventProcessorTest' --tests='io.sentry.android.core.ApplicationExitInfoEventProcessorTest' --tests='io.sentry.android.core.InternalSentrySdkTest' :sentry-android-core:apiCheck :sentry-android-core:spotlessJavaCheck :sentry-android-core:spotlessKotlinCheck
  • git diff --check

📝 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.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Continue the remaining Data Collection configuration and documentation work.

#skip-changelog

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

Store DeviceInfoUtil on each SentryAndroidOptions instance so repeated SDK initializations cannot reuse stale collection policy or Android services. Preserve lazy initialization while allowing old and new clients to retain their own device context.

Refs #5666

Co-Authored-By: Claude <noreply@anthropic.com>
@sentry

sentry Bot commented Jul 24, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.48.0 (1) release

⚙️ sentry-android Build Distribution Settings

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.

1 participant