Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
511efbf
helio strap: adapter, typed-key pairing, sync, forget
abdulsaheel Nov 22, 2026
e0ff5a7
sparse wearables: strain and readiness off minute hr, device rmssd as…
abdulsaheel Nov 22, 2026
e6cc59f
devices: helio entry and sync arm in the right place
abdulsaheel Nov 22, 2026
5dcfed8
helio strap: ask plist entry, registry-listing tests know it
abdulsaheel Nov 22, 2026
1b3467a
helio strap: secure-storage owners and reset-steps host on the guard …
abdulsaheel Nov 22, 2026
9d59a2f
a wearable alone is a source: onboarding, cadence checks, home sync
abdulsaheel Nov 22, 2026
d359230
sessions and steps off the active wearable
abdulsaheel Nov 22, 2026
0c4d8e9
recovery-ready push settles on the active wearable's edge too
abdulsaheel Nov 22, 2026
fd87f97
test: piggyback helper is public now
abdulsaheel Nov 22, 2026
600d5cf
test: wearable steps are served now, not device-only
abdulsaheel Nov 22, 2026
1d7120c
settings: band-only rows only with a band
abdulsaheel Nov 23, 2026
0a971c2
absence note: a stamped device with no calibration isn't 'unstamped'
abdulsaheel Nov 23, 2026
c5e6932
copy: wear/sync your device, not the band
abdulsaheel Nov 23, 2026
7daf675
readiness breakdown: a device-hrv night gets its hrv row
abdulsaheel Nov 23, 2026
7570750
test: the alarm guide runs with a band paired
abdulsaheel Nov 23, 2026
24a86db
test: every minute-hr wearable family gets the sparse tier
abdulsaheel Nov 23, 2026
f39bc7b
helio strap: fetch from a local midnight, use only whole nights
abdulsaheel Nov 23, 2026
922990e
ios picker: helio strap under the huami company id, each id declared …
abdulsaheel Nov 23, 2026
fa4ef7e
ln_rmssd_dev only where it applies
abdulsaheel Nov 23, 2026
6312197
workout setup: a paired band still says 'no band connected'
abdulsaheel Nov 23, 2026
23bcd18
repin protocol to the huami2021 transport (d74cbc8)
abdulsaheel Nov 23, 2026
5a530fb
ln_rmssd_dev: null-aware map entry
abdulsaheel Nov 23, 2026
1e9d3d4
test: the first derive pass also re-scores the day owed a quiet level
abdulsaheel Nov 23, 2026
26b2afa
whoop freeze goldens: restamp algo_version 127 -> 131, nothing else
abdulsaheel Nov 23, 2026
1be5657
l10n: device step label, key-only field text, fr wording, skin-temp m…
abdulsaheel Nov 23, 2026
ff105f8
session zones: cadence from every sample, not the worn ones
abdulsaheel Nov 23, 2026
5211374
steps name the wearable when its count wins; device hrv in the rescan…
abdulsaheel Nov 23, 2026
63d46a7
recovery-ready push: settle on the night's own device edge
abdulsaheel Nov 23, 2026
686acba
day signature: the wearable's own step count
abdulsaheel Nov 23, 2026
d4cb7ee
helio strap: key-only pairing everywhere, reset and forget guards
abdulsaheel Nov 23, 2026
1cc9696
sleep tab: redraw the alarm row when a band is paired or forgotten
abdulsaheel Nov 23, 2026
978de98
repin protocol to f2398ab (#86 head)
abdulsaheel Nov 23, 2026
9d811fa
l10n: steps method names the wearable; vitals tab names in skin-temp …
abdulsaheel Nov 23, 2026
fa2a4c7
session zones: each sample weighted by its own source's cadence
abdulsaheel Nov 23, 2026
c1e0750
device hrv row cleared when a re-derive drops it; day export carries …
abdulsaheel Nov 23, 2026
6418d1a
helio strap: delete-everything drops its key; nearby pairing reports …
abdulsaheel Nov 23, 2026
3133732
workouts: each source at its own cadence in detail, list and peak; da…
abdulsaheel Nov 23, 2026
0ab1a4f
reset clears the wearable source flag; counter spans only when the ba…
abdulsaheel Nov 23, 2026
d672beb
workouts: completeness, trace replacement and mean in seconds covered
abdulsaheel Nov 24, 2026
692b4a3
workouts: sparse hr priced over its span; read guards and means in cl…
abdulsaheel Nov 24, 2026
f469dc9
helio pairing: reset rules in one persist step, counter read before t…
abdulsaheel Nov 24, 2026
571b1d3
day signature: input revisions catch in-place rewrites
abdulsaheel Nov 24, 2026
1047470
sparse workout strain: carry seconds across samples, not a rounded mi…
abdulsaheel Nov 24, 2026
44cad9e
helio pairing: refuse during an active reset; say what an undo left b…
abdulsaheel Nov 24, 2026
2c98fde
sparse minutes: each minute is the mean hr of the seconds it holds
abdulsaheel Nov 24, 2026
9563024
repin protocol to e4ccba2: an activity round that doesn't add up deco…
abdulsaheel Nov 24, 2026
e92876b
hrv chart with no band: say it needs beats, not more nights
abdulsaheel Nov 24, 2026
ef44fd6
helio strap: fetch and handshake hardening
abdulsaheel Nov 24, 2026
014649d
pairing: helio name wins on fee1, ios picker scoped by name, key befo…
abdulsaheel Nov 24, 2026
eada7e0
sessions read the active wearable's device, not its adapter family; s…
abdulsaheel Nov 24, 2026
a070e4e
derive: refused device hrv is never carried back; helio temperature j…
abdulsaheel Nov 24, 2026
e31a4f4
wearable source flag: only the newest read writes it
abdulsaheel Nov 24, 2026
68ed4b8
hrv empty state: a chest strap doesn't record overnight
abdulsaheel Nov 24, 2026
352c75a
helio pairing: one at a time
abdulsaheel Nov 24, 2026
c2f9d56
helio pairing: a forget during the handshake stays in effect
abdulsaheel Nov 24, 2026
e5f6d4f
hrv empty state: a ring that records beats fills it too
abdulsaheel Nov 24, 2026
adb7a1e
helio pairing: forget counter read before the queue; re-check after r…
abdulsaheel Nov 24, 2026
df1313f
hrv empty state: no device class implied to supply beats
abdulsaheel Nov 24, 2026
1cac856
one lock for helio pair, forget and reset
abdulsaheel Nov 24, 2026
c2d7040
helio pair: read reset gen and forget count before waiting on the lock
abdulsaheel Nov 24, 2026
304d306
protocol: repin to main at the #86 merge
abdulsaheel Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ a hotspot.
permanent data loss or an infinite re-flood. Never ACK a partial chunk.
2. **`decoded_onehz` stays INSERT-OR-REPLACE on its key `(device_id, ts_ms)`.**
Newest wins: with INSERT-OR-IGNORE a stale or failed decode would
permanently shadow a fresh re-offload of the same second. A write that
permanently shadow a fresh re-offload of the same second. The neutral
path (`_queueNeutralOneHz`) is newest-wins PER FIELD (INSERT OR IGNORE +
UPDATE COALESCE): a `NeutralSample` carries only what it measured, and a
whole-row REPLACE let a same-second temperature sample null the HR. A write that
replaces a second must replace that `(device_id, ts_ms)`'s `decoded_rr`
beats in the same batch, never another device's (`_queueRrBeats` via
`_queueDecodedOneHz`, and `_queueNeutralOneHz`). Known gap: the restore
Expand Down
29 changes: 23 additions & 6 deletions ios/Runner/AccessorySetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ enum AccessorySetup {
// or no argument is the band picker, byte-identical to before.
if let args = call.arguments as? [String: Any],
let services = args["services"] as? [String] {
Impl.shared.showSensorPicker(services: services, reply)
// `name`/`label`: a sensor that SHARES its service with another
// (FEE1: the Mi Bands and the Helio Strap) is told apart by the
// name it advertises and the label its approval was made under.
Impl.shared.showSensorPicker(services: services,
name: args["name"] as? String,
label: args["label"] as? String, reply)
return
}
let addAnother = (call.arguments as? Bool) ?? false
Expand Down Expand Up @@ -424,26 +429,34 @@ private final class Impl {
/// return. Every service must be declared under `OSAskSensorServices`; anything else
/// is refused here rather than handed to ASK, whose descriptor validation traps.
func showSensorPicker(services: [String],
name: String? = nil,
label: String? = nil,
_ completion: @escaping (Result<String, PickerError>) -> Void) {
// Same as showPicker: the already-approved check needs the activated accessory list.
whenActivated({ [weak self] in
self?.showSensorPickerActivated(services: services, completion)
self?.showSensorPickerActivated(services: services, name: name, label: label,
completion)
}, timedOut: {
completion(.failure(PickerError(message: "Accessory setup is not ready yet. Try again.")))
})
}

private func showSensorPickerActivated(services: [String],
name: String?,
label: String?,
_ completion: @escaping (Result<String, PickerError>) -> Void) {
let wanted = Set(services.map { $0.uppercased() })
guard !wanted.isEmpty, wanted.isSubset(of: sensorServices) else {
completion(.failure(PickerError(
message: "That sensor is not declared for the iOS pairing sheet.")))
return
}
// A shared service is reused only when the approval is THIS device's (its
// label); another sensor's approval on the same service would hand back
// that sensor's id on every attempt.
if let existing = session.accessories.first(where: { a in
guard let svc = service(of: a) else { return false }
return wanted.contains(svc)
guard let svc = service(of: a), wanted.contains(svc) else { return false }
return label == nil || a.displayName == label
}), let id = existing.bluetoothIdentifier?.uuidString.uppercased() {
completion(.success(id))
return
Expand All @@ -459,8 +472,12 @@ private final class Impl {
let sensorItems = wanted.sorted().map { svc -> ASPickerDisplayItem in
let descriptor = ASDiscoveryDescriptor()
descriptor.bluetoothServiceUUID = CBUUID(string: svc)
return ASPickerDisplayItem(name: labels[svc] ?? "Sensor", productImage: image,
descriptor: descriptor)
// Always WITH the service UUID (a name-only descriptor traps; see the
// note on whoopMemberUUID16), and the name must be declared under
// NSAccessorySetupBluetoothNames or iOS ignores it.
if let name = name { descriptor.bluetoothNameSubstring = name }
return ASPickerDisplayItem(name: label ?? labels[svc] ?? "Sensor",
productImage: image, descriptor: descriptor)
}
pickerResult = completion
present(sensorItems, known: allIdList, fallback: { nil }, allowGen4Retry: false)
Expand Down
5 changes: 5 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<string>6E40FFF0-B5A3-F393-E0A9-E50E24DCCA9E</string>
<string>86F65000-F706-58A0-95B2-1FB9261E4DC7</string>
<string>FEE1</string>
<string>FEE1</string>
<string>FED9</string>
<string>6A4E2800-667B-11E3-949A-0800200C9A66</string>
<string>1809</string>
Expand All @@ -82,6 +83,7 @@
<key>NSAccessorySetupBluetoothNames</key>
<array>
<string>WHOOP</string>
<string>Helio Strap</string>
</array>
<key>NSAccessorySetupKitSupports</key>
<array>
Expand All @@ -107,6 +109,8 @@
<string>Ultrahuman Ring Air</string>
<key>FEE1</key>
<string>Mi Band 2/3</string>
<key>FEE1</key>
<string>Amazfit Helio Strap</string>
<key>FED9</key>
<string>Pebble</string>
<key>6A4E2800-667B-11E3-949A-0800200C9A66</key>
Expand Down Expand Up @@ -137,6 +141,7 @@
<string>6E40FFF0-B5A3-F393-E0A9-E50E24DCCA9E</string>
<string>86F65000-F706-58A0-95B2-1FB9261E4DC7</string>
<string>FEE1</string>
<string>FEE1</string>
<string>FED9</string>
<string>6A4E2800-667B-11E3-949A-0800200C9A66</string>
<string>1809</string>
Expand Down
11 changes: 10 additions & 1 deletion lib/ble/accessory_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,18 @@ class AccessorySetup {
/// service must be declared under `OSAskSensorServices`; the native side
/// refuses anything else. Sent in [plistUuid] form (`180D`, not the 128-bit
/// expansion), the form the plist declares. An already-approved sensor comes back with no sheet.
static Future<String> showSensorPicker(List<String> services) async {
///
/// [name] (an advertised-name substring, declared under
/// `NSAccessorySetupBluetoothNames`) and [label] tell apart a sensor that
/// shares its service with another: the sheet lists only devices with that
/// name, and an earlier approval is reused only if it was made under
/// [label].
static Future<String> showSensorPicker(List<String> services,
{String? name, String? label}) async {
final id = await _ch.invokeMethod<String>('showPicker', <String, Object>{
'services': [for (final s in services) plistUuid(s)],
'name': ?name,
'label': ?label,
});
if (id == null || id.isEmpty) {
throw Exception('Pairing cancelled.');
Expand Down
99 changes: 99 additions & 0 deletions lib/ble/adapters/_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,57 @@ bool _looksLikeMiBand23(String lowercaseName) => const {
'xiaomi band 3',
}.contains(lowercaseName);

/// Chunked transport write/notify (auth + small commands) and the plaintext
/// activity-fetch control/data pair (bulk history) — see
/// `huami2021_chunks.dart` and `huami2021_fetch.dart` in protocol. All four
/// are required: without the chunk pair there is no handshake, without the
/// fetch pair there is nothing to decode.
const String kHuami2021FetchControlChar = kHuamiActivityControlChar;
const String kHuami2021FetchDataChar = kHuamiActivityDataChar;

/// Amazfit Helio Strap (Huami2021/ZeppOS protocol family). The auth key is a
/// precondition this adapter assumes already exists in secure storage — see
/// `helio_strap.dart`'s header; acquiring one is a separate, unbuilt flow.
///
/// EXPERIMENTAL, and it stays that way: nobody on this project owns one, so
/// not a byte of this path has met hardware (ASSUMPTIONS R6). The service
/// UUID is the same `0000fee1-…` the whole Huami/Zepp family shares
/// (confirmed for Mi Band 2/3 above; assumed, not separately confirmed, for
/// this specific device) — a wrong guess here only means the scan filter
/// never matches, not a silent wrong decode.
const BandEntry kHelioStrap = BandEntry.notify(
id: 'helio_strap',
role: DeviceRole.band,
kind: DeviceKind.strap,
resetSteps: ResetSteps.unverified(
officialUrl: 'https://support.amazfit.com/en/amazfit_helio_strap/',
),
category: DeviceCategory.wearable,
label: 'Amazfit Helio Strap',
service: kHuami234Service,
characteristics: <String>[
kHuami2021ChunkWriteChar,
kHuami2021ChunkNotifyChar,
kHuami2021FetchControlChar,
kHuami2021FetchDataChar,
],
// The strap stamps its own records (session/round/absolute `sec` fields);
// none of this protocol's timestamps are arrival-anchored.
timeAnchor: TimeAnchor.measured,
nameMatcher: _looksLikeHelioStrap,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// Its own service as a HINT too: FEE1 is shared with the Mi Bands, so an
// advertisement named "Amazfit Helio Strap" carrying FEE1 must match this
// entry by name before the first FEE1 entry claims it by service. A
// nameless FEE1 advertisement still falls back to the service match.
scanHints: <String>[kHuami234Service],
scanByName: true,
);

/// The name the strap advertises, confirmed from the real Zepp app's own
/// BLE advertised-name match table.
bool _looksLikeHelioStrap(String lowercaseName) =>
lowercaseName.contains('helio strap');

/// Pebble 2 / Pebble 2 SE. Pure client, no envelope, no command channel —
/// PPoGATT carries the inner protocol, whose health data logging the adapter
/// decodes (HR, steps, the watch's sleep periods). `pebble_link.dart`'s
Expand Down Expand Up @@ -1238,6 +1289,7 @@ const List<BandEntry> kBandRegistry = <BandEntry>[
kCoros,
kUltrahuman,
kMiBand234,
kHelioStrap,
kPebble,
kColmi,
kGarmin,
Expand Down Expand Up @@ -1281,6 +1333,19 @@ final List<BandEntry> kFramedBands =
/// a picker filtered on them would hand back another sensor's approval. On
/// iOS 18+ they cannot be paired yet; `PairSensorScreen` says so.
///
/// [kHelioStrap] IS listed, with a known, owner-accepted risk: it shares
/// [kMiBand234]'s FEE1 service, and nothing here tells the two apart —
/// no company identifier, no manufacturer-data blob, because nobody has a
/// real strap to read one off. A developer forum report describes exactly
/// this shape (several products sharing one service UUID, no company
/// identifier set) as "random which device is found"; Apple's own WWDC24
/// session says the picker shows the device's OWN advertised name as well
/// as ours, so a user may well see and tap the right one, but which
/// physical device the approval actually resolves to is unconfirmed when
/// more than one FEE1 device is nearby. Fix it properly once a real strap's
/// advertisement can be read for a `bluetoothCompanyIdentifier` or
/// manufacturer-data blob that differs from Mi Band's.
///
/// [kMiBand234], [kColmi], [kUltrahuman], [kMiScaleComposition] and
/// [kMiScale2] are listed although they break the rule above: the band is
/// not known to advertise FEE1, the Colmi ring is not known to advertise its
Expand All @@ -1298,6 +1363,7 @@ const List<BandEntry> kAskPickerSensors = <BandEntry>[
kColmi,
kUltrahuman,
kMiBand234,
kHelioStrap,
Comment thread
abdulsaheel marked this conversation as resolved.
Resolved
kPebble,
kGarmin,
kThermometer,
Expand Down Expand Up @@ -1339,6 +1405,17 @@ const Map<String, int> kAskSensorCompanyIds = <String, int>{
// Unverified on a band (R6): declared because a Mi Band 2/3 advertisement
// is expected to carry this manufacturer data, the Oura case above.
'miband234': 0x0157, // Anhui Huami Information Technology
// The same company (Zepp Health, formerly Huami) makes every Amazfit
// device, so the same id; already declared above, listed so the plist
// test keeps it declared for this entry too. Unverified on a strap (R6).
'helio_strap': 0x0157,
};

/// iOS picker names for sensors whose service another sensor shares (FEE1):
/// the advertised-name substring the sheet filters on. Each must also be
/// declared under `NSAccessorySetupBluetoothNames` in Info.plist.
const Map<String, String> kAskSharedServiceNames = <String, String>{
'helio_strap': 'Helio Strap',
};

/// The entry speaking [wire]. Used by the engine's test seam, which is handed
Expand Down Expand Up @@ -1430,6 +1507,19 @@ const Map<String, Map<InputSignal, Duration>> kAdapterSignals =
InputSignal.deviceSpo2: Duration(days: 1),
InputSignal.deviceStress: Duration(days: 1),
},
// Mirrors `kHelioStrapSignals` in `helio_strap.dart` exactly — keep the
// two in sync by hand, same as every other entry here.
'helio_strap': {
InputSignal.hrSparse: Duration(minutes: 1),
InputSignal.steps: Duration(minutes: 1),
InputSignal.skinTempC: Duration(minutes: 1),
InputSignal.deviceStress: Duration(minutes: 1),
InputSignal.deviceHrv: Duration(minutes: 2),
InputSignal.deviceResp: Duration(minutes: 30),
InputSignal.deviceSpo2: Duration(minutes: 5),
InputSignal.deviceStages: Duration.zero,
InputSignal.vendorScalars: Duration.zero,
},
'thermometer': <InputSignal, Duration>{},
'miscale_bc': <InputSignal, Duration>{},
'miscale2': <InputSignal, Duration>{},
Expand All @@ -1444,6 +1534,15 @@ const Map<String, Map<InputSignal, Duration>> kAdapterSignals =
},
};

/// POLICY EXCEPTION PE-1 (docs/internal/sparse_device_analytics_architecture.md
/// §1, owner decision 2026-11-22): the families whose OWN RMSSD readings
/// (`decoded_onehz.dev_rmssd_ms`, raw timestamped samples in ms) our readiness
/// may take as its HRV input, on a night no strap's beats gave our own.
/// Raw samples only: a device's stress score, readiness, PAI, ODI or any
/// aggregate it made stays in `observation`, display-only, forever. A family
/// not listed here contributes nothing even with samples on disk.
const Set<String> kDeviceRmssdFamilies = {'helio_strap'};

/// [adapterId]'s [DeviceCategory], or null for an id this build has no
/// entry for.
DeviceCategory? categoryOf(String? adapterId) {
Expand Down
13 changes: 13 additions & 0 deletions lib/ble/adapters/adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ class NeutralSample {
/// metric is claimed on its behalf.
final double? skinTempC;

/// The device's OWN RMSSD reading for this second, in ms, or null; and its
/// own breathing-rate reading, breaths/min. Raw single-quantity samples in
/// a physical unit, never a composite and never an aggregate the device
/// made (its night mean is an observation). They land in
/// `decoded_onehz.dev_rmssd_ms` / `dev_resp_brpm`, and the ONLY reader is
/// `compute/inputs/device_night_samples.dart`, for a family listed in
/// `kAdmittedDeviceSamples` (policy exception PE-1,
/// docs/internal/sparse_device_analytics_architecture.md §1).
final double? deviceRmssdMs;
final double? deviceRespBrpm;

/// Anything the band emitted that we do not have a column for, under the
/// band's OWN name for it (owner rulings R1-R3: capture everything, decide
/// what to do with it later). Never an input to a derivation, never in a
Expand All @@ -181,6 +192,8 @@ class NeutralSample {
this.hr,
this.rrMs = const <int>[],
this.skinTempC,
this.deviceRmssdMs,
this.deviceRespBrpm,
this.vendor = const <String, Object?>{},
this.beatTsMs,
this.gapMs = 0,
Expand Down
Loading
Loading