Refuse the flash with a reason when the glasses are in silent mode

Silent mode blanks the display and stops the firmware dispatching input while
BLE and GATT stay up, so the create-prompt page is written, accepted, and never
rendered. There is no touchpad event available to answer it with, and the flash
ends after four attempts on "prompt page not acked", which tells the wearer
nothing about what is wrong or what to do about it.

readBattery was already performing a sid-0x09 settings read whose ack carries
silentMode next to the battery, and the field was being discarded. readSettings
is factored out so one read serves both callers, and requireNotSilent runs it
before the prompt page is written. A positive report throws, and the existing
error path turns the message into what the wearer sees: that the glasses are in
silent mode, and that long-pressing both touchpads leaves it.

It refuses only on a positive report. An arm that does not answer, and firmware
whose ack omits the field, both fall through to the prompt exactly as before, so
older firmware is unaffected and a missing answer can never block a flash.

This replaces the phone-side confirmation fallback that was here before. An
unacked page is not by itself evidence that the prompt was never displayed, and
the on-lens step is what proves the glasses being flashed are the ones in front
of you, so overriding it on a timeout gave up more than it was worth.
This commit is contained in:
JMO committed 2026-09-23 08:12:19 -07:00
1 parent a7916a5479
commit 423f9fbcd1
3 files changed
+55 -95

No files matched your search

@@ -51,6 +51,15 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
// Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid.
private static final String[] ITEMS = new String[] {"No, cancel", "Yes, flash"};
/**
* Shown instead of a bare "prompt page not acked" timeout. Silent mode is
* entered and left by the same gesture on the glasses and nothing here can
* clear it, so the instruction has to travel with the error.
*/
private static final String SILENT_MODE_MESSAGE =
"Your glasses are in silent mode, so they cannot show the confirmation prompt. "
+ "Long-press both touchpads on the glasses to leave silent mode, then try again.";
private static final int HEARTBEAT_INTERVAL_MS = 4_000;
private static final int SELECTION_TIMEOUT_MS = 120_000;
private static final int CREATE_ACK_TIMEOUT_MS = 3_000;
@@ -183,6 +192,12 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
sendPrelude(rightAddress);
if (!skipPrompt) {
// Ask before writing a page that cannot be answered: silent mode
// blanks the display and stops the firmware dispatching input while
// BLE stays up, so the create-prompt write is still accepted and the
// flash would spend four attempts timing out on an error that says
// nothing about the reason.
requireNotSilent(rightAddress);
showPrompt(rightAddress);
startHeartbeat();
emitState("prompting", "");
@@ -376,6 +391,18 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
}
private int readBattery(String address, String arm) throws InterruptedException {
BleProtocol.BatterySnapshot snapshot = readSettings(address, arm);
return snapshot == null ? -1 : snapshot.battery;
}
/**
* The sid-0x09 settings read behind both the battery gate and the
* silent-mode check. One ack carries both fields, so neither caller needs
* a query of its own. Returns null when the arm does not answer or the ack
* carries no settings payload.
*/
private BleProtocol.BatterySnapshot readSettings(String address, String arm)
throws InterruptedException {
for (int attempt = 0; attempt < 2 && !cancelled; attempt++) {
int magic = allocMagic();
byte[] ack = writeAndAwaitAck(
@@ -386,16 +413,38 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
BleProtocol.buildSettingsQuery(magic),
BATTERY_ACK_TIMEOUT_MS);
if (ack == null) {
emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm");
emitLog("settings read attempt " + (attempt + 1) + " unacked: " + arm + " arm");
continue;
}
BleProtocol.BatterySnapshot snapshot = BleProtocol.parseSettingsBattery(ack);
if (snapshot != null) {
return snapshot.battery;
return snapshot;
}
emitLog("battery read ack had no battery field: " + arm + " arm");
emitLog("settings read ack had no settings payload: " + arm + " arm");
}
return null;
}
/**
* Refuse the prompt only when the arm POSITIVELY reports silent mode. An
* arm that does not answer, and firmware whose ack omits the field
* (silentMode -1), both fall through to the prompt, so behavior on older
* firmware is unchanged and a missing answer never blocks a flash.
*/
private void requireNotSilent(String address) throws InterruptedException {
BleProtocol.BatterySnapshot snapshot = readSettings(address, "right");
String state;
if (snapshot == null) {
state = "unknown (arm did not answer)";
} else if (snapshot.silentMode < 0) {
state = "unknown (ack omits the field)";
} else {
state = snapshot.silentMode > 0 ? "on" : "off";
}
emitLog("silent mode before prompt: " + state);
if (snapshot != null && snapshot.silentMode > 0) {
throw new IllegalStateException(SILENT_MODE_MESSAGE);
}
return -1;
}
/** Write and wait for the matching ack; returns the ack's protobuf (may be empty), or null on timeout/write failure. */
+2 -29
View File
@@ -56,8 +56,6 @@ export class OnboardingFlashViewModel extends Observable {
private flasher: FirmwareFlasher | null = null;
private flasherUnsubscribers: Array<() => void> = [];
private retryAction: () => void = () => this.beginPrompt();
/** Overrides the error screen's "Retry" when the action is not a retry. */
private primaryLabelOverride: string | null = null;
constructor(options?: { mode?: FlashMode; fromOnboarding?: boolean; autoStart?: boolean }) {
super();
@@ -176,7 +174,7 @@ export class OnboardingFlashViewModel extends Observable {
case "flashed":
return "Finish";
case "error":
return this.primaryLabelOverride ?? "Retry";
return "Retry";
default:
return "";
}
@@ -331,25 +329,6 @@ export class OnboardingFlashViewModel extends Observable {
break;
case "error":
this.busy = false;
// An unacked prompt page is not a connection failure. The lens accepts the
// write at the GATT layer and then never answers, which is what firmware
// older than the revision this build needs does -- measured on revision 13,
// four writes accepted with status 0 and no reply, nothing shown on the lens.
// Flashing is the only way OFF that firmware, so failing here leaves the
// glasses permanently unupgradable. Fall back to the phone-side confirmation
// that the low-battery retry already uses, and say plainly what is being
// given up: the on-lens step is what proves these are the wearer's glasses.
if (/prompt page not acked/i.test(detail)) {
this.toError(
"Your glasses are on older firmware that can't show the confirmation prompt, so it can't be " +
"confirmed on the lens. You can confirm here instead. Only continue if these are your glasses " +
"and you want to install Faceclaw's custom firmware.",
() => this.beginPrompt({ skipPrompt: true }),
"Confirm On Your Phone",
"Confirm & Install",
);
break;
}
this.toError(detail || "Connection failed.", () => this.beginPrompt({ skipPrompt }));
break;
}
@@ -590,13 +569,7 @@ export class OnboardingFlashViewModel extends Observable {
});
}
private toError(
message: string,
retry: () => void,
headline = "Something Went Wrong",
primaryLabel: string | null = null,
): void {
this.primaryLabelOverride = primaryLabel;
private toError(message: string, retry: () => void, headline = "Something Went Wrong"): void {
this.retryAction = retry;
this.status = message;
this.setPhase("error");
-62
View File
@@ -1,62 +0,0 @@
// The flash cannot always ask for confirmation on the lens: firmware older than
// the revision this build needs accepts the create-prompt write and then never
// answers it. Flashing is the only way off that firmware, so an unacked prompt
// must not be a dead end. These cover the decision at that seam.
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function fixture() {
class Observable { notifyPropertyChange() {} }
const load = loader({}, {
'@nativescript/core': { Observable, Frame: { topmost: () => null } },
'./onboarding-navigation': { finishOnboardingNavigation() {} },
'./onboarding-state': { setOnboardingCompleted() {}, setPreviewOnlyMode() {} },
'../native/ble-permissions': { ensureBlePermissions: async () => {} },
'../g2/device-addresses': {
isValidMacAddress: () => true,
loadDeviceAddresses: () => ({ right: 'R', left: 'L' }),
saveDeviceAddresses() {},
},
'../g2/firmware-builder': {
buildCustomFirmware: async () => '', buildStockFirmware: async () => '',
FirmwareBuildError: class extends Error {}, FirmwareProgress: {},
},
'../native/device-discovery': { buildAddressSet: () => new Set(), DeviceDiscoveryBridge: class {} },
'../native/firmware-flasher': { FirmwareFlasher: class {} },
'../native/flash-prompt-communicator': { FlashPromptCommunicator: class {} },
'../g2/reconnect-policy': { resumeAutoReconnect() {}, suppressAutoReconnect() {} },
'../util/format-error': { formatErrorMessage: (e) => String(e) },
});
const mod = load('app/phone-ui/onboarding-flash-view-model.ts');
const Model = mod.OnboardingFlashViewModel ?? Object.values(mod).find((v) => typeof v === 'function');
const model = new Model();
const beginArgs = [];
model.beginPrompt = async (options) => { beginArgs.push(options); };
return { model, beginArgs };
}
test('an unacked prompt page offers the phone-side confirmation instead of dead-ending', () => {
const { model, beginArgs } = fixture();
model.handlePromptState('error', 'prompt page not acked: AA:BB:CC:DD:EE:FF', false);
assert.equal(model.phase, 'error');
assert.equal(model.headline, 'Confirm On Your Phone');
assert.equal(model.primaryLabel, 'Confirm & Install', 'the action is a confirmation, not a retry');
assert.match(model.status, /can't show the confirmation prompt/i);
model.retryAction();
// The loader runs the module in its own vm realm, so the options object has that
// realm's prototype and deepStrictEqual would reject it. Compare the field.
assert.equal(beginArgs.length, 1);
assert.equal(beginArgs[0].skipPrompt, true, 'confirming must skip the lens prompt, not re-ask for it');
});
test('any other prompt failure still reports as an ordinary retry', () => {
const { model, beginArgs } = fixture();
model.handlePromptState('error', 'discoverServices failed: right arm', false);
assert.equal(model.phase, 'error');
assert.equal(model.headline, 'Something Went Wrong');
assert.equal(model.primaryLabel, 'Retry');
model.retryAction();
assert.equal(beginArgs.length, 1);
assert.equal(beginArgs[0].skipPrompt, false, 'an ordinary failure must not silently skip the lens prompt');
});