Skip to content

fix: Bluetooth-off status, GPS in background, sleep coach card timing, stopped ring clock (#136 #139 #140 #142) - #144

Open
foureight84 wants to merge 9 commits into
mainfrom
fix/batch-2026-11-12
Open

foureight84 wants to merge 9 commits into
mainfrom
fix/batch-2026-11-12

Conversation

@foureight84

Copy link
Copy Markdown
Owner

Fixes #136, #139, #140, #142.

#136: "Connected" while the phone's Bluetooth is off

No onConnectionStateChange arrives when the adapter goes down, and the watchdog skipped its probes while Bluetooth was off. RingBLEClient now listens for ACTION_STATE_CHANGED for every ring family (before this, only CRP did), marks the link disconnected and shows "Phone Bluetooth is off". The watchdog also catches a missed broadcast. Reconnecting when Bluetooth comes back works the same as before.

#139: GPS route stops when the phone is in a pocket

The workout foreground service was health only, so Android 10+ cut off "while using the app" location once the app was in the background. It now also runs as location when the workout records GPS, which needs FOREGROUND_SERVICE_LOCATION and no background-location grant. The GPS filter also accepts fixes up to 15 s old, so fixes the phone delivers in batches with the screen off aren't dropped as stale.

#140: Sleep

  • Coach card written from half a night: while the wearer's Bedtime (a DND window that began by the night's end) or quiet-hours schedule is still open, the card waits, for at most 8 h. A later sync that adds 15+ minutes of sleep rewrites it straight away instead of waiting out the 2 h floor.
  • Sub-minute gap not drawn: the hypnogram now draws the gap minute that the Awake and Records cards already count, ahead of the next record's first block.

#142: Ring clock stops

There's no command to read the ring's clock, so PulseLoop watches the copy a YCBT ring logs of each spot reading it completed. A running clock stamps that copy when the measurement ends. A stopped clock stamps it at the last time we set, or the copy lands nowhere near our reading. Two such cases within 24 h show a card on Today with a guided restart: power off (03 16 01, the vendor's appShutDown(1), offered on every SmartHealth ring), put the ring on its charger, and PulseLoop reconnects and sets the time. The card clears on a healthy reading, a restart, Forget, or when a ring from another family connects. Each spot reading is judged only after a sync pass that delivered vitals history, and only against the closest copy in that pass.

Not done: the weaker "no automatic HR for 2× the interval" hint. An unworn ring looks exactly the same.

Testing

  • ./gradlew testDebugUnitTest: 1700 tests, 0 failures.
  • An independent review of the first commit found 9 issues, all fixed in 092d41c.
  • Not hardware-tested yet: each reporter will get an RC build.
  • CRPSyncEngineTest fails between 19:55 and 20:05 local time, because CRPDecoder.nearSleepDayRollover reads the wall clock. That's pre-existing and unrelated to this PR.

…d, stopped ring clock

- #136: mark the link disconnected as soon as the phone's Bluetooth turns
  off (adapter-state receiver for every ring family, watchdog fallback),
  instead of showing "Connected" until it comes back.
- #139: run the workout foreground service with the location type when the
  workout records GPS, so while-in-use location keeps flowing with the
  phone in a pocket. No background-location grant needed.
- #140: don't write the sleep coach card while the Bedtime / quiet-hours
  window is still open (capped at 8 h), and rewrite it straight away when
  a later sync makes the night longer. The hypnogram now draws a
  sub-minute gap between records that the Awake and Records cards count.
- #142: detect a YCBT ring whose clock has stopped from where it stamps
  its own copy of a spot reading, and offer a guided restart: power off
  (03 16 01, vendor appShutDown(1)), put it on the charger, reconnect.
- #142 detector: judge a pass only when it delivered HR/SpO2 history
  (a sleep-only pass no longer counts as a missing copy), pair each spot
  reading with its closest copy in the pass rather than the first sample in
  the window, clear on any copy short of the evidence threshold, and reset
  on Forget, on connecting another ring family, and after a restart.
- #142 restart: powerOff() reports whether it queued a command; restartRing()
  returns SENT / NOT_CONNECTED / UNSUPPORTED; the walkthrough's state lives in
  TodayScreen so the charger step survives the warning clearing; the Restart
  button is hidden for rings that can't be powered off.
- #140: draw the sub-minute gap ahead of the next record on a tied minute;
  skip the rewrite floor only for 15+ more minutes asleep; an open DND only
  counts as night if it started by the night's end plus an hour.
- #139: remember a refused location type instead of retrying every refresh;
  accept GPS fixes up to 15 s old so batched screen-off fixes aren't dropped.
- #136: clear the Bluetooth-off message when Bluetooth comes back on.
foureight84 and others added 7 commits November 13, 2026 19:55
RC feedback: the Bluetooth-off message only reached the pairing screen, so
every other surface just read Disconnected. BLEState now carries bluetoothOff,
set from the adapter at init (covers a launch with Bluetooth already off), the
ACTION_STATE_CHANGED receiver, and re-synced each watchdog tick. The header pill,
the Settings hero card and the Wearable card use it. Replaces the unused
isBluetoothReady field.
English output is unchanged: values/strings.xml carries the original copy
verbatim, and the existing unit tests pass without modification.

- Composables use stringResource / pluralStringResource. Code without a
  Context goes through util/L10n, which in JVM tests reads the default
  values/strings.xml directly.
- util/LocaleFormats picks date/time patterns from Android's best-pattern
  skeletons, falling back to the original pattern when java.time or
  SimpleDateFormat rejects the platform's one (zh-TW "Bh:mm" on Android
  12/13). Patterns and formatters are cached per (skeleton, locale).
- coach/context/CoachLanguage reads the coach_language resource, so the
  coach replies in the language the UI actually resolved. For English the
  directive is empty and prompts are byte-for-byte unchanged. Coach summary
  signatures carry the language, so a language switch regenerates cards.
- Strings that would otherwise stick after a per-app language switch
  (tool progress labels, threshold units, the sleep no-data card) are
  resolved on read.
- Coach chart colours also match a translation's own metric words.
- values-ru/strings.xml covers every string in values/strings.xml (except
  app_name), with Russian plural forms wherever a count precedes a noun.
- coach_language = "Russian", so the coach replies in Russian when the app
  shows Russian.
- res/xml/locales_config.xml enables the Android 13+ per-app language picker.
- README.ru.md, linked from README.md.
- Onboarding welcome tiles grow to fit a wrapped title instead of clipping
  it at a fixed height; the Russian titles surfaced this.
…lose sync race (#142, #103)

RC feedback on #142: Doze wakeups at :57/:58 were skipped by the 5m + 75s margin before the ring's reading and dropped the whole 2h slot.

- ScheduledSpo2Slots: set CONNECT_AND_SYNC_SECONDS = 30 (105s pre-reading budget in isClear), add 75s isClearToMeasure for the post-sync check, and add nextClear to retry 5 min after the conflicting reading.
- ScheduledSpo2Worker: set isMeasuring = true at doWork() entry before Room reads so a concurrent RingSyncWorker yields GATT in shared Doze windows, re-check isClearToMeasure after startup sync, and schedule via min(nextClear, nextSlot) when skipped for ring proximity.
- ScheduledSpo2SlotsTest: update pre-reading boundary assertions and cover isClearToMeasure, nextClear, midnight rollovers, and grid recovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant