Skip to content

Fix: Fix native crash when displaying battery levels#457

Merged
d4rken merged 1 commit intomainfrom
fix/compose-float-equals-crash
Mar 20, 2026
Merged

Fix: Fix native crash when displaying battery levels#457
d4rken merged 1 commit intomainfrom
fix/compose-float-equals-crash

Conversation

@d4rken
Copy link
Member

@d4rken d4rken commented Mar 20, 2026

What changed

Fixed a native crash that could happen when the app displays or updates battery levels for AirPods. The crash occurred during screen refreshes and could affect the main dashboard, case-open popup, and home screen widgets.

Technical Context

  • Root cause: Compose runtime's ComposerImpl.changed() boxes Float? parameters and calls Float.equals() at the ART native level, triggering a known JIT/AOT compilation crash. Non-null Float parameters use a primitive overload that avoids boxing entirely.
  • All composable functions that accepted nullable battery percentages (Float?) now use non-null Float with a sentinel value (BATTERY_UNKNOWN = -1f). Two small extension functions (toBatteryFloat() / toBatteryOrNull()) centralize the conversion at the boundary between domain models (which correctly use null for unknown) and UI composables.
  • Also fixed WidgetRenderState data classes which are passed as composable parameters — their auto-generated equals() would internally call Float.equals() on nullable fields, hitting the same crash path.

ComposerImpl.changed() boxes Float? and calls Float.equals() at the ART native level, triggering a known crash. Non-null Float params use the primitive overload with no boxing.

Introduces BATTERY_UNKNOWN sentinel, toBatteryFloat(), and toBatteryOrNull() extensions to eliminate Float? from all composable signatures and WidgetRenderState data classes.
@d4rken d4rken added the bug Something isn't working label Mar 20, 2026
@d4rken d4rken merged commit 6e9b275 into main Mar 20, 2026
10 checks passed
@d4rken d4rken deleted the fix/compose-float-equals-crash branch March 20, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant