Skip to content

feat: onboard BLE device rename with Zephyr NVS persistence & settings UI (#2824) - #23938

Open
malek-bounties wants to merge 4 commits into
BasedHardware:mainfrom
malek-bounties:feat/2824-onboard-device-rename
Open

malek-bounties wants to merge 4 commits into
BasedHardware:mainfrom
malek-bounties:feat/2824-onboard-device-rename

Conversation

@malek-bounties

@malek-bounties malek-bounties commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #2824

Summary

Lets users rename their Omi from Device Settings → Device Name. The name is stored on the device (Zephyr settings/NVS), re-advertised over BLE, and read by any phone that connects, with a phone-local alias as a fallback for older firmware.

How it works (matches the diff)

Firmware (omi/firmware/omi/)

  • omi.conf: CONFIG_BT_DEVICE_NAME_DYNAMIC=y.
  • settings.h / settings.c: MAX_DEVICE_NAME_PAYLOAD_LEN = 25 bytes, app_settings_save_device_name() / app_settings_get_device_name(), persisted under settings key omi/device_name. The in-RAM name is only replaced after settings_save_one() succeeds, so a read-back never reports a name that would be lost on reboot.
  • transport.c: new characteristic 19B10014-E8F2-537E-4F6C-D104768A1214 (READ | WRITE | NOTIFY) in the existing settings service, next to dim ratio (…0011), mic gain (…0012) and charging status (…0013). Writes reject a non-zero offset, zero length and anything over 25 bytes. A successful write saves to NVS, calls bt_set_name(), and updates the scan response through a work item. At boot, transport_start() re-applies the saved name before advertising. The name moves from the advertisement into the scan response. Discovery still works because the app matches Omi devices by service UUID.

App (app/lib/)

  • omi_connection.dart: performSetDeviceName() / performGetDeviceName() on …0014, with UTF-8 truncation that won't split a character (truncateUtf8ToBytes, maxDeviceNameBytes = 25). getDeviceInfo() reads the onboard name, so a new phone shows it. DeviceConnection provides safe defaults (setDeviceName → false, getDeviceName → null, supportsOnboardDeviceName → false). Only Omi connections opt in.

  • preferences.dart: phone-local alias under deviceAlias:<deviceId>. Validation uses the same 25-byte UTF-8 budget as the firmware (maxDeviceNameBytes, isValidDeviceName), not a character count, so the renaming phone and every other phone show the same name.

  • device_provider.dart: renameDevice() returns a DeviceRenameResult:

    • savedOnDevice: the BLE write succeeded and a read-back of …0014 matched.
    • deviceWriteFailed: the alias was saved on the phone, but the onboard write threw or was rejected, the read-back failed, or the read-back didn't match (this covers old firmware without the characteristic).
    • savedLocally: the device isn't connected, or the connection type can't store a name.
    • failed: the name is invalid or over budget, the device is unknown, or the alias couldn't be saved.

    The alias is re-applied in setConnectedDevice() / getDeviceInfo() and cleared on Forget Device.

  • device_settings.dart / device_info_groups.dart: tapping the Device Name row opens _renameDevice. The text field caps input at 25 UTF-8 bytes (Utf8ByteLimitFormatter) and shows a byte counter (n/25). If the result is deviceWriteFailed, a localized error snackbar says the name was saved only on this phone (deviceNameSaveFailed, translated in all 49 locales).

  • Changelog: app/changelog/unreleased/onboard-device-rename.json.

Review feedback addressed

  1. Best-effort onboard write. The app now reads the name back after writing it and shows a partial-success error instead of returning success silently. Tests cover a write error, a write that was acknowledged but not persisted, and a read-back error.
  2. Length budgets. The 40-character app limit is gone. The app alias, the text field, and the firmware all use 25 bytes of UTF-8.
  3. Description. This body has been rewritten to match the code.

Verification

  • flutter test test/unit/device_onboard_rename_test.dart test/providers/device_provider_test.dart: 58/58 pass (16 rename/connection tests, 42 provider tests including the existing suite).
  • flutter analyze on every touched Dart file: no errors and no warnings. The only notices are pre-existing avoid_print / naming infos in omi_connection.dart. dart format -l 120 is clean.

Not verified (honest disclosure)

  • I haven't compiled the firmware changes (omi.conf, settings.h, settings.c, transport.c) with the nRF Connect SDK / Zephyr toolchain, and no CI ran on omi/firmware for this PR.
  • I haven't tested anything on physical Omi hardware: the rename, NVS persistence across reboot, the re-advertised name, and a second phone reading the name.
  • Security posture: …0014 is plain READ/WRITE, like the neighboring settings characteristics, so anyone in BLE range could rename a device. This needs maintainer sign-off.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: the implementation direction is right and correctly targets the onboard-persistence requirement from #2824 (name stored in device NVS, readable by a new phone), and I found no blocking correctness bug — but three concrete issues should be addressed before this is merge-ready.

What looks good:

  • transport.c — the new device-name write handler rejects non-zero offsets and lengths over 25 bytes before touching NVS, and the boot path in transport_start() re-applies the saved name to bt_set_name() and the scan response before advertising starts.
  • Moving the advertised name from bt_ad into the scan response does not break app discovery: the app identifies Omi devices by the audio service UUID (app/lib/services/devices/discovery/native_bluetooth_discoverer.dart), which stays in the advertisement.
  • omi_connection.dart — truncateUtf8ToBytes() is boundary-safe for multi-byte UTF-8 (good test coverage), and GATT read/write failures degrade gracefully to the phone-local alias, which keeps old firmware working.
  • The 25-byte cap is safe against Zephyr's default CONFIG_BT_DEVICE_NAME_MAX (28), so bt_set_name() will not reject these names.

To address:

  1. device_provider.dart renameDevice() saves the local alias first and treats the onboard BLE write as best-effort (catch → debug log, still returns true). When that write fails transiently, the rename silently does not meet the acceptance criterion — a new phone will read the old name from the device. Please verify with a read-back after performSetDeviceName() or surface a partial-success state in the UI.
  2. Length budgets diverge: preferences.dart allows a 40-char alias while omi_connection.dart truncates to 25 UTF-8 bytes for the device. A 26–40 char (or multi-byte) name will show in full on the renaming phone but truncated on every other phone. Clamping the app alias to the same 25-byte budget would keep names consistent cross-phone.
  3. The PR description does not match the diff: it describes opcodes 0x03/0x04 on the 0x19B10011 characteristic, CONFIG_BT_DEVICE_NAME_MAX=32 and 31-byte names, a custom_device_name_ pref key, and getOnboardDeviceName()/BtDevice.sanitizeDeviceName()/_showRenameDeviceDialog() — none of which exist here (the diff adds characteristic 0x19B10014, a 25-byte cap, deviceAlias:, setDeviceName/getDeviceName, _renameDevice). Please update the body so reviewers and bounty adjudicators can trust it.

Security note: the new characteristic is plain READ|WRITE like the neighboring settings characteristics, so anyone in BLE range can rename a device. That matches the existing service posture (mic gain, dim ratio), so I'm not requesting a change — just maintainer sign-off that this is acceptable.

USER IMPACT: users can rename their Omi in Device Settings; the custom name persists on the device itself and shows up on other phones, with a phone-local fallback for older firmware.

What I'd still want as a reviewer: a firmware build confirmation (no CI ran on the omi/firmware changes in this PR), a test documenting the intended behavior when the onboard write fails after a local alias save, and on-hardware verification of the rename + re-advertise path — and note that #13182, #14289, and #14558 are also open for #2824, so a maintainer will need to pick which candidate carries the feature.

Leaving for human maintainer review: choosing among the competing open #2824 PRs and signing off on the firmware BLE surface are maintainer calls, not mine.


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 29, 2026
…UTF-8 bytes (BasedHardware#2824)

- renameDevice() now returns DeviceRenameResult; after writing 0x19B10014 it
  reads the name back and reports deviceWriteFailed on write error, read error
  or mismatch instead of silently succeeding.
- Device settings shows a localized snackbar (deviceNameSaveFailed, 49 locales)
  when the name was saved on the phone but not on the Omi.
- App alias budget is now the firmware's 25-byte UTF-8 limit
  (SharedPreferencesUtil.maxDeviceNameBytes) instead of 40 characters; the
  rename field uses a UTF-8 byte-limit formatter with a byte counter.
- Tests for read-back success/failure paths, byte-based validation and the
  formatter.
…ceeds (BasedHardware#2824)

Keeps the 0x19B10014 read-back truthful: if settings_save_one() fails the
characteristic keeps returning the previous (persisted) name.
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: this is a well-built, cohesive feature — firmware + app rename with a verified read-back and genuinely good test coverage. Nothing blocking from my side; a few non-blocking findings and two checks I'd want before a maintainer merges.

I verified the main behavioral claim: transport.c moves the BLE name out of the advertisement (bt_ad) into the scan response (bt_sd) to fit the 31-byte budget with a 25-byte name. I checked app/lib/services/devices/discovery/native_bluetooth_discoverer.dart on main — Omis are classified solely by service UUID (_hasService(p, omiServiceUuid)) and bt_ad still carries the audio service UUID, so app discovery is unaffected. The name stays visible in the scan response and via GAP (bt_set_name), which active scanners read.

Non-blocking findings:

  • transport.c: 0x19B10014 declares BT_GATT_CHRC_NOTIFY plus a CCC handler, but nothing ever calls bt_gatt_notify() on it and the app only reads. Either drop the NOTIFY property + CCC, or actually notify subscribers on rename.
  • transport.c write handler accepts arbitrary bytes; an embedded NUL would be silently truncated by strlen() inside app_settings_save_device_name() (settings.c) and persist a shorter name. The app always writes valid UTF-8, so this is cosmetic — but a byte check or a one-line comment documenting the contract would help.
  • device_provider.dart renameDevice(): the phone-local alias takes precedence over the onboard name on reconnect, so if another phone renames the device, this phone keeps showing its own alias until it renames again. Sensible as designed — just confirming the precedence is the intended product behavior.

Two checks before merge: (1) confirm CONFIG_BT_DEVICE_NAME_MAX >= 26 in this build so bt_set_name() doesn't truncate the GAP name (the scan response is set directly and is unaffected); (2) no CI check runs are visible on this PR at all — please make sure the app test suite runs on this head.

What's notably good: settings.c persists to NVS first and only adopts the name in RAM after flash accepts it, so a GATT read-back can never report a name that would be lost on reboot; the 25-byte UTF-8 budget is enforced consistently at three layers (validator in preferences.dart, byte-limit formatter with a byte counter in device_settings.dart, and truncateUtf8ToBytes in omi_connection.dart which refuses to split a codepoint); device_onboard_rename_test.dart covers the multi-byte boundary, GATT read/write failures, and an acked-but-dropped write caught by the read-back.

Blast radius: the writable characteristic needs no encryption/auth — the same trust model as the existing settings characteristics (mic gain, dim ratio), and a display name is non-sensitive. The advertising-layout change is visible to every BLE observer of the device, not just the app.

USER IMPACT: users can rename their Omi in Device Settings; with new firmware the name persists on the device itself and shows up on other phones, with a phone-local fallback name on older firmware.

Leaving for human maintainer review: this adds a new cross-surface firmware protocol (a new GATT characteristic and a change to the advertising layout) plus an alias-precedence product decision — a firmware maintainer should sign off on the protocol and adv changes.

This review was produced by the repo's automated maintainer-review assistant on behalf of the Omi maintainers.


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

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