Step sensor: expose via getSensorStepData, stop bypassing Health Connect - #20
Merged
Merged
Conversation
…lth Connect The step sensor is a steps-only fallback. Previously, when it was active, getData() routed EVERY data type to the sensor store, silently returning empty lists for sleep, heart rate, and daylight. Now getData() always uses Health Connect, and sensor step records are exposed through a dedicated getSensorStepData method (source_name "sensor_step") so callers can merge the two feeds per time bucket instead of choosing one or summing them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ktvCjd71EnESb9fS1AwBs
- getSensorStepData now does its ObjectBox query on Dispatchers.IO via
the plugin's supervised scope, and replies exactly once on Main.
Handler(...).run {} is Kotlin's scope function — it ran the block
inline, so the query and the map serialization were on the platform
thread. SensorStep rows are only pruned by an explicit
clearStepSensorData, so an established sensor user's table is large
enough for that to jank the app on every health fetch.
- An exception in the reply path previously escaped the ad-hoc coroutine
with no handler and left the Dart caller awaiting a reply that never
arrived. Every path now returns success or error exactly once.
- Return empty rather than building the ObjectBox store on demand;
onAttachedToEngine already builds it with a real context, and the
on-demand call passed the plugin instead of a Context.
- fetchCacheData: persist BEFORE advancing last_q_epoch, and advance
only to the window actually read. The cursor is the sole lower bound
on the next read, so moving it past records that were never written
(a throwing put, or steps recorded while Tasks.await blocked) lost
them permanently.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ktvCjd71EnESb9fS1AwBs
…leepData Sleep types are now always routed through getSleepData/_dataSleepQuery on iOS, so the SLEEP_* filter branches in getData() were unreachable and duplicated the category-value mapping already encoded in _requestedIosSleepType. Removed to avoid the two copies drifting. getSleepData() was writing the literal string "unknown" when a sample had no HKDevice, which defeats health_data_point.dart's null-coalescing fallback to Health().deviceId (that fallback only triggers when the key is absent/null). Now omits source_device_id entirely when there's no device, matching the pattern used elsewhere in this file.
Fix duplicate iOS sleep-stage queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to shiftapp_flutter#1529.
The step sensor is meant to be a steps-only fallback, but
getData()short-circuited onstepSensorActiveand sent every data type to the sensor store. SincegetSensorData()only handles STEPS, sleep / heart rate / daylight requests silently returned empty lists whenever sensor mode was on.getData()no longer branches onstepSensorActive— Health Connect always serves it.getSensorStepDatamethod (Kotlin + Dart) returns the sensor's step records, taggedsource_name: "sensor_step", including thefetchCacheDatarefresh that the old path did before reading.Callers merge the two step feeds per time bucket (max, not sum) rather than picking one — see the app PR.
Merge this first, then re-pin the app's pubspec to a tagged ref.
🤖 Generated with Claude Code
https://claude.ai/code/session_018ktvCjd71EnESb9fS1AwBs