Skip to content

Conversation

@Shahroz16
Copy link
Contributor

closes: https://linear.app/customerio/issue/MBL-984/android-sdk-running-into-anr-during-initialization-cont-gh-470

This supports a case, where nullable inbuilt device attributes are sent by Device.

Changes:
This includes updating the BuildStore and DeviceStore interfaces and their implementations to make fields like brand, model, and OS version optional. JSON serialization logic was updated accordingly, and tests were added to verify the changes.

This is a potential fix for the Kotlin reflection crash.

However, the more robust solution would be to update the Kotlin serialization library to 1.9.0, which includes proper handling for unexpected values (introduced in 1.8.1 – PR #2911). But that upgrade would require bumping the Kotlin version to 2.2.0.

@Shahroz16 Shahroz16 requested a review from a team as a code owner July 21, 2025 22:19
@Shahroz16 Shahroz16 requested review from Copilot and removed request for a team July 21, 2025 22:19
@github-actions
Copy link

github-actions bot commented Jul 21, 2025

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a crash that occurs when device attributes are nullable during Android SDK initialization. The fix updates the BuildStore and DeviceStore interfaces to handle nullable device attributes, preventing Kotlin reflection crashes when certain device properties are null.

  • Changed device attribute fields (brand, model, manufacturer, OS version, locale) from non-null to nullable types
  • Updated JSON serialization logic to handle nullable values in device attributes
  • Added test coverage to verify nullable device attributes are properly serialized and sent

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/src/main/kotlin/io/customer/sdk/data/store/BuildStore.kt Updated interface and implementation to make device attribute fields nullable
core/src/main/kotlin/io/customer/sdk/data/store/DeviceStore.kt Updated interface to return nullable device attributes and modified buildDeviceAttributes return type
common-test/src/main/java/io/customer/commontest/util/DeviceStoreStub.kt Updated test stub to match new nullable interface signatures
datapipelines/src/test/java/io/customer/datapipelines/testutils/extensions/JsonExtensions.kt Generalized JSON extension functions to handle nullable values instead of just CustomAttributes
datapipelines/src/test/java/io/customer/datapipelines/DataPipelinesCompatibilityTests.kt Added test case to verify nullable device attributes are properly handled in device registration

override fun buildDeviceAttributes(): Map<String, Any> {
override fun buildDeviceAttributes(): Map<String, Any?> {
return mapOf(
"device_os" to deviceOSVersion,
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

The device_os field is being set to deviceOSVersion (an Int?) but should likely be set to a string representation of the OS name like "Android". Based on the test, device_os should be "Android" and device_os_version should be the version number.

Suggested change
"device_os" to deviceOSVersion,
"device_os" to "Android", // Set to OS name
"device_os_version" to deviceOSVersion, // Add version number

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.11%. Comparing base (f577014) to head (9491f29).
Report is 21 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #584      +/-   ##
============================================
+ Coverage     63.15%   67.11%   +3.95%     
- Complexity      514      573      +59     
============================================
  Files           118      125       +7     
  Lines          3602     3801     +199     
  Branches        445      465      +20     
============================================
+ Hits           2275     2551     +276     
+ Misses         1186     1075     -111     
- Partials        141      175      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jul 21, 2025

📏 SDK Binary Size Comparison Report

No changes detected in SDK binary size ✅

@github-actions
Copy link

  • kotlin_compose: mbl-984 (1753136423)

@Shahroz16 Shahroz16 self-assigned this Jul 21, 2025
@github-actions
Copy link

Build available to test
Version: mbl-984-SNAPSHOT
Repository: https://s01.oss.sonatype.org/content/repositories/snapshots/

@github-actions
Copy link

  • java_layout: mbl-984 (1753136438)

@github-actions
Copy link

  • java_layout: mbl-984 (1753209017)

@github-actions
Copy link

  • kotlin_compose: mbl-984 (1753209002)

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.

4 participants