accurate_step_counter 4.0.0
accurate_step_counter: ^4.0.0 copied to clipboard
Android step counter using hardware sensors and a health foreground service, with live totals, SQLite history, reboot recovery, and optional merge policies.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
4.0.0 - 2026-10-25 #
Breaking #
- Return to Android-only tracking. Remove the experimental HealthKit detector and
healthdependency. Unsupported tracking platforms throwUnsupportedError. stop()flushes and stops auto-logging. UsestartTracking()to resume the complete pipeline.- Deprecate the synchronous legacy
reset(); it fails clearly for hardware daily totals. Use stop, clear logs, and reset native state for an explicit reset. - Fail clearly for missing activity permission or a hardware service that cannot start. Continuous counting uses a health service without a data-sync fallback.
- Align the Flutter SDK minimum with Dart 3.9 (Flutter 3.35).
Added #
- Automatic lifecycle observation and shared concurrent/repeated
startTracking. - Native cadence limits in
StepDetectorConfig; running uses 240/minute and 14,400/hour while walking retains 180/minute and 9,000/hour. - Android acceptance matrix and a package verification record.
- Dart and JVM regression checks for the actual package integration and native restore/rotation rules.
Fixed #
- New-day floors and aggregate baselines, current-date stream queries, original date attribution for cold-start history, and stale queries completing at midnight.
- Shared native event-channel ownership, first logged delta, repeated equal-sized recovery gaps, concurrent imports, and double-counted session totals on import.
- Keep displayed/stored floors out of the raw sensor logging stream; preserve distinct external imports during native startup and historical reconciliation.
- Retain buffered storage operations on write failure and register plugins in the database isolate; acknowledge isolate shutdown before terminating it.
- Persist native offsets, floors, and actual rotation timestamps across process restarts; preserve valid counter batches without impossible detector evidence.
- Validate delayed screen-off batches against the whole elapsed interval and persist rejected increments so a restart cannot resurrect discarded steps.
- Wait for sensor registration before reporting startup success; preserve explicit stop/logout across reboot.
3.1.0 - 2026-07-28 #
Added #
- iOS support via HealthKit (
healthpackage) with filtered step reads and step smoothing. - New internal
IosHealthStepDetectorservice that emits realtime step events from Health app totals. - Cross-platform example flow now handles iOS initialization cleanly.
Changed #
watchTodaySteps()remains immediate and floor-protected while now supporting iOS live step source.- Package positioning updated from Android-only to Android + iOS HealthKit.
Fixed #
- Native event merge now always applies floor protection before emitting (prevents downward jitter on transient resets).
- Rotation drain persists previous day totals into SQLite with date anchoring.
3.0.0 - 2026-07-26 #
Breaking #
- Primary detection is now TYPE_STEP_COUNTER FGS on all Android API 24+ (including Samsung). Previous API≤29 / non-Samsung gate removed.
SmartMergeHelper.mergeStepCountssemantics changed — no longer naivemax(). UsesStepLogic(HC duplication band, sensor overcount at 1.10×, HC can correct downward, server floor). PreferSmartMergeHelper.merge()for fullMergeDecisionflags.- Legacy auto-start of
StepCounterForegroundServiceon app termination is off by default to prevent dual-FGS fights. StepDetectorConfig.useForegroundServiceOnOldDevicesdefaults to false (legacy sensors_plus fallback only).
Added #
- Production-hardened
StepCounterService: prefs persist, reboot detect, burst/minute/hour caps with baseline fold-in, vehicle/bicycle Activity Recognition filter, TYPE_STEP_DETECTOR cross-check, exact midnight alarm, BootReceiver, TimeChangeReceiver, rotation stamps ActivityClassifier+ soft-fail without Play Services (play-services-location)- Dart policies:
StepLogic,MergePolicy,smoothHcReading,RotationGuard,StepRateLimiter - Platform APIs:
setNotificationDisplay,forceUpdateTodaySteps,consumeLastRotation,resetNativeStepState startTracking()— one-call setup (DB + FGS + aggregated logging)- Short aliases:
isBatteryOptimized(),requestBatteryOptimization() - Safe calibration from SQLite today (sensor=0, seed ≤40k) on start
- Native↔SQLite reconcile on aggregated start (fixes undercount after process death)
- Rotation drain on start / resume / step stream
- Ported production policy unit tests under
test/policy/ - Soft
uses-featurefor stepcounter/stepdetector (required=false) - Consumer ProGuard keep rules for services/receivers
Fixed (production DX / hardening) #
- Skip legacy terminated-prefs sync when the native FGS is available (no dual recovery)
- Example + verification check TYPE_STEP_COUNTER FGS, not fallback detector
- Removed 500ms artificial delay from
initSteps(now aliasesstartTracking) - Collapsed duplicate
getTodaySteps/getYesterdayStepsdefinitions - Cold-start day-gap restore stamps
KEY_LAST_ROTATION_*and persists rotated prefs - Activity Recognition PendingIntent uses explicit component + unique request code; receiver in manifest
- Removed Play-risk permissions
USE_EXACT_ALARM,BODY_SENSORS,BODY_SENSORS_BACKGROUND,HIGH_SAMPLING_RATE_SENSORS - Plugin no longer permanently registers a second
TYPE_STEP_COUNTERlistener (battery) - Kotlin unit test matches real MethodChannel API
NotificationChannelcreation guarded for API 24–25 (StepCounterService)dispose()/stopLogging()flush write buffer and cancel flush timer
Migration #
- Bump to
^3.0.0and requestACTIVITY_RECOGNITION+ notifications beforestartTracking(). - Prefer
await steps.startTracking()over the old three-call sequence. - If you relied on naive max merge, switch to
SmartMergeHelper.merge(...)and handleMergeDecision. - Keep notification synced with
setNativeNotificationDisplay(merged)— do not force-write merged HC into sensor baseline. - Supply HC/server yourself (BYO); package does not embed Health Connect SDK.
2.0.0 - 2026-02-28 #
Major: Native Step Service + Smart Merge #
This release promotes the native TYPE_STEP_COUNTER foreground service as the primary detection strategy and adds the SmartMergeHelper utility for combining multiple step sources.
Added #
- SmartMergeHelper — combine sensor + Health Connect + server (naive max in 2.x)
- Native Step Service Status API —
isNativeStepServiceRunning(),isUsingNativeStepService
Changed #
- VERSION BUMP to 2.0.0
- README rewritten for TYPE_STEP_COUNTER architecture
Fixed #
StepCounterService.kt— addedisRunningflag
Removed #
- Stale Hive artifacts
1.9.5 - 2026-02-22 #
Fixed #
- Background isolate
sqfliteinitialization error — AddedDartPluginRegistrant.ensureInitialized()to isolate entry point
1.9.4 - 2026-02-22 #
Added #
- Terminated sync gap reconciliation with idempotent deterministic gap keys
- Single-flight terminated sync to prevent concurrent reprocessing
- Production example flow in example app
1.9.3 - 2026-02-03 #
Added #
- Automatic 30-day log retention policy
- Database write batching (3-second buffer)
- Background isolate for database operations (
StepRecordConfig.lowEndDevice()) - Stream emission throttling (max 10Hz)
1.9.2 - 2026-02-03 #
1.9.1 - 2026-01-28 #
Verified #
- ANR-safe architecture audit: all Kotlin I/O on
Dispatchers.IO, async SharedPreferences, background SQLite
1.9.0 - 2026-01-28 #
1.8.12 and earlier #
See git history for pre-1.9.0 notes.