Skip to content

Android: fill WorkoutSummary from Health Connect workout keys - #535

Open
ChandraChaan wants to merge 1 commit into
carp-dk:mainfrom
ChandraChaan:fix/android-workout-summary
Open

ChandraChaan wants to merge 1 commit into
carp-dk:mainfrom
ChandraChaan:fix/android-workout-summary

Conversation

@ChandraChaan

Copy link
Copy Markdown

Fixes #492.

Problem

On Android, HealthDataPoint.workoutSummary is always null for WORKOUT records. The Kotlin reader (handleWorkoutData in HealthDataReader.kt) sends workoutActivityType, totalDistance, totalEnergyBurned and totalSteps, but WorkoutSummary.fromHealthDataPoint and the check in HealthDataPoint.fromHealthDataPoint only look for the snake_case keys (workout_type, total_distance, ...) that the iOS reader sends.

Fix

  • WorkoutSummary.fromHealthDataPoint reads the snake_case keys first and falls back to the camelCase ones, so iOS behaves exactly as before.
  • HealthDataPoint.fromHealthDataPoint also builds a summary when workoutActivityType is present, which every Android workout has.

I fixed this on the Dart side rather than adding snake_case keys in Kotlin, so it also works without a native rebuild and can be covered by unit tests. Happy to move it into HealthDataReader.kt instead if you prefer to keep the key mapping native.

Tests

Added four cases to test/unit/health_value_parsing_test.dart:

  • an Android-shaped workout produces a summary with type, distance, energy and steps
  • an Android workout without totals still produces a summary with zeros
  • iOS snake_case keys still take precedence
  • non-workout points still have no summary

The two Android cases fail on main and pass with this change. Note that flutter test on current main already has 49 failing tests from the device_info_plus mocking issue addressed in #523; this change adds no new failures.

On Android, HealthDataPoint.workoutSummary was always null because the
Kotlin reader sends workoutActivityType, totalDistance, totalEnergyBurned
and totalSteps, while WorkoutSummary only read the snake_case keys that
iOS sends. Fall back to the camelCase keys so the summary is filled on
both platforms.

Fixes carp-dk#492
iarata added a commit that referenced this pull request Nov 11, 2026
…alth Connect workout keys

HealthDataPoint.workoutSummary was null for every Android workout:
WorkoutSummary read only the snake_case keys that iOS sends, while
Android sends the camelCase keys of WorkoutHealthValue. The PR reads the
snake_case key first and falls back to the camelCase one, so on Android
the workouts of reads, pages, reads by UUID and changes all get a
summary: the workout's type name, as in workoutActivityType, and its
totals, 0 for a missing one as on iOS. iOS sends both sets of keys, so
its summaries do not change.

It merges as is. Adapted: the new tests are formatted to the repo's 120
columns, and the iOS precedence test uses the reply of 14.0.0's iOS
code (the RUNNING name, and both the whole-number summary totals and the
workout value's). WorkoutSummary.toString had no ', ' after the workout
type; the Android test checks it.
@ChandraChaan

Copy link
Copy Markdown
Author

Hi maintainers, a gentle ping on this one when you have a moment. It fixes #492: on Android workoutSummary is always null because the Dart side only reads the snake_case keys that iOS sends. iOS behaviour is unchanged. Happy to make any changes. Thanks!

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.

[Android] HealthDataPoint.workoutSummary is always null — Kotlin emits camelCase keys, Dart parser expects snake_case

1 participant