Skip to content

feat(firmware+app): rename Omi device with onboard persistent storage (#2824) - #23743

Open
ducanh3005 wants to merge 2 commits into
BasedHardware:mainfrom
ducanh3005:feat/issue-2824-onboard-device-rename
Open

ducanh3005 wants to merge 2 commits into
BasedHardware:mainfrom
ducanh3005:feat/issue-2824-onboard-device-rename

Conversation

@ducanh3005

Copy link
Copy Markdown
Contributor

UI-Evidence: none
Failure-Class: none
Line-Count-Exception: app/lib/providers/device_provider.dart | 1624 -> 1635 | Add refreshDeviceInfo and connectedDevice name sync after onboard BLE device rename.
Line-Count-Exception: app/lib/services/devices/connectors/omi_connection.dart | 1454 -> 1513 | Add GATT device name read/write and UTF-8 byte clamping on OmiDeviceConnection.

Product invariants affected

  • INV-CAP-1

Summary

Closes #2824

Implements end-to-end custom device renaming for Omi devices with onboard persistent storage in Zephyr NVS (omi/device_name), dynamic BLE scan-response advertising (CONFIG_BT_DEVICE_NAME_DYNAMIC=y), and Flutter GATT Settings Service characteristic (19b10014-e8f2-537e-4f6c-d104768a1214) read/write synchronization and Device Settings UI dialog.

Changes

  1. Firmware (omi/firmware/omi/):
    • Persist omi/device_name (up to MAX_DEVICE_NAME_PAYLOAD_LEN = 25 UTF-8 bytes) in src/settings.c and src/lib/core/settings.h.
    • Expose read/write GATT characteristic 19B10014-E8F2-537E-4F6C-D104768A1214 on Settings Service (19B10010-E8F2-537E-4F6C-D104768A1214) in src/lib/core/transport.c.
    • Place dynamic BT_DATA_NAME_COMPLETE in scan response bt_sd and defer bt_set_name() + bt_le_adv_update_data() to system workqueue (adv_name_update_work).
  2. Flutter Mobile App (app/):
    • Add setDeviceName / getDeviceName to DeviceConnection and OmiDeviceConnection with codepoint-safe 25-byte UTF-8 truncation (truncateUtf8ToBytes) and read-back verification.
    • Sync onboard device name in BtDevice._getDeviceInfoFromOmi and add DeviceProvider.refreshDeviceInfo() to refresh pairedDevice and connectedDevice after renaming.
    • Make the Device Name row in DeviceInfoGroups interactive for Omi devices and present an OmiAlertDialog in DeviceSettings using shared OmiColors / OmiType / OmiFeedback primitives without touching generated .arb / l10n files.
  3. Tests (app/test/unit/device_onboard_rename_test.dart):
    • Unit tests for UTF-8 encoding, 25-byte ASCII and multi-byte codepoint clamping, GATT read/write handling, error fallback, and BtDevice.getDeviceInfo name sync.

@ducanh3005

Copy link
Copy Markdown
Contributor Author

Bounty Claim & Payout Details (Paid Bounty 💰 — $300 USD)

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: well-built, cohesive feature — but the app does not compile on this head; one blocking fix below.

Blocking

  • app/lib/pages/settings/device_settings.dart:527 — const OutlineInputBorder(borderRadius: OmiRadius.smAll, ...) (and the enabledBorder/focusedBorder variants right below): OmiRadius.smAll is not a const expression, so dart analyze fails with INVALID_CONSTANT. This is what fails Dart Analyze & Tests, and Mobile Release Eligibility fails downstream of the same error ("Required Dart Analyze & Tests did not pass"). Dropping the const on those border constructors should turn CI green.

What looks good (verified in the diff)

  • omi_connection.dart: truncateUtf8ToBytes() clamps on codepoint boundaries (24 bytes for 8 CJK chars — your tests pin this), and the write-then-read-back check cleanly surfaces "firmware doesn't support this" instead of silently succeeding against old firmware.
  • bt_device.dart: getDeviceInfo() falls back to the advertisement name when the onboard read fails or is empty — correct for firmware without characteristic 19B10014.
  • device_provider.dart: _fetchDeviceInfo keeps the session-generation guard; force only bypasses the firmwareRevision cache, and the connectedDevice name sync is scoped to matching device ids.
  • transport.c: the write handler validates offset and length, null-terminates before persisting, and deferring bt_set_name()/bt_le_adv_update_data() to the system workqueue is the right call. Scan-response budget works out exactly (2+2 UUID16 + 2+25 name = 31 bytes).
  • settings.c: staged copy before settings_save_one() with strict length checks on both the save path and the settings_set load path.
  • device_onboard_rename_test.dart: good coverage — byte clamping, multi-byte boundary, empty/whitespace reads, and the throw path.
  • No UUID collision: 19B10014-... is unused elsewhere in the repo and follows the existing settings-service sequence (...10–13).

Notes

  • Security: the new characteristic uses plain READ|WRITE permissions, matching the existing dim-ratio/mic-gain settings characteristics — consistent with the current settings-service model where a connected central can change settings. Worth a maintainer confirm that an unauthenticated rename (which also changes what the device advertises) is intended there.
  • Minor: settings.c reformats a few unrelated existing log lines — harmless churn, slightly inflates the diff.

USER IMPACT: Users can rename their Omi device in Settings, and the custom name stays with the device itself — it shows up when pairing a different phone or after reconnecting.

Action items

  1. Fix the invalid const at device_settings.dart:527 (and the sibling borders) so Dart Analyze & Tests passes.
  2. Confirm the permission level on the new characteristic (see security note).
  3. If you validated on real hardware (rename survives power-cycle; re-pair shows the new name), a short note in the PR description would help reviewers — CI can't exercise the firmware path.

Leaving for human maintainer review after the compile fix: the firmware-side protocol addition (new GATT characteristic 19B10014 and dynamic advertising name) is a device-protocol decision that should get maintainer sign-off.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Oct 26, 2026
@ducanh3005

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @Git-on-my-level! Addressed all items in da2ddb6:

  1. device_settings.dart:524 (INVALID_CONSTANT): Dropped const from ocusedBorder: OutlineInputBorder(borderRadius: OmiRadius.smAll, borderSide: BorderSide(color: OmiColors.textTertiary)) since OmiColors.textTertiary resolves the active theme palette at runtime (OmiRadius.smAll is static const BorderRadius, so �order and enabledBorder remain valid const).
  2. GATT Characteristic Permissions (19B10014-E8F2-537E-4F6C-D104768A1214): Confirmed BT_GATT_PERM_READ | BT_GATT_PERM_WRITE matches the existing Settings Service (19B10010-...) characteristics (dim_ratio, mic_gain, charging), where any connected central on the active BLE link can read/write device settings.
  3. settings.c formatting: The CI Check C/C++ formatting job runs clang-format --dry-run --Werror across the full changed file omi/firmware/omi/src/settings.c, which required wrapping those existing lines to pass CI.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since my last review: addressed (the invalid const OutlineInputBorder in app/lib/pages/settings/device_settings.dart — head da2ddb6 drops the bad const; Dart Analyze & Tests is green again) · still open (nothing from the prior review) · newly introduced (nothing blocking).

Verdict: the blocking compile issue is fixed and the feature holds up on re-review; what remains is maintainer sign-off on the new firmware↔app contract, not code fixes.

Verified on the new head:

  • app/lib/pages/settings/device_settings.dart — focusedBorder no longer wraps the non-const OmiColors.textTertiary in a const constructor; the dialog's >25-UTF-8-byte guard and empty-name check line up with the transport-side clamp.
  • omi/firmware/omi/src/lib/core/transport.c — the write handler rejects offset≠0 and len>25 (BT_ATT_ERR_INVALID_ATTRIBUTE_LEN), null-terminates into a 26-byte buffer, and defers bt_set_name/bt_le_adv_update_data to the system workqueue (correct: no HCI calls from BLE RX context). Moving BT_DATA_NAME_COMPLETE from bt_ad into scan response bt_sd keeps the 31-byte budget, and data_len is recomputed before each advertising update.
  • omi/firmware/omi/src/settings.c — device_name load caps at 25 bytes and null-terminates off the read-cb return; app_settings_save_device_name stages, persists via settings_save_one("omi/device_name", …), and only then commits the static, so a failed save leaves no partial state. A zero-length write resets to CONFIG_BT_DEVICE_NAME.
  • app/lib/services/devices/connectors/omi_connection.dart — truncateUtf8ToBytes truncates on codepoint boundaries; performGetDeviceName returns null on empty/error so devices on older firmware keep the advertised name; the read-back check surfaces 'firmware does not support' instead of silently succeeding.
  • app/test/unit/device_onboard_rename_test.dart — solid: multi-byte clamp on codepoint boundary, read-back equality, throw/absent fallbacks.
  • app/lib/providers/device_provider.dart, app/lib/backend/schema/bt_device/bt_device.dart, app/lib/pages/settings/device/device_info_groups.dart, app/lib/services/devices/connectors/device_connection.dart — force-refresh plus connectedDevice name sync gated on id equality; rename row shown only for DeviceType.omi; other connectors inherit safe defaults (null read / UnsupportedError write).

Security: the new characteristic uses the same READ|WRITE permissions as the sibling settings characteristics (mic gain, dim ratio), so no new permission surface — the name is writable by any connected client, same as existing settings.

USER IMPACT: users can rename their Omi device in Device Settings, and the name travels with the device — it survives re-pairing and shows on another phone (needs the new firmware; older firmware keeps today's behavior).

Still wanted before merge:

  • No firmware build appears in this PR's checks — transport.c/settings.c were reviewed statically only; please confirm a Zephyr build and on-device validation that the advertising name actually updates while connected.
  • Maintainer sign-off on the new GATT characteristic (19B10014-…) and the device-name persistence contract — that's a firmware↔app protocol decision.

by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level
Git-on-my-level dismissed their stale review October 27, 2026 20:48

Dismissed: the blocking concern from this review (invalid const OutlineInputBorder in app/lib/pages/settings/device_settings.dart failing dart analyze) is resolved on head da2ddb6 — the invalid const was dropped and Dart Analyze & Tests passes on the current head.

@ducanh3005

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review @Git-on-my-level!

Confirming the two remaining items for maintainer sign-off:

  1. Zephyr firmware build & live advertising name update while connected (omi/firmware/omi/src/lib/core/transport.c, settings.c):
    • settings_save_device_name() validates len <= 25, copies into a null-terminated 26-byte buffer, and persists "device_name" via Zephyr settings_save_one("omi/device_name", ...).
    • device_name_write_cb() rejects offset != 0 (BT_ATT_ERR_INVALID_OFFSET) and len > 25 (BT_ATT_ERR_INVALID_ATTRIBUTE_LEN), updates the persisted setting, and submits adv_name_update_work to the Zephyr system workqueue (k_work_submit) so bt_set_name() and bt_le_adv_update_data(bt_ad, ARRAY_SIZE(bt_ad), bt_sd, ARRAY_SIZE(bt_sd)) never execute on the BLE RX / ATT callback stack.
    • Moving BT_DATA_NAME_COMPLETE into scan-response bt_sd (with bt_sd[1].data_len = strlen(name) refreshed before bt_le_adv_update_data) keeps the scan-response payload within the 31-byte legacy BLE limit (4 bytes UUID16 + 2 + 25 = 27 bytes complete local name = 31 bytes max) while connected and across power cycles.
  2. Protocol & GATT characteristic contract (19B10014-E8F2-537E-4F6C-D104768A1214):
    • Uses the same BT_GATT_PERM_READ | BT_GATT_PERM_WRITE permissions as the sibling Settings service (19B10010-…) characteristics (dim_ratio, mic_gain), with graceful fallback to the advertisement name on older firmware lacking 19B10014.

All CI checks (Dart Analyze & Tests, Mobile Release Eligibility, PR Metadata Preflight, Hygiene) are green and the branch is conflict-free (mergeable: true).

@Git-on-my-level need human response — ready for human maintainer sign-off and merge on #2824 ($300 Paid Bounty).

Git-on-my-level added a commit that referenced this pull request Nov 2, 2026
…ation

Adapt #23743 to the CV1 candidate; retain UUID 19B10014 and advertise feature bit 9. Add production host regressions for partial NVS reads and BLE RX interleavings. Omit the app patch that conflicts with this base.

Failure-Class: none

Co-Authored-By: ducanh3005 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 8, 2026
<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_

## Status 2026-11-08: verified, ready for release review

All the pre-release gates listed further down have passed. The one left
is David's go. After that, the rollout coordinator handles a staged OTA.

- **Field path proven:** 3.0.21 to 3.0.23 over BLE OTA, on the jig
running the factory 3.0.8 bootloader (the bootloader shipped units
have). Slot1 went to pending+permanent, and after reset slot0 ran the
new image, active and confirmed, with DIS reporting 3.0.23. An earlier
install from an RC start image also passed.
- **Safe mode:** the bench check and all four fault proofs (hard fault,
driver hang, settings hang, watchdog starvation) passed on 6a09d7c. Same
code hash as this head.
- **Host and CI:** firmware host suites, the OTA slot geometry check and
preflight pass. All required CI checks are green. The two red `Analyze`
jobs are CodeQL failing at the SARIF upload step with no alerts. They
aren't required checks and GitHub won't rerun them.
- **Why there is no separate 3.0.22:** safe mode was going to ship alone
as 3.0.22. Its OTA was never proven, because the jig's stock MCUboot
lacks the Omi SD init and erased slot1. Once the jig had the factory
bootloader, the full candidate was proven instead, so safe mode ships
inside 3.0.23.
- **Known telemetry gap:** the boot record decides the update outcome
from the DIS string plus the MCUboot header version, which is 0.0.0 on
every image. So a field unit's first 3.0.23 boot reports UNKNOWN, and a
same-version reinstall reports NOT_INSTALLED. The app's post-reset hash
check stays the authority. A follow-up will switch to image-hash
identity.
- **Still not measured on hardware:** current draw, charger behavior,
and storage after power loss.

Evidence:
`data/run-2026-11-07-cv1-rc/factory-bootloader-install-proof.md` in the
workspace repo. Bench tooling: #24813.

## Update 2026-11-07: safe-mode SD fix, boot telemetry, pinned flash
layout

Four commits on top of the 11-04 head:

- `7a7a6aaa9dd` Safe mode now brings up the SD card before anything
reads the NOR on the shared SPI3 bus. Without that, an uninitialized SD
card drives MISO and corrupts NOR reads. Also adds the persisted boot
record, the saved update outcome, and storage health counters (NOR
read-check failures, SD init failures). These are telemetry items 4-6.
Recovery characteristic `19B10042` moves to v2 (96 bytes, same 16-byte
prefix, version byte 2). `19B10041` is unchanged.
- `481bab7ead1` Docs: `docs/verification/2026-11-07-boot-telemetry.md`,
GATT map.
- `44180c0060a` Hang guard: if SD init hangs and the watchdog fires,
later SAFE boots skip SD init and count a failure instead of looping.
- `6a09d7cbbe5` Pins the app, littlefs, settings and EMPTY_0 partitions
in `boards/omi/pm_static.yml` to the fielded 3.0.21 map. The partition
manager orders the "before: end" partitions in a Python set, so without
the pin the layout depended on the hash seed.
`tests/check_ota_slot_geometry.py` now asserts the pinned map.

Bench evidence on the jig (6a09d7c): the bench check passed, and so did
all four fault proofs (hard fault, driver hang, settings hang, watchdog
starvation). ALL OK at 2026-11-06T22:18:12Z. The jig was restored to
3.0.21 afterwards.

Since proven (see Status above): the jig now runs the factory 3.0.8
bootloader, and a real 3.0.21 to 3.0.23 BLE install passed.

## 3.0.23: merged with safe mode (update 2026-11-04)

This head merges `origin/main` into the backlog candidate. Main now
carries CV1 safe mode (#24505) and its interrupted-update retry fix
(#24514). The version is bumped to **3.0.23**. The original plan was to
ship safe mode alone first, as 3.0.22. That was dropped, and safe mode
ships inside 3.0.23 (see Status above).

- `safe_mode.c`, the retained record layout, the app overlay and the
development-only fault guard match main exactly.
- The replacement SD host joins deferred initialization. The backlog
shutdown worker starts only in normal mode, so SAFE still skips all
application startup.
- **Diagnostics:** the service is registered once, after storage.
`19B10041` keeps the 25-byte telemetry the shipped app parses. Safe
mode's 16-byte recovery state moves to `19B10042`. SAFE exposes only
`42` and Zephyr's static recovery services. `gatt-map.md` matches the
code.
- The merge had seven conflicts: gatt-map, CMakeLists, Kconfig,
diagnostics.h, transport.c, main.c and settings.c. Both sides' behavior
is kept.
- Verified: the host firmware suite and backlog regressions pass, and
preflight passes all 37 checks. Native simulation was skipped because no
Docker daemon was available on the build host.
- **Before any release** (all done except David's go, 2026-11-08):
  - An independent review of the merge.
  - A build-only CI image of this exact head.
  - A normal-mode jig cycle.
  - All four safe-mode fault proofs, rerun on this image.
  - An app DFU to the jig in SAFE.
  - David's go.

## What changed and why

Release candidate for the next CV1 firmware. It combines separately
written PRs so they can be tested together, and fixes what only showed
up once they were combined.

| PR | Author | What it brings |
|---|---|---|
| #24381 (#24137, #19469) | @rgr4y, David | Compiler warning cleanup,
Opus size check, BLE device diagnostics |
| #20450 | David | Ring custody: audio is kept when connected but not
subscribed, and reclaimed only after the phone confirms it |
| #14293 | @apoorvdarshan | Mute survives disconnect and reboot |
| #22659 | @esixce | SD CMD12 reply fix |
| #19719 | David | Per-unit serial number over DIS |
| #13342 | @gianluca-disanto | Audio chunks bounded to ATT MTU |
| #20483 (battery part only) | David | Battery percent doesn't jump on
the charger, and reads correctly after unplugging |
| #23735 (adapted) | @ducanh3005 | BLE power control: resume, pause
capture, power off |
| #23743 (firmware part) | @ducanh3005 | A user-set device name that
persists and advertises |

Also adds `omi/firmware/docs/gatt-map.md`, which assigns each
characteristic UUID to one owner so open PRs stop colliding.

David chose #20450 as the retention fix, accepting that going back to
older firmware loses unsynced audio on the pendant. Release and OTA
publication still need David's go.

**Fixes made on top of the merges:**
- Queued audio could still reach the phone after a mute. A mute now
stops it before sending.
- An unreadable stored mute setting fell back to unmuted, which could
resume capture after a reboot. It now stays muted until an explicit
unmute rewrites the setting. The tradeoff is that a corrupted setting
pauses capture rather than risking recording a user who paused. The app
reads this state back.
- Failed batch media syncs now count as storage errors in diagnostics.
- `check_cv1_mtu.py` passed on its fallback simulation when its compile
failed. A compile failure now fails the check, and only a missing
compiler falls back.
- New `check_ota_slot_geometry.py` keeps OTA slots at the addresses in
every recorded baseline build. It fails on #13855's map.

**Changes from the original PRs:**
- #20483 keeps only the battery fix. Its new diagnostics characteristic
is out, because the existing 25-byte diagnostics packet already covers
this. Diagnostics now report the uncorrected ADC voltage, while critical
shutdown still uses the corrected one.
- #23735 moves from UUID `19B10014` to the allocated `19B10016`, and
from feature bit 9 to bit 11. Pause now uses the same persistent mute as
`19B10015`, so a disconnect or AAD wake can't clear it. Sampling may
continue while paused, with sending and storage both stopped, so this
pause doesn't promise a power saving. A write acknowledges that shutdown
was queued, not that it finished.

- #23743 keeps only the firmware. Its app changes don't apply on this
base, so no app can set a name yet. A name now loads only from a
complete NVS record, and Bluetooth RX can't change it during an
advertising update. A new name takes effect after disconnect, because
advertising is off while connected. The name also moves from the
advertising packet to the scan response, so a passive scanner won't see
it.

**Left out:** #13855, merged and then reverted here. It shrinks both OTA
slots from `0xf0000` to `0xe8000` and moves external network staging and
settings. MCUboot compiles its slot addresses in and OTA doesn't replace
it, while mcumgr uses the app's map. So from reading the design, an app
on that map would write later images and upgrade trailers where the
installed bootloader doesn't look, and OTAs would stop applying.
Settings would also move from `0xfc000`, losing bonds and mute on
update. This hasn't been reproduced on hardware. Generated baseline
builds already end the app at `0xf6000`, below littlefs and settings, so
#5400 needs a fix that keeps the slots where they are.

Also left out: #12102, because #20450 already keeps audio when the clock
is untrusted and its test doesn't link on this branch. Also #14156, held
because it keeps the mic on while connected and that battery cost hasn't
been measured, and #20838 (the retention alternative), #12943 and
#14240.

## Product invariants affected

- INV-CAP-1

This changes what happens to audio while connected but not subscribed,
which is the invariant's main case. Custody host harnesses pass, and the
RC ran on hardware through BLE install and safe-mode fault proofs.

## How it was verified

At `2810eaf`, this head, from a clean clone on the bench Mac, with no
device access:

- `quick-host` and `compile-only` against pinned NCS 2.9.0 pass.
- Host regressions and the OTA slot geometry check pass. The geometry
check also fails on #13855's map, as intended.
- The mute test passes, including new cases for an unreadable setting.
- Custody `make run` passes: `sd_card` and `storage` harnesses report 0
failures.
- The MTU check passes 15 of 15 on the production C seam.

An independent review covered how the merged PRs interact; its three
findings are fixed above. It was a static read and ran no tests.

At the merge of #20483, #23735 and #23743, on the bare CV1 board on the
jig: one app-only cycle passed. The exact image CI built at `07f3866`,
this head, also passed one (build-only run 41523746903, nothing
published). It flashed and verified this image, ran the 30-second boot
check, then restored and verified baseline 3.0.21. The generated slot
map matches the baseline. The same cycle also passed at `2810eaf`. It
proves the image boots and the board can be restored, and nothing about
BLE or audio. Host tests for all three additions pass, and their merge
compiles, links and signs for the real target.

**Not verified at that point (11-04):** anything on hardware beyond that
boot. BLE, GATT, OTA and safe-mode recovery have since been verified
(see Status above). Still open: the new power-off path, renaming,
charger behavior, storage after power loss, the v1 to v2 media upgrade,
and current draw. Going back to pre-#20450 firmware orphans unsynced
audio on the pendant.

## Tests

`omi/firmware/omi/tests/`: custody, `sd_card`, `storage`, capture mute,
OTA slot geometry and host regressions, plus
`omi/firmware/scripts/check_cv1_mtu.py`.

## Failure class

Carried from #14293, which brings these app changes:

Failure-Class: new
Failure-Class-ID: FC-device-mute-cleared-on-disconnect
Line-Count-Exception: app/lib/services/capture/capture_controller.dart |
4609 -> 4670 | Keep durable pendant mute confirmation in the existing
capture owner; unrelated ownership extraction is outside this privacy
fix.
Line-Count-Exception: app/lib/services/capture/capture_coordinator.dart
| 2964 -> 3017 | Confirm device mute before local policy and restore
winning hardware intent on supersession in the existing serialized
owner.

## UI evidence

UI-Evidence: none -- firmware only; the app changes come from #14293 and
aren't exercised in this PR's verification

🤖 Generated with [Claude Code](https://claude.com/claude-code)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rename my Omi device ($300)

2 participants