Commit Graph
124 Commits
Author SHA1 Message Date
James Babcock 1f9f3b35d3 UI refinements to watch app and phone preview
<details>
<summary>Prompts Used</summary>
Thanks. Next up, let's add a "Phone display" section to the Settings app (above the Watch section). We'll add a "Preview color" setting (options: White, Green; default White), which controls whether the mirror display is white/grayscale (best looking) or green (matches the physical glasses). We'll move the "Touch mirror" toggle setting (currently on the phone main screen) into the phone display settings menu. We'll add a "Show brightness control" toggle setting (default off) and a "Show screen size" toggle setting (default off), which control the visibility of the corresponding elements on the phone main screen.

Let's also make it so that double-tapping the watch (or simulated watch on the phone, mirror, etc) while the app-switcher is selected turns off the glasses display, in the same way that double-tappign the R1 ring does.

> All four pieces are in and everything builds (webpack, Gradle with the Java changes, and a clean `tsc`). Summary:
>
> **"Phone display" Settings section** — added between Roam and Watch in the on-glasses Settings app, with four entries:
> - **Preview color** (White/Green, default White) — new enum setting `phone.previewColor`. The colorization happens in the Java preview path: `PreviewBitmapUtil.fromGray` gained a `green` variant whose LUT maps luminance to green-on-black instead of grayscale, threaded through `getCompositePreviewBitmap` → `getCompositePreview(green)` → the controller, which reads the setting per refresh. A settings change also schedules an immediate preview refresh, so flipping the color updates the mirror right away instead of waiting for the next composited frame.
> - **Touch mirror** — moved from the phone main screen. It's now a proper `ConfigSettingBoolean` reusing the existing `phone.mirrorTouch` storage key, so anyone who already turned it off keeps that choice. The label+switch pair is gone from the ring row in `remote-controls.xml`, and the view model reads the setting per gesture.
> - **Show brightness control** and **Show screen size** (both default off) — new booleans controlling visibility of the brightness slider/Auto toggle and the display-mode picker on the phone main screen. The whole display-controls row collapses when both are off; the bindings refresh through the existing `onAnySettingChanged` → `refreshDisplayControls` path, so toggling them from the glasses updates the phone screen live. Note this means the main screen is more minimal out of the box — brightness and screen size remain reachable via the Settings app either way.
>
> **Watch double-tap at the app switcher** — the watch-scheme special case in `handleSidebarInput` is removed: a double-click from any source (watch, phone pad/d-pad, mirror double-tap — they all arrive as source `"watch"`) now turns the display off when the sidebar is selected, exactly like the ring's. The original code deliberately excluded the watch on the theory that sleeping was a trap since any watch gesture re-wakes; with your "Watch input wakes display" setting now gated (and double-tap waking a dark display regardless), the toggle behavior is symmetric: double-tap at the switcher sleeps, double-tap again wakes.
>
> Hardware-test notes: the green preview tint and the collapsed-controls layout are worth one visual check on the phone, and the double-tap-to-sleep from the watch is a quick on-device confirm.
</details>
2026-08-25 01:37:29 -07:00
James Babcock eef7aa2679 <details>
<summary>Prompts Used</summary>
Act as a code reviewer for https://github.com/jimrandomh/faceclaw/pull/14 (checked out in this working directory).

> * The review finished — 42 raw candidates were verified down to 10 confirmed findings. Reporting them now.
>
> * Code review(review · 10 findings)
>   ⎿  app/phone-ui/main-view-model.ts
>        ●  766 [correctness]   mirrorFraction subtracts view.getLocationOnScreen() from tap coordinates that NativeScript already delivers
>                               view-local, so every phone-mirror tap is shifted up/left and misroutes
>        ●   84 [resource-leak] MainViewModel's constructor registers onAnySettingChanged and discards the unsubscriber; a new view model is
>                               built on every page navigation, leaking listeners and retained preview bitmaps
>      wear/app/src/main/kotlin/com/faceclaw/wear/MainActivity.kt
>        ●   52 [correctness]   onStop abandons an in-progress stem-button hold without sending LONG_PRESS_RELEASE, so the glasses shell
>                               escape menu opens by itself
>      wear/app/src/main/kotlin/com/faceclaw/wear/ui/TouchpadGestures.kt
>        ●   62 [correctness]   Breaking out of the touchpad gesture loop on a consumed pointer event (or coroutine cancellation mid-hold)
>                               skips onLongPressEnd, leaving a stuck long-press
>      wear/app/src/main/kotlin/com/faceclaw/wear/PhoneLink.kt
>        ●  270 [correctness]   loadStateItem queries the Data Layer with a hostless Uri (`wear:/faceclaw/state`), which matches no stored
>                               items, so the cached phone state is never read
>      app/ui/shell/modal-layer.ts
>        ●   14 [correctness]   MODAL_INTERIOR is a module-level constant frozen at import time from the (now runtime-dynamic) display mode,
>                               while modalRect() is computed live, so modals render corrupted after a display-mode switch
>      app/g2/dashboard-controller.ts
>        ● 1404 [correctness]   handleMirrorTouch wakes the glasses display unconditionally, bypassing the watchWakesDisplaySetting gate
>                               that the parallel injectSyntheticRingInput path honors
>        ● 1440 [correctness]   A mirror tap while any second layer is stacked (e.g. an in-window long-press menu) degrades to a blind
>                               synthetic click that activates whatever is highlighted, not what was tapped
>      App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java
>        ●  147 [correctness]   Watch gestures/commands queued while the JS listener is down are replayed up to 30 seconds later on listener
>                               registration, executing stale non-idempotent input the watch already reported as failed
>      wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt
>        ●  232 [efficiency]    WristTwistDetector (gyroscope, default-on) samples at 100 Hz via DisposableEffect and is not stopped when
>                               the activity stops, draining the watch battery while the process is cached
>
> * Review of PR #14 (Wear OS companion app + remote controls, 85 files, +5813/−102) is done — 10 confirmed findings reported above, ranked by
>   severity. The headline items are the phone-mirror tap coordinate double-correction (which misroutes every mirror tap in the default
>   configuration) and two independent paths on the watch that can drop LONG_PRESS_RELEASE, each of which makes the shell escape menu open on the
>   glasses by itself.
>
> A few things beyond the reported list, for context:
>
> Refuted during verification (looked like bugs, aren't): the watch ack-timeout-during-render theory (input injection never blocks on BLE
> transmit), mirror swipes stealing page scroll (no enclosing ScrollView), and a suspected raw-settings-key notification gap (the store-level
> broadcast covers raw keys).
>
> Confirmed but below the 10-finding cap — worth folding in if you're touching those areas anyway:
> - shell.closeAssistant() no-ops via popIfTop when another layer sits above the assistant, yet still acks ok to the watch.
> - Landscape preview sizing still assumes the old 260-wide panel after the XML moved to 360 (overlap under ~568 dip).
> - The shell escape menu and tool-debug dialogs hardcode SIDEBAR_WIDTH + 8, wrong in the new full-panel mode.
> - A CapabilityClient IPC fires every 250 ms during streamed assistant replies even on watchless phones; backgrounded preview updates bypass
>   their 150 ms floor.
> - Cleanups: the sidebarWidth() > 0 || focus === "sidebar" predicate appears three times, sidebar slot math is duplicated in chrome-layer.ts,
>   dead protocol-version plumbing, dead padPointers field, and display-mode is missing from wear/PROTOCOL.md.
>
> If you'd like, I can apply fixes for any subset of these, or post the findings as inline PR comments (/code-review 14 --comment).

<hr>

Thanks, let's go ahead and write fixes for all of the issues you described.

> Everything builds and tests pass. All 16 issues from the review are fixed — the 10 reported findings plus the six below-cap items. Here's what changed, by fix:
>
> **Watch app (Kotlin)**
> - **Stuck long-press via onStop** — `MainActivity.onStop` now sends `LONG_PRESS_RELEASE` when a stem hold is in progress before dropping the link, so the phone's escape-menu countdown can't run to completion on its own.
> - **Stuck long-press via the gesture loop** — `detectTouchpadGestures` wraps the loop in try/finally that pairs every `onLongPressStart` with an `onLongPressEnd`, covering both the consumed-event `break` and coroutine cancellation mid-hold.
> - **Cached state never loading** — `PhoneLink.loadStateItem` now queries `wear://*/faceclaw/state` (wildcard host) instead of a hostless Uri that matched nothing, so the watch shows the cached dashboard state when the phone is unreachable.
> - **Sensors draining battery while stopped** — the gyroscope/accelerometer/off-body detectors are now driven by a `WhileStartedEffect` helper tied to the activity lifecycle: they stop on `ON_STOP` (palmed screen, back to watch face) and restart on `ON_START`, instead of running at 100 Hz for as long as the process is cached.
> - **Dead protocol plumbing** — removed the unused `Protocol.PROTOCOL_VERSION` const and the never-read `PhoneState.protocol` field; the wire field stays and PROTOCOL.md now documents it as reserved.
>
> **Phone Java**
> - **Stale input replay** — `FaceclawWearBridge` now queues only idempotent `/faceclaw/state/request` messages for replay after the JS listener registers; gestures and commands that arrived while the dashboard was down are acked as failed and dropped, never executed up to 30 seconds later.
>
> **Phone TypeScript**
> - **Mirror taps misrouting (the top finding)** — `mirrorFraction` no longer subtracts `getLocationOnScreen()`; NativeScript's `getX`/`getY` are view-local DIPs (I verified this in the installed `@nativescript/core` gesture source), so every mirror tap was being shifted up-left by the status bar + action bar. Taps now land where you touch.
> - **Mirror touch ignoring the wake setting** — `handleMirrorTouch` now honours `watchWakesDisplaySetting`: with it off, only a double-tap reaches a dark display, matching the rest of the watch scheme.
> - **Blind click through open menus** — `LayerStack.hitTest` now consumes a mirror tap when any layer is stacked (menu, dialog) instead of reporting a miss, so a tap on visible app content can no longer activate whatever menu row happened to be highlighted (e.g. "Close window").
> - **Modal corruption after display-mode switch** — `MODAL_INTERIOR` is now a live `modalInterior()` function, and `ShellModalLayer.paint` re-syncs the inner stack's size each paint, so notification modals render correctly after switching Band ↔ Full panel.
> - **View-model leak** — `MainViewModel` keeps its controller/settings unsubscribers and exposes `attach()`/`dispose()`; `main-page.ts` disposes on unload and re-attaches on load (re-attach is needed because suspend/resume fires unloaded/loaded without a navigation, and `subscribe` delivers a fresh snapshot so nothing is missed).
> - **`closeAssistant` no-op** — new `LayerStack.popThrough` closes the assistant overlay plus anything stacked above it (follow-up voice dialog, alert); the watch ack now says "The assistant was not open." when there was nothing to close.
> - **Watchless-phone IPC churn** — assistant stream events and alerts are skipped when no watch is reachable, so a streaming reply no longer triggers a CapabilityClient lookup every 250 ms.
> - **Backgrounded preview floor bypass** — the 150 ms floor check (and timestamp) in `updateCompositePreview` now runs before the foreground-activity check, so backgrounded per-frame refreshes actually throttle.
> - **Full-panel hardcodes** — the shell escape menu and tool-debug dialogs position at `sidebarWidth() + 8` (0 in full-panel mode) instead of the fixed 64 px strip.
> - **Cleanups** — the strip-visible predicate is now one `sidebarStripVisible()` helper in geometry.ts (used in three places); sidebar slot math is a single `slotPosition()` shared by drawing and hit-testing; dead `padPointers` removed; landscape preview sizing updated to the XML's 360 dp panel; `wear/PROTOCOL.md` documents the `display-mode` command and `displayMode` state field.
>
> Verification: `./build.sh` (webpack + Gradle) succeeds, `npx tsc --noEmit` is clean, the wear `:app:assembleDebug` builds, and all 59 tests pass. The behavioral fixes — especially mirror-tap coordinates, the two long-press-release paths, and the watch state cache — still need a hardware pass to confirm on device.
</details>
2026-08-25 00:09:47 -07:00
James Babcock 646335cb64 Merge branch 'main' of https://github.com/jimrandomh/faceclaw into android-wear-integration
# Conflicts:
#	app/phone-ui/main-page.xml
#	app/phone-ui/main-view-model.ts
2026-08-24 22:24:03 -07:00
James Babcock ca183e5aed Merge branch 'bluetooth-pairing-improvements' 2026-08-24 12:59:33 -07:00
James Babcock 16d3b7c25f Fix reconnect-loop issue when device MAC address is configured but not paired 2026-08-24 12:56:09 -07:00
James Babcock 92a2530e0e Merge branch 'main' of https://github.com/jimrandomh/faceclaw into android-wear-integration 2026-08-24 00:23:16 -07:00
James Babcock fa241161e4 Merge branch 'main' of https://github.com/jimrandomh/faceclaw 2026-08-24 00:19:07 -07:00
James Babcock fea29c5ff3 Add a bunch of refinements to the pairing process
<details>
<summary>Prompts Used</summary>
Thanks. Let's address 1-8. We can leave the setLegacy(false) in place as too-old phones are already unsupported for other reasons. Let's pause the scan and timer when the app is backgrounded and resume it when it's foregrounded again. Let's deduplicate and clean up the things mentioned in that section. We don't need to support single-arm pairing at all; the glasses themselves won't boot/function unless both temples are working.

I tested on-device and also noticed some dark-mode issues and minor UI cleanup. The instructional text at the top ("Take the glasses out of there case [...]") is dark-on-dark if in dark mode. The background behind the glasses, ring, and selected cards is light-blue (regardless of dark mode); some of the text on it is white and some is black. Let's keep the card background the same in light mode and make it dark-gray in dark mode.

> All fixes are implemented, tested, and committed as `1718253` on `bluetooth-pairing-improvements` — but one thing needs your decision before the PR itself updates (details at the end).
>
> ## What landed
>
> **Findings 1–8**, as requested:
>
> 1. **Auto-reconnect** — `onPairGlassesTap` now calls `resumeAutoReconnect()` right after the pre-scan disconnect (pairing is a detour, not a Disconnect), so the main page's `autoConnect` picks the glasses back up on return. The config page's "Scan for glasses" now also drops the live link first (lazy-required controller so onboarding still never instantiates the singleton).
> 2. **Mixed-arms warning** — `pairs()` groups by a new canonical `serialKey()`, and when exactly one lone left and one lone right with different serials are visible, both rows now carry the "arms from two different pairs" warning. (The old per-row check was provably unreachable, since a serial-keyed group can't contain two serials.)
> 3. **Degrading selection** — `refresh()` deselects a pair that regresses below complete, and `onPrimaryTap` refuses to save a one-armed pair instead of padding it with stored addresses. Since single-arm pairing is unsupported, the identity is now always saved on a pair save.
> 4. **ingest() clobbering** — a manufacturer-data-less record (bonded re-emit or split report) no longer overwrites note/flag/name learned from a full advertisement; additionally, a split report that fails to classify on its own is retried with the remembered name/manufacturer data, so a nameless half no longer drops the arm.
> 5. **TX power** — `estimateProximity` no longer takes a TX-power argument at all; the calibration table is the only reference, and confidence no longer rewards an advertised value.
> 6. **Ring identity** — a ring-only save updates `ringName`/`ringAddress` in the stored identity.
> 7. **Ring detection** — TS requires the stock `EVEN R1` prefix; Java admission tightened to match (still a strict superset).
> 8. **One-shot scans** — `scanCandidates` keeps every sample, and `buildAddressSet` runs them through `DiscoveryAggregator`: left/right come from the closest serial-joined *complete* pair. Bonded-only batches (no serials anywhere) keep the old per-role fallback so "Load paired devices" still works. `setLegacy(false)` left as-is per your call.
>
> **Backgrounding** — the pairing model hooks Application suspend/resume: scan + 500 ms timer stop on suspend and restart on resume, with the hooks detached when the page is truly left (back navigation, Save, Cancel).
>
> **Cleanup** — one MAC normalizer (`normalizeMacAddress`, now in the pure advertisement module, re-exported by device-addresses, used for the ring "Yours" compare); one serial-equality definition (`serialKey`/`serialsMatch`, containment fallback removed); shared `formatErrorMessage` replaces five copies (there were 5, not 3); shared `app/util/hex-util` replaces the duplicate TS hex codecs (firmware-builder keeps its strict validation as a thin wrapper); one Java `bytesToHex` in `FaceclawFirmwareUtil` replaces three; `glassesRow`/`ringRow` share a presentation-base helper; dead row-address fields, `glassesSectionVisibility`, the identical-branch ternary, and `zoneRank`/`ZONE_ORDER` deleted; `.test-build/` added to `.gitignore`.
>
> **Dark mode** — light mode is untouched; in dark mode the instructions and empty-state text get light grays, all cards go dark-gray (selected keeps a blue border on a blue-tinted dark gray), and every card text color has an explicit dark-mode counterpart so nothing mixes white and black on one card. Worth a quick on-device look since I can't verify colors visually.
>
> **Verification**: `npm test` — 60/60 pass including 5 new tests (mixed-arms warning, bonded-re-emit preservation, split-report merge, strict ring prefix, TX-power arity pin); `build.sh` and `tsc --noEmit` clean; Java compiles in the Gradle build.
>
> ## The catch: PR #13 is from a fork
>
> PR #13's head branch lives in **kalanihelekunihi/faceclaw**, not your repo. My `git push origin` created a same-named branch in *your* repo (which doesn't touch the PR), and when I then tried to push to the fork's branch (allowed — the PR has "maintainer edits" enabled), the permission gate blocked it, sensibly, since it writes into someone else's repository. Your options:
>
> - **Update the PR**: `git push https://github.com/kalanihelekunihi/faceclaw.git bluetooth-pairing-improvements:bluetooth-pairing-improvements` — the local branch contains their commit plus your merge of main plus the fixes.
> - **Or merge directly**: the fixed branch is already at `origin/bluetooth-pairing-improvements` in your repo; merge it to main and close PR #13 with a comment. (If you go this route, note the accidental branch on origin is the thing you'd merge — otherwise you may want to delete it.)
<hr>
Thanks. Next up, after selecting devices and clicking Continue and advancing to the "Checking Firmware" stage, the check fails with "no response to the device-info query". This was when testing on a device that hasn't previously been paired with the glasses (as opposed to the more common case of a device taking over an already-bonded connection that was created by the stock Even app and remembered in Android's paired devices list), when connecting to glasses with stock firmware 2.2.9. I believe this was preexisting and not introduced in this branch. I have a logcat from the run in ~/tmp/a9_logcat.

Possibly relevant: Firmware version 2.2.9 changed some details of connection and pairing, which broke `g2flash`. A writeup of what changed is in ../notes/ble-connections-2.2.9.md.

> Done. Here's the summary:
>
> ## Root cause — confirmed
>
> The logcat corroborated the 2.2.9 writeup exactly. At 14:09:43 the phone opened an ACL connection to `Even G2_32_R_820967` (the probe connecting to the right arm), and it dropped 5.5 s later — connect + discovery + prelude ack + the probe's 4 s query timeout, then the probe closing. Critically, **no SMP pairing or bonding activity appears anywhere in that window**: nothing ever asked the lens to authenticate or encrypt. On 2.2.9, the firmware acks the prelude but won't answer the settings query until the sid-0x80 security-auth exchange completes over an encrypted link — and on a never-bonded phone, that exchange is also what triggers SMP pairing in the first place. The probe (like every Faceclaw connection path) never sent it, so it only ever worked by inheriting a bond the stock Even app had created.
>
> ## The fix (committed as `1bde70a`, pushed to `origin/bluetooth-pairing-improvements`)
>
> Implemented the authentication exchange from `../notes/ble-connections-2.2.9.md` (the g2flash-validated wire format) across all four connection paths:
>
> - **`BleProtocol`**: `buildAuthenticationRequest(magic)` (f1=4, f2=magic, f3={f1=1,f2=4} on sid `0x80`, flag `0x00`) and `isAuthenticationSuccess` (strict per the writeup: command 4, matching magic, empty `1a 00` result — a completed GATT write is not success).
> - **Device-info probe** (the failing path): authenticates after subscribing, before the prelude, with a 30 s window since a first-time connection may sit waiting on the OS pairing dialog — the check page now shows *"Authenticating with your glasses... If Android asks to pair, tap Pair."* I made this one **soft**: the probe also runs against the custom firmware, whose response to the exchange isn't hardware-verified, so an unconfirmed auth falls through to the query as before — but a query timeout after unconfirmed auth now says the pairing didn't complete instead of the bare "no response" you saw.
> - **Flash-prompt communicator**: authenticates each arm before the prelude, mandatory (it only ever talks to stock firmware).
> - **Firmware flasher**: control-channel notifications are now mandatory, each lens authenticates before OTA `BEGIN`, and I removed the OTA-time heartbeat entirely per the writeup's follow-up list — official captures show no control traffic mid-transfer, heartbeats demonstrably don't satisfy the 2.2.9 deadline, and a concurrent control writer interleaves with the marker/data transactions. The envelope counter also resets after bring-up, mirroring the stock sequence.
> - **Main communicator**: authenticates both arms after connecting, before the prelude, with a short (6 s) soft wait that logs and continues on timeout — so firmware that never answers can't stall every reconnect, while stock 2.2.9 (e.g. the incompatible-firmware detection path) gets a working session.
>
> Build passes (webpack + Gradle/Java). Left `setLegacy(false)` and everything else untouched.
>
> **Hardware tests to run**: fresh-phone onboarding against stock 2.2.9 end-to-end (check → on-lens prompt → flash — expect one Android pairing request per lens the first time), and a regression pass on custom-firmware connect + re-check. One thing to watch: if the CFW turns out not to answer the auth request, the probe adds ~30 s per check on CFW glasses — if you see that, tell me and I'll gate the long wait on bond state.
<hr>
Hmm, that did make it pair fully (which if nothing else is necessary for the next step where we actually flash firmware), but I'm still getting "no response to the device-info query".
One thing to check: Are we sending the message and expecting the response on the correct lens? Some messages are right-lens-only and this might be one of them.

> Pushed as `a7684f6`. Here's where the investigation stands:
>
> ## Answer to your lens question
>
> I checked the routing against every reference we have, and the probe *is* doing what the pre-2.2.9 world says is correct:
>
> - The probe sends prelude + settings query to the **right** arm — same as Faceclaw's main communicator (`MessageBuilder.batteryQuery()` has `isLeftArmMessage=false`), which is the path that works when bonded.
> - `g2-kit-unofficial`'s `transport.md` is explicit: "For most things we only use the **right arm**… The L arm is silent on async channels," and its `settings.ts` sends the same query shape (commandId=2, `settingInfoType=BASIC`) to the right-arm session.
> - But: all of that predates 2.2.9, and `g2flash.py` — the only thing hardware-validated against 2.2.9 — never does a settings read at all (auth + OTA only). The 2.2.8-app capture slice also contains no settings read. So **nobody has a verified 2.2.9 settings-read exchange**, and your hypothesis can't be ruled out from references.
>
> One telling detail from your report: the error text you got was the *plain* "no response…" variant, which the probe only produces when the auth exchange **succeeded** (an unconfirmed auth appends a pairing hint). So on 2.2.9 the right lens acks the prelude, completes security auth, and still won't answer the settings read — the auth gate wasn't the (whole) story for this particular message.
>
> ## What I changed — one run should settle it
>
> Rather than guess again, the probe is now an instrumented experiment:
>
> 1. **Full frame tracing** — every control-channel frame in both directions (sid, flag, protobuf type, magic, fragment info, payload hex prefix) plus every write logs under the `FaceclawDeviceInfo` tag. If the lens is answering with an unexpected flag, a different magic, a fragmented frame, or a device-initiated push we've been dropping, it will be in the trace.
> 2. **Query retry** — the read is attempted twice per lens before declaring silence.
> 3. **Push acceptance** — any sid-0x09 frame that parses to firmware versions is accepted as the answer even if it doesn't match our magic (in case 2.2.9 pushes the snapshot on its own magic instead of acking reads).
> 4. **Left-lens fallback** — if the right lens stays silent, the probe runs the identical connect → auth → prelude → read against the **left** lens and uses its answer, logging which lens replied. That's your hypothesis tested directly, in the same run.
>
> Build passes. When you re-run the check, please grab the app-side log — last time's capture only had the system buffer, so none of the probe's own lines were in it:
>
> ```
> adb logcat -s FaceclawDeviceInfo
> ```
>
> That trace will show exactly what each lens said (or didn't), and whichever way it comes out, we'll know whether the fix is "query the left lens", "match the response differently", or something 2.2.9-new.
<hr>
Thanks. There's now a filtered logcat file at ~/tmp/logcat_deviceinfo and an unfiltered logcat at ~/tmp/logcat.

> Mystery solved — and the check is passing on your fresh device now. Here's what the trace showed:
>
> ## What the frames said
>
> 1. **The right lens is the correct endpoint after all.** Every successful read came from the right lens; the left-lens fallback never fired.
> 2. **The real culprit was a post-prelude drop window.** In each failing sequence: auth succeeds → prelude acked → our settings read (magic 101) goes out → and right around it the *lens* starts sending its own sid `0x80` notifications (flag `0x01`, command 4, device-chosen magics like 252/104, payload `{f1:1}` — a shape distinct from both our request and the success ack, repeating ~2 s apart). A read that lands inside that window is silently swallowed. The retry 4 s later (magic 102) was answered within ~100 ms, every single run. In the one run where the lens's notification arrived *before* our read, the first read succeeded immediately — so it's a brief busy window, not a rejection.
> 3. So the fresh-phone failure was two stacked problems: missing auth prevented pairing entirely (fixed last round), and once auth existed, the first read still intermittently fell into this window (fixed by the retry). The earlier `17:13:36` line in your log even shows one lucky success on the previous build — it was always timing-dependent.
>
> ## Follow-ups (pushed as `3e44083`)
>
> - **Flash-prompt page-create now retries once too** — it writes at exactly the same post-prelude moment, so it would have hit the same window intermittently when you proceed to the actual flash step.
> - **Documented the finding** in `../notes/ble-connections-2.2.9.md` as a new "Post-prelude drop window and device-initiated sid-0x80 notifications" section, including the observed frame bytes and the guidance to retry the first post-prelude request.
> - The probe's frame tracing is still in place — it'll be useful when you test the flash itself.
>
> One open question I noted in the writeup: we currently ignore the lens's own sid-0x80 notifications and saw no ill effect in these short sessions, but if a long-lived stock-firmware connection (the main communicator's incompatible-firmware detection) ever misbehaves, those unanswered notifications would be the first suspect — we don't know whether the stock app replies to them.
>
> Next step when you're ready: the flash path itself on this fresh device — the flasher now authenticates per lens and streams without heartbeats (matching the hardware-validated g2flash sequence), but that's the one leg still untested on hardware.
<hr>
Another developer reported running into a Samsung-device-specific issue where inbound (glasses-to-phone) messages larger than 64 bytes were truncated. The response to the Settings message (containing the firmware-extensiosn string) is larger than that, and it might be packaged in a way where truncation causes the packet to be dropped entirely. I tested on a different device and it looks like the no-settings-reply issue only replicates on the Samsung tablet.

> Pushed as `b952cc2`, and the workspace note is corrected. Summary of how the Samsung report changes the picture:
>
> ## Reconciling the report with the trace
>
> The 64-byte theory fits everything, with one important detail: nothing arrived at the app for the missing replies — the probe's tracing logs every value delivered on the control characteristic, even unparseable ones, and `FaceclawBleManager` filters nothing. So on this tablet, oversized values are being *dropped below the app layer*, not truncated-and-delivered.
>
> The size arithmetic supports it: every frame the tablet did deliver was ≤55 bytes (the steady-state settings reply is 8+47). The missing first reply would only trip a 64-byte limit if it were larger — either the firmware's first reply carries a fuller snapshot, or it gets coalesced into one notification value with one of those lens-initiated sid-0x80 notifies (11-byte frame + 55-byte frame = 66 bytes > 64). Both variants explain why the other device never reproduces it, why the retry (compact reply) always lands, and why the one run where the notify had already been delivered separately succeeded first try. If you still have the other device's `FaceclawDeviceInfo` trace, one line would settle which variant it is: the `len=` of its *first* settings reply (47 → coalescing; >55 → fuller first snapshot).
>
> ## What I changed
>
> - **`BleProtocol.splitFrames()`** — splits a notification value into its individual `aa21`/`aa12` envelope frames. This fixes a real latent bug the theory exposed: we only ever parsed the *first* envelope per value, so a coalesced second frame was silently dropped even on healthy devices. The probe, flash-prompt communicator, and flasher control channel now process every frame in a value.
> - **Better tracing** — the probe logs multi-frame values with the raw value size, and marks any frame whose actual length falls short of its declared length as `TRUNCATED`. If Samsung ever delivers a truncated value rather than dropping it, the next trace will say so explicitly.
> - The first-request retries from last round remain the workaround for values the Samsung stack drops outright — that's what already makes the check pass on the tablet, and the flash prompt has the same insurance.
>
> ## The residual exposure worth deciding on
>
> The onboarding flow itself should now be Samsung-safe: all flasher OTA acks are 12 bytes, the auth reply is 19, the prompt-page acks are small. But **after** flashing, the custom firmware's settings reply carries the capability string — well over 64 bytes in a single frame. On this tablet the main communicator would never see it and would report "firmware not detected", and no app-side code can recover bytes the stack never delivers. Since you control the CFW, the durable fix is firmware-side: have the CFW chunk its lens-to-phone notifications at ≤64 bytes (or split the caps into a separate small frame) — that work lives in the g2flash patches repo, not here. I've noted this in `../notes/ble-connections-2.2.9.md` and memory so it doesn't get lost when you hit it.
<hr>
Let's replace the single "Retry" option with three buttons "Retry", "Install", and "Skip" (Install proceeding as if we had detected stock firmware, skip proceeding as if we had detected compatible custom firmware).
<hr>
Continue
<hr>
Continue

> Done — pushed as `9adff01`.
>
> When the firmware check lands in the error state, the button row now offers four actions:
>
> - **Install / Skip** (new row, error phase only):
>   - **Install** navigates straight to the flash page with `mode: "install"` — identical to what the "Install Firmware" button does after a real stock-flashable detection.
>   - **Skip** routes through the same `applyClassification("custom", …)` path as a genuine custom-firmware detection, which matters for one subtlety: if the phone-side G2 fonts haven't been extracted yet, Skip still runs the font download/extraction step before showing "you're all set" with Finish, rather than completing onboarding with EvenHub fonts missing.
> - **Back / Retry** keep their existing places, with Retry remaining the primary action.
>
> Both new handlers are guarded on the error phase so a stale tap can't fire them from another state, and the row collapses everywhere else. Build passes; visual check on the tablet pending as usual.
<hr>
Let's make some refinements to the onboarding flow.

On the initial splash screen (Faceclaw / Perching on the faces of giants / logo), the logo is a black-on-transparent image. This looks reasonable in light mode on a phone-sized screen, but on a dark-mode tablet it's too low contrast, is too close to the top (we'd like it vertically centered), and is too small.

On the "Pair Your Glasses" screen, we will remove some unnecessary UI elements. In the list of glasses and list of rings, there's a "Closest" badge; hide that badge unless there is more than one entry in the list for it to be closer-than. Keep the signal-strength-out-of-four estimate, but remove the conversion to estimate distance in cm/m. Remove the line that says "Advertising" from the ring. Remove the log display from the bottom (it says "scan started (unfiltered, low latency)" and if you press the pause button also "scan stopped").

On the "Flashing Firmware" page, we have a progress bar with step-size based on the number of segments uploaded so far. Since the update package is one large segment and five small ones, this makes it progress very unevenly. Weight the sizes by segment size.

On the "Configure Devices" screen, the Save and Back button positions are swapped (Back should be on the left, Save on the right). If the device is in dark mode, the text boxes for right arm/left arm/R1 ring MAC addresses are white-on-white.

> All four refinements are in place; the build (webpack + Gradle) succeeds and all 59 node tests pass.
>
> **Splash screen** (`onboarding-page.xml`, `onboarding-view-model.ts`, `app.css`): Step 1 now renders as its own vertically-centered stack (headline, tagline, logo) instead of sharing the top-anchored ScrollView with steps 2–3. The logo height scales to ~40% of the screen height (capped at 480dp so the 306×512 PNG doesn't upscale into mush), and a new `.ns-dark .onboarding-logo { tint-color: #e6e6e6 }` rule tints the black-on-transparent art light in dark mode.
>
> **Pair Your Glasses** (`pairing-candidates.ts`, `ble-proximity.ts`, `pairing-view-model.ts`, `pairing-page.xml`): `nearestCandidateId` now returns null for a single-entry list, so the "Closest" badge only appears when there's something to be closer than (the "Yours" badge is unaffected). The proximity line keeps the ●●●○ glyph and zone label but drops the cm/m distance — I deleted `formatDistance`/`proximitySummary` from ble-proximity entirely since the pairing list was their only consumer. The ring's "Advertising" line is gone (rows only show "Paired with this phone" when bonded, with a visibility binding so empty lines don't take space), and the diagnostics log at the bottom is removed along with its view-model plumbing and CSS.
>
> **Flashing Firmware progress** (`FaceclawFirmwareFlasher.java`, `FaceclawFirmwareFlasherListener.java`, `firmware-flasher.ts`, `onboarding-flash-view-model.ts`): the Java flasher now reports `bytesSent`/`bytesTotal` across the whole lens image alongside the existing component/block indices, and the progress bar is driven by the byte ratio instead of stepping evenly per component — so the one large segment no longer makes the bar crawl and then sprint. The "part 2/6, block x/y" status text is unchanged.
>
> **Configure Devices** (`config-page.xml`, `app.css`): Back is now on the left and Save on the right. The white-on-white fields came from the app's unconditional `TextField { background-color: #ffffff }` colliding with the theme's `.ns-dark TextField { color: white }`; a new `.ns-dark TextField` rule gives dark fields with light text (placed before the `.system-name-modal` rule so that deliberately light modal still wins its tie).
>
> These are phone-UI changes verified by build and unit tests only — worth a quick visual pass on the dark-mode tablet, and the byte-weighted progress bar will only show its behavior during a real flash.
</details>
2026-08-24 00:16:20 -07:00
James BabcockandClaude Fable 5 b952cc2269 Handle coalesced envelope frames; trace truncated values (Samsung >64B issue)
Another developer reports Samsung devices truncating inbound notifications
larger than 64 bytes, and the missing-settings-reply issue indeed reproduces
only on the Samsung tablet. Every frame the tablet DID deliver was <=55 bytes;
a reply would only trip a 64-byte limit if it were bigger -- e.g. a fuller
first-reply snapshot, or a reply coalesced into one notification value with
one of the lens's own sid-0x80 notifies (11+55 = 66 bytes).

The coalescing case also exposed a latent app-side bug: parseFrame only ever
read the FIRST envelope in a notification value, so a second frame packed into
the same value was silently dropped even on healthy devices.

- BleProtocol.splitFrames(): split a notification value into its individual
  aa21/aa12 envelope frames (self-describing via the length byte), returning
  a trailing partial frame as-is so callers can log stack truncation.
- Device-info probe, flash-prompt communicator, and flasher control channel
  now process every frame in a value. The probe additionally logs multi-frame
  values (with the raw value size) and marks frames whose actual length falls
  short of the declared length as TRUNCATED, so the next tablet run can
  confirm whether the stack truncates or drops oversized values.

The existing first-request retries remain the workaround for replies the
Samsung stack drops outright. Known residual exposure, not addressed here:
the custom firmware's settings reply carries the capability string and is
well over 64 bytes in a single frame, so on affected Samsung devices the
main communicator would never see CFW capabilities; the durable fix is
firmware-side (chunk lens-to-phone notifications at <=64 bytes), since an
app cannot recover bytes the stack never delivers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
2026-08-23 19:47:57 -07:00
James BabcockandClaude Fable 5 3e440830a3 Flash prompt: retry the page-create once (2.2.9 post-prelude drop window)
The device-info frame trace settled the remaining firmware-check mystery: the
right lens is the correct settings endpoint, but on stock 2.2.9 a request
written immediately after the prelude ack is sometimes silently dropped while
the lens emits its own sid-0x80 notifications (flag 0x01, cmd 4, device-chosen
magic, result {f1:1}, ~2 s apart). The probe's retry answers within ~100 ms
every time, so the check now passes; the left-lens fallback never fired.

The flash-prompt page-create goes out at exactly the same post-prelude moment,
so give it the same single retry. Finding documented in
../notes/ble-connections-2.2.9.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
2026-08-23 17:32:15 -07:00
James BabcockandClaude Fable 5 a7684f603d Device-info probe: frame tracing, query retry, push acceptance, left-lens fallback
On stock 2.2.9 the settings read on the right lens goes unanswered even after
a successful security-auth exchange and fresh pairing. Since no 2.2.9-era
capture of a settings read exists (g2flash only exercises auth + OTA), turn
the probe into an experiment that a single on-device run can settle:

- Log every control-channel frame (sid/flag/type/magic/frag/payload prefix)
  and every write under the FaceclawDeviceInfo logcat tag.
- Retry the settings read once before concluding a lens is silent.
- Accept a sid-0x09 frame carrying firmware versions on the device's own
  magic (an unsolicited push) as an answer, not just the awaited ack.
- If the right lens stays silent, run the same connect/auth/prelude/read
  against the LEFT lens and use its answer, logging which lens replied, to
  test whether 2.2.9 moved the settings endpoint.

The probe now takes both arm addresses; the firmware-check page passes them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
2026-08-23 17:24:19 -07:00
James Babcock 33f06b9655 Fix up the first few pages of the onboarding flow 2026-08-23 16:52:34 -07:00
James BabcockandClaude Fable 5 1bde70aa45 Implement the 2.2.9 security-auth exchange on every stock-facing BLE connection
Firmware 2.2.9 requires the sid-0x80 DEVICE_SETTINGS/AUTHENTICATION(4)
exchange shortly after each GATT connection: it gates query responses on
completing it over an encrypted link, and closes unauthenticated links after
~30 s. On a phone with no existing bond (no inherited stock-app pairing) the
exchange is also what triggers SMP pairing. This is why the onboarding
firmware check failed with "no response to the device-info query" on a fresh
device: the probe connected, the prelude was acked, but the settings query was
never answered and no pairing ever happened. (See
../notes/ble-connections-2.2.9.md, validated by g2flash on hardware.)

- BleProtocol: buildAuthenticationRequest / isAuthenticationSuccess (strict:
  command 4, matching magic, empty result message), SID_SECURITY_AUTH.
- Device-info probe: authenticates before the prelude with a 30 s window (the
  user may need to accept an OS pairing prompt; the check page says so). Soft
  on non-response since the probe also runs against the custom firmware —
  but a query timeout after unconfirmed auth now names the pairing problem.
- Flash-prompt communicator: authenticates each arm before the prelude
  (mandatory — it only ever talks to stock firmware).
- Firmware flasher: control-channel notifications are now mandatory, each
  lens authenticates before OTA BEGIN, and the OTA-time heartbeat is gone —
  official captures show no control traffic during a transfer, heartbeats
  demonstrably do not satisfy the 2.2.9 deadline, and a concurrent control
  writer interleaves with the marker/data transactions. The OTA envelope
  counter now resets after bring-up, mirroring the stock sequence.
- Main communicator: authenticates both arms after connecting, before the
  prelude, with a short soft wait (logs and continues on timeout so firmware
  that never answers cannot stall reconnects).

Hardware test pending: fresh-device onboarding against stock 2.2.9 (check,
prompt, flash), and a regression pass on custom-firmware connect + probe.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
2026-08-23 16:19:16 -07:00
James BabcockandClaude Fable 5 17182532f4 Address review findings for the proximity-pairing PR
Correctness:
- Pair-glasses flows no longer strand the app in the manual-disconnected
  state: the pre-scan disconnect is followed by resumeAutoReconnect(), and
  the config page's scan hand-off drops the live link too.
- The mixed-arms serial warning is reachable now: pairs() groups by the
  canonical serial key, and a lone left + lone right with different serials
  get the mismatch warning on both rows (it previously required two
  different serials inside one serial-keyed group, which cannot happen).
- A selected pair that degrades to one arm (prune while the page is open)
  is deselected, and Save never pads a missing arm from stored addresses.
- DiscoveryAggregator.ingest no longer lets a bonded re-emit or split
  advertisement overwrite the note/name/flag learned from a full
  advertisement, and reclassifies split reports using remembered fields so
  a nameless half doesn't drop the arm.
- estimateProximity ignores the advertised TX Power Level (radiated power,
  not measured-power-at-1m); the calibration table is the only reference.
- Saving a ring without a glasses pair updates the stored identity's ring
  name/address instead of leaving the previous ring on record.
- Ring detection requires the stock "EVEN R1" name prefix in both the TS
  classifier and the Java pre-filter; a bare "R1" substring matched
  unrelated devices, and ring rows are always selectable.
- One-shot scans keep every sample (buildAddressSet merges them through
  DiscoveryAggregator), and flash-flow address resolution takes left/right
  from one serial-joined complete pair instead of latest-per-role.

Lifecycle:
- The pairing scan and its refresh timer pause on app suspend and resume
  with the app, and the model's app-event hooks are detached when the page
  is left for good.

Cleanup:
- One MAC normalizer (even-advertisement.normalizeMacAddress, re-exported
  by device-addresses), used for the ring "Yours" comparison too.
- One serial-equality definition (serialKey/serialsMatch); the containment
  fallback in isPreviouslyPaired is gone.
- Shared formatErrorMessage replaces five per-view-model copies; shared
  hex-util replaces the duplicate TS hex codecs; one Java bytesToHex in
  FaceclawFirmwareUtil replaces three hand-rolled encoders.
- glassesRow/ringRow share a presentation-base helper; dead row address
  fields, the constant glassesSectionVisibility, the identical-branch
  status ternary, and zoneRank/ZONE_ORDER are removed.
- .gitignore now actually covers .test-build/ as tests/README claims.

UI:
- Dark-mode styles for the pairing page: readable instructions, dark-gray
  cards with consistent light text; light mode keeps its current look.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
2026-08-23 15:28:59 -07:00
James Babcock ee022cdc84 Merge branch 'main' into bluetooth-pairing-improvements 2026-08-23 13:39:50 -07:00
Kalani Helekunihi 8fa04d1b46 Add Wear OS companion app and remote controls
Add a Wearable Data Layer bridge for syncing dashboard state and commands.

Introduce a standalone watch app with assistant, app launcher, touchpad remote, settings, and connectivity UI.
2026-08-23 15:02:35 -05:00
James Babcock 2b71eddab5 Optimize APK size
Removes unused keyword-spotting model. Makes on-device voice model a
runtime download rather than bundling it. Removes native-code library
versions for 32-bit and x86_64 processors.
2026-08-22 23:04:01 -07:00
James Babcock 69ec828cb7 Add release-build script; and bump version number to 0.5.0 2026-08-22 22:28:36 -07:00
Kalani Helekunihi aaaa7288ee Add proximity-based pairing for Even devices
Stream BLE advertisements into a dedicated pairing flow with arm, ring, serial, and hardware variant detection.

Add proximity ranking, device artwork, pairing safeguards, and unit coverage for discovery and candidate grouping.
2026-08-22 21:50:17 -05:00
James Babcock 0ed242a36f QR code loading works 2026-08-22 00:24:36 -07:00
James Babcock 5db6df93dd Merge branch 'main' into evenhub-from-qr 2026-08-21 23:55:08 -07:00
James Babcock 8ebfbb4fa6 Speed up connection/wake
Removes "image warmup", which was a workaround for a firmware bug that
no longer exists (even in stock, I think).
2026-08-21 22:58:44 -07:00
James Babcock 92cd05b6ca Add options to load an app from a URL or a QR code
(The QR code reading does not work yet)
2026-08-21 12:03:24 -07:00
James Babcock 6e4ece5dc7 Brightness-correct and dither music player album art images 2026-08-21 10:54:25 -07:00
James Babcock 8cdee2a701 HTTP requests identify Faceclaw in their user-agent string 2026-08-20 11:32:50 -07:00
James Babcock 33b669ed41 Remove a stray merge conflict marker 2026-08-20 09:07:15 -07:00
James Babcock 0c0fc7d7f6 Merge branch 'evenhub-compatibility' 2026-08-20 08:46:47 -07:00
James Babcock f6035ea9ec Performance optimizations 2026-08-20 02:46:03 -07:00
James Babcock 96842ceb23 Use TTF fonts throughout the UI; also add some more functions to app extension API 2026-08-19 19:35:24 -07:00
James Babcock 90603b5aa4 Use the texture cache and builtin-font drawing firmware extensions 2026-08-19 10:36:16 -07:00
James Babcock 83e0fa919f Use the texture cache to avoid resending icons and font glyphs 2026-08-18 23:39:21 -07:00
James Babcock 526a236193 Display link to EvenHub apps' privacy policy on first run 2026-08-16 22:33:04 -07:00
James Babcock 6a9743d27c Fix an overly-strict validation firmware validatio
The flasher was validating that there are exactly 5 firmware segments
(which was true of 2.2.4 but not 2.2.6), causing it to reject the stock
firmware in the uninstall flow.

(This doesn't actually prevent uninstalling as you can still use the
stock Android app's OTA updater.)
2026-08-16 21:01:21 -07:00
James Babcock dcf35dd606 Fix issue with EvenHub apps freezing when not foregrounded on the phone 2026-08-16 21:01:20 -07:00
James Babcock b6785e5a5a Send cleanup messages on disconnect 2026-08-16 21:01:20 -07:00
James Babcock 5cd61da362 Virtualize timers in app webviews 2026-08-16 21:01:20 -07:00
James Babcock 1d00849eb2 Add font viewer 2026-08-16 21:01:17 -07:00
James Babcock b9f48c8e16 Allow backgrounding EvenHub apps 2026-08-16 20:59:42 -07:00
James Babcock 812c3f9b4a Add font viewer 2026-08-13 00:38:19 -07:00
James Babcock 5d29d91133 First-pass EvenHub compatibility layer 2026-08-11 22:52:32 -07:00
James Babcock 6f45888627 Add support for a local model (Qwen3) 2026-08-09 23:52:21 -07:00
James Babcock 9ade3503a0 Add a resource-usage monitor to debug app; fix excessive memory-usage from screen preview when not focused 2026-08-07 02:21:24 -07:00
James Babcock 2cfe511efb Ensure magnetometer compass is off when in suspend/sleep
<details>
<summary>Prompts Used</summary>
We recently added a magnetometer/compass app. I notice that, when I left it open, battery life was shorter (similar to what it was before we implemented screen-off powersave mode support). Let's ensure that we turn off magnetometer option off when turning the screen off.
</details>
2026-08-04 20:35:55 -07:00
James Babcock ba81e46624 Add Soniox as an API speech-to-text option 2026-08-04 20:15:39 -07:00
James Babcock 852626e950 Add a compass using the G2's magnetometer 2026-08-04 02:09:32 -07:00
James Babcock 1ec6b3ff83 Crop screenshots 2026-08-02 19:36:16 -07:00
James Babcock 960e2fd6e1 Add a lock screen, controlled by wear-detection 2026-08-02 15:38:07 -07:00
James Babcock 4302a506d4 On-device voice model: Normalize before input, place boundary cuts at silence
These changes hopefully improve transcription accuracy with the
on-device model
2026-08-02 02:43:53 -07:00
James Babcock 02c09ef889 Fix broken wakeword handling 2026-08-01 14:37:30 -07:00
James Babcock 6d42f0e65e Expand screen resolution to the full 640x480 2026-07-31 12:57:10 -07:00