forked from Blendman974/faceclaw
Flashing uses 2.2.9 as base version
This commit is contained in:
1 parent
c7d4e7a630
commit
76825f68a7
8 files changed
+324
-91
No files matched your search
@@ -254,8 +254,15 @@ function buildCommon(version: 1 | 3): string {
|
||||
const fields: Record<string, string | number> = {
|
||||
platform: "16",
|
||||
package: "com.even.sg",
|
||||
versionName: "2.2.6",
|
||||
build: "114",
|
||||
// versionName/build must be a real shipped pair of the official Android
|
||||
// app (versionName/versionCode from its manifest): 2.2.8 = versionCode 122
|
||||
// (captures/even-2.2.8-base.apk). Earlier this said 2.2.6 with build 114,
|
||||
// but 114 was actually 2.2.4's versionCode (see notes/firmware-download.md).
|
||||
// buildTime is not a literal in the app binary (computed at runtime), so
|
||||
// it still carries the value from the 2.2.4 capture; the API has accepted
|
||||
// the mismatch so far.
|
||||
versionName: "2.2.8",
|
||||
build: "122",
|
||||
brand: "Google",
|
||||
model: "Pixel 7a",
|
||||
osVersion: "16",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Builds the Faceclaw custom firmware on-device: downloads the stock Even
|
||||
* Realities G2 2.2.6.10 image from Even's CDN, verifies its SHA-256, applies
|
||||
* Realities G2 image the patch set was built against (CFW_PATCH_SET.base,
|
||||
* currently 2.2.9.22) from Even's CDN, verifies its SHA-256, applies
|
||||
* the committed byte-patch set (cfw-patches.ts), extracts the stock EvenHub
|
||||
* fonts for phone-side rendering, verifies the patched SHA-256, and writes the
|
||||
* result to app storage.
|
||||
@@ -24,9 +25,15 @@ import { EvenHubFont } from "../graphics/evenhub-font";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
const FIRMWARE_URL = "https://cdn.evenreal.co/firmware/e28738432d7b612d625331b00383149b.bin";
|
||||
const CFW_OUTPUT_FILENAME = "g2_2.2.6.10_cfw.bin";
|
||||
const STOCK_OUTPUT_FILENAME = "g2_2.2.6.10.bin";
|
||||
// The CDN names firmware files by MD5. This must be the image whose SHA-256 is
|
||||
// CFW_PATCH_SET.baseSha256 — keep it in sync with FW_URL in g2flash/build_cfw.sh
|
||||
// whenever cfw-patches.ts is regenerated against a new stock base.
|
||||
// (2.2.9.22 = fc250b05…; the older 2.2.6.10 base was e2873843….)
|
||||
const FIRMWARE_URL = "https://cdn.evenreal.co/firmware/fc250b05e98a9ff998b4b68f5f99f994.bin";
|
||||
// Output names follow the patch set's base name (e.g. g2_2.2.9.22.bin →
|
||||
// g2_2.2.9.22_cfw.bin) so a rebase can't leave stale version numbers here.
|
||||
const STOCK_OUTPUT_FILENAME = CFW_PATCH_SET.base;
|
||||
const CFW_OUTPUT_FILENAME = CFW_PATCH_SET.base.replace(/\.bin$/, "") + "_cfw.bin";
|
||||
|
||||
export type FirmwareProgress =
|
||||
| { phase: "downloading" }
|
||||
|
||||
@@ -21,10 +21,16 @@ type FontSpec = {
|
||||
};
|
||||
|
||||
// Priority order is the stock EvenHub fallback chain (before the CJK font).
|
||||
// These are lv_font_fmt_txt_dsc_t addresses in the stock image the patch set
|
||||
// is built against (CFW_PATCH_SET.base), so they move on every firmware
|
||||
// rebase: run scripts/find-firmware-fonts.py against the new stock .bin and
|
||||
// match rows by cmap count / code-point count (12/8081, 9/9566, 4/11590).
|
||||
// 2.2.9.22: 0x007a8954, 0x007a8968, 0x007a8878
|
||||
// 2.2.6.10: 0x0077f414, 0x0077f428, 0x0077f374
|
||||
const FONT_SPECS: FontSpec[] = [
|
||||
{ descriptor: 0x0077f414, lineHeight: 27, baseLine: 5 },
|
||||
{ descriptor: 0x0077f428, lineHeight: 26, baseLine: 5 },
|
||||
{ descriptor: 0x0077f374, lineHeight: 20, baseLine: 2 },
|
||||
{ descriptor: 0x007a8954, lineHeight: 27, baseLine: 5 },
|
||||
{ descriptor: 0x007a8968, lineHeight: 26, baseLine: 5 },
|
||||
{ descriptor: 0x007a8878, lineHeight: 20, baseLine: 2 },
|
||||
];
|
||||
|
||||
type ExtractedGlyph = {
|
||||
|
||||
@@ -6,20 +6,32 @@ export type FlashPromptState =
|
||||
| "connecting"
|
||||
| "connected"
|
||||
| "prompting"
|
||||
| "battery"
|
||||
| "result"
|
||||
| "cancelled"
|
||||
| "timeout"
|
||||
| "disconnected"
|
||||
| "error";
|
||||
|
||||
/** Per-arm battery percent; null when that arm didn't answer. */
|
||||
export type FlashPromptBattery = { right: number | null; left: number | null };
|
||||
|
||||
function normalizePercent(value: number): number | null {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) && n >= 0 ? n : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* TS wrapper around the native FaceclawFlashPromptCommunicator — the
|
||||
* stock-firmware-compatible BLE path that shows the pre-flash confirmation on
|
||||
* the glasses and reports the user's Yes/No choice. Separate from
|
||||
* FaceclawCommunicatorBridge on purpose (different, minimal protocol subset).
|
||||
*
|
||||
* Talks to the right arm only: the lenses relay messages between themselves,
|
||||
* and acks/events always come from the right arm.
|
||||
* Connects and authenticates both arms (so any OS pairing prompts happen up
|
||||
* front, before flashing), shows the prompt via the right arm (the lenses relay
|
||||
* messages between themselves, and acks/events always come from the right
|
||||
* arm), then reads each arm's battery. With `skipPrompt` the on-glasses
|
||||
* confirmation is omitted and only the battery is read.
|
||||
*/
|
||||
export class FlashPromptCommunicator {
|
||||
private readonly communicator: any;
|
||||
@@ -27,20 +39,32 @@ export class FlashPromptCommunicator {
|
||||
private readonly logListeners = new Set<(line: string) => void>();
|
||||
private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>();
|
||||
private readonly resultListeners = new Set<(approved: boolean) => void>();
|
||||
private readonly batteryListeners = new Set<(battery: FlashPromptBattery) => void>();
|
||||
|
||||
constructor(rightAddress: string, warningText: string) {
|
||||
constructor(
|
||||
addresses: { right: string; left: string },
|
||||
warningText: string,
|
||||
options?: { skipPrompt?: boolean },
|
||||
) {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
if (!context) throw new Error("Android application context unavailable");
|
||||
|
||||
this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator(
|
||||
context,
|
||||
rightAddress,
|
||||
addresses.right,
|
||||
addresses.left,
|
||||
warningText,
|
||||
Boolean(options?.skipPrompt),
|
||||
);
|
||||
this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({
|
||||
onLog: (line: string) => this.emit(this.logListeners, String(line)),
|
||||
onState: (state: string, detail: string) =>
|
||||
this.emit(this.stateListeners, String(state) as FlashPromptState, String(detail ?? "")),
|
||||
onBattery: (rightPercent: number, leftPercent: number) =>
|
||||
this.emit(this.batteryListeners, {
|
||||
right: normalizePercent(rightPercent),
|
||||
left: normalizePercent(leftPercent),
|
||||
}),
|
||||
onResult: (approved: boolean) => this.emit(this.resultListeners, Boolean(approved)),
|
||||
});
|
||||
this.communicator.setListener(this.listenerProxy);
|
||||
@@ -56,6 +80,11 @@ export class FlashPromptCommunicator {
|
||||
return () => this.stateListeners.delete(listener);
|
||||
}
|
||||
|
||||
onBattery(listener: (battery: FlashPromptBattery) => void): () => void {
|
||||
this.batteryListeners.add(listener);
|
||||
return () => this.batteryListeners.delete(listener);
|
||||
}
|
||||
|
||||
onResult(listener: (approved: boolean) => void): () => void {
|
||||
this.resultListeners.add(listener);
|
||||
return () => this.resultListeners.delete(listener);
|
||||
|
||||
@@ -14,7 +14,11 @@ import {
|
||||
} from "../g2/firmware-builder";
|
||||
import { buildAddressSet, DeviceDiscoveryBridge } from "../native/device-discovery";
|
||||
import { FirmwareFlasher, FlashProgress, FlashState } from "../native/firmware-flasher";
|
||||
import { FlashPromptCommunicator, FlashPromptState } from "../native/flash-prompt-communicator";
|
||||
import {
|
||||
FlashPromptBattery,
|
||||
FlashPromptCommunicator,
|
||||
FlashPromptState,
|
||||
} from "../native/flash-prompt-communicator";
|
||||
import { resumeAutoReconnect, suppressAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
@@ -23,6 +27,10 @@ type FlashPhase = "intro" | "prompt" | "building" | "ready" | "flashing" | "flas
|
||||
|
||||
export type FlashMode = "install" | "uninstall";
|
||||
|
||||
// Flashing a lens takes minutes and the glasses reboot afterwards; refuse to
|
||||
// start when either arm is below this so a flat battery can't interrupt it.
|
||||
const MIN_FLASH_BATTERY_PERCENT = 30;
|
||||
|
||||
export class OnboardingFlashViewModel extends Observable {
|
||||
private readonly mode: FlashMode;
|
||||
private readonly fromOnboarding: boolean;
|
||||
@@ -40,6 +48,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
|
||||
private prompt: FlashPromptCommunicator | null = null;
|
||||
private promptUnsubscribers: Array<() => void> = [];
|
||||
private promptBattery: FlashPromptBattery | null = null;
|
||||
private flasher: FirmwareFlasher | null = null;
|
||||
private flasherUnsubscribers: Array<() => void> = [];
|
||||
private retryAction: () => void = () => this.beginPrompt();
|
||||
@@ -55,10 +64,10 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
this._headline = this.mode === "uninstall" ? "Uninstall Custom Firmware" : "Flash Custom Firmware";
|
||||
this._status =
|
||||
this.mode === "uninstall"
|
||||
? "This connects to your glasses, asks for confirmation on the lens, then downloads and reflashes the " +
|
||||
"official firmware — removing Faceclaw's custom features."
|
||||
: "This connects to your glasses, asks for confirmation on the lens, then downloads, verifies, and flashes " +
|
||||
"Faceclaw's custom firmware.";
|
||||
? "This connects to your glasses, asks for confirmation on the lens, checks the battery, then downloads " +
|
||||
"and reflashes the official firmware — removing Faceclaw's custom features."
|
||||
: "This connects to your glasses, asks for confirmation on the lens, checks the battery, then downloads, " +
|
||||
"verifies, and flashes Faceclaw's custom firmware.";
|
||||
}
|
||||
|
||||
// Kept short to fit the glasses' ~50-column text grid.
|
||||
@@ -219,15 +228,24 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
|
||||
// --- prompt flow -----------------------------------------------------------
|
||||
|
||||
private async beginPrompt(): Promise<void> {
|
||||
/**
|
||||
* Connect to both arms, authenticate (this is where any Android pairing
|
||||
* prompts appear), show the Yes/No confirmation on the lens, then read the
|
||||
* battery. With `skipPrompt` (retrying after a low-battery refusal, when
|
||||
* the user has already confirmed) the on-glasses confirmation is skipped
|
||||
* and only the battery is re-checked.
|
||||
*/
|
||||
private async beginPrompt(options?: { skipPrompt?: boolean }): Promise<void> {
|
||||
const skipPrompt = Boolean(options?.skipPrompt);
|
||||
if (!global.isAndroid) {
|
||||
this.toError("Flashing is only available on Android.", () => this.beginPrompt());
|
||||
this.toError("Flashing is only available on Android.", () => this.beginPrompt(options));
|
||||
return;
|
||||
}
|
||||
this.setPhase("prompt");
|
||||
this.headline = "Confirm On Your Glasses";
|
||||
this.headline = skipPrompt ? "Checking Battery" : "Confirm On Your Glasses";
|
||||
this.log = "";
|
||||
this.busy = true;
|
||||
this.promptBattery = null;
|
||||
this.status = "Preparing to connect. Make sure your glasses are on and the Even app is disconnected.";
|
||||
|
||||
try {
|
||||
@@ -237,40 +255,50 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
this.busy = false;
|
||||
this.toError(
|
||||
"Couldn't find both glasses arms. Make sure the glasses are powered on and the Even app is disconnected, then retry.",
|
||||
() => this.beginPrompt(),
|
||||
() => this.beginPrompt(options),
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.addresses = addresses;
|
||||
|
||||
this.status = "Connecting to your glasses. Watch the lens for a Yes/No prompt.";
|
||||
this.startCommunicator(addresses);
|
||||
this.status = skipPrompt
|
||||
? "Connecting to your glasses to re-check the battery..."
|
||||
: "Connecting to your glasses. Watch the lens for a Yes/No prompt.";
|
||||
this.startCommunicator(addresses, skipPrompt);
|
||||
} catch (error) {
|
||||
this.busy = false;
|
||||
this.toError(this.formatError(error), () => this.beginPrompt());
|
||||
this.toError(this.formatError(error), () => this.beginPrompt(options));
|
||||
}
|
||||
}
|
||||
|
||||
private startCommunicator(addresses: { right: string; left: string }): void {
|
||||
private startCommunicator(addresses: { right: string; left: string }, skipPrompt: boolean): void {
|
||||
this.disposePrompt();
|
||||
const prompt = new FlashPromptCommunicator(addresses.right, this.glassesWarning);
|
||||
const prompt = new FlashPromptCommunicator(addresses, this.glassesWarning, { skipPrompt });
|
||||
this.prompt = prompt;
|
||||
|
||||
this.promptUnsubscribers.push(
|
||||
prompt.onLog((line) => this.appendLog(line)),
|
||||
prompt.onStateChange((state, detail) => this.handlePromptState(state, detail)),
|
||||
prompt.onResult((approved) => this.handlePromptResult(approved)),
|
||||
prompt.onStateChange((state, detail) => this.handlePromptState(state, detail, skipPrompt)),
|
||||
prompt.onBattery((battery) => {
|
||||
this.promptBattery = battery;
|
||||
}),
|
||||
prompt.onResult((approved) => this.handlePromptResult(approved, skipPrompt)),
|
||||
);
|
||||
prompt.start();
|
||||
}
|
||||
|
||||
private handlePromptState(state: FlashPromptState, detail: string): void {
|
||||
private handlePromptState(state: FlashPromptState, detail: string, skipPrompt: boolean): void {
|
||||
switch (state) {
|
||||
case "connecting":
|
||||
this.status = "Connecting to your glasses...";
|
||||
break;
|
||||
case "connected":
|
||||
this.status = "Connected. Showing the confirmation on the lens...";
|
||||
this.status =
|
||||
"Connected. Pairing with both lenses — if Android asks to pair, accept it (once per lens)." +
|
||||
(skipPrompt ? "" : " Then watch the lens for the confirmation.");
|
||||
break;
|
||||
case "battery":
|
||||
this.status = "Checking the glasses' battery level...";
|
||||
break;
|
||||
case "prompting":
|
||||
this.status =
|
||||
@@ -289,25 +317,57 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
break;
|
||||
case "disconnected":
|
||||
this.busy = false;
|
||||
this.toError(detail || "Lost connection to the glasses.", () => this.beginPrompt());
|
||||
this.toError(detail || "Lost connection to the glasses.", () => this.beginPrompt({ skipPrompt }));
|
||||
break;
|
||||
case "error":
|
||||
this.busy = false;
|
||||
this.toError(detail || "Connection failed.", () => this.beginPrompt());
|
||||
this.toError(detail || "Connection failed.", () => this.beginPrompt({ skipPrompt }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private handlePromptResult(approved: boolean): void {
|
||||
private handlePromptResult(approved: boolean, skipPrompt: boolean): void {
|
||||
this.disposePrompt();
|
||||
if (!approved) {
|
||||
this.busy = false;
|
||||
this.toError("You declined on the glasses. No firmware was written.", () => this.beginPrompt());
|
||||
return;
|
||||
}
|
||||
const lowBattery = this.describeLowBattery(this.promptBattery);
|
||||
if (lowBattery) {
|
||||
this.busy = false;
|
||||
// The user already confirmed on the lens; a retry only re-checks the battery.
|
||||
this.toError(lowBattery, () => this.beginPrompt({ skipPrompt: true }), "Charge Your Glasses");
|
||||
return;
|
||||
}
|
||||
if (!this.promptBattery || (this.promptBattery.right === null && this.promptBattery.left === null)) {
|
||||
this.appendLog("battery level unknown; proceeding");
|
||||
}
|
||||
this.appendLog(skipPrompt ? "battery ok; confirmed earlier on the lens" : "confirmed on the lens; battery ok");
|
||||
void this.buildFirmware();
|
||||
}
|
||||
|
||||
/** A "charge first" message when either arm is below the flashing threshold, else null. */
|
||||
private describeLowBattery(battery: FlashPromptBattery | null): string | null {
|
||||
if (!battery) {
|
||||
return null;
|
||||
}
|
||||
const readings = [
|
||||
{ arm: "right", percent: battery.right },
|
||||
{ arm: "left", percent: battery.left },
|
||||
].filter((r): r is { arm: string; percent: number } => r.percent !== null);
|
||||
const low = readings.filter((r) => r.percent < MIN_FLASH_BATTERY_PERCENT);
|
||||
if (low.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const levels = readings.map((r) => `${r.arm} ${r.percent}%`).join(", ");
|
||||
return (
|
||||
`The glasses' battery is too low to flash safely (${levels}). ` +
|
||||
`Charge both lenses to at least ${MIN_FLASH_BATTERY_PERCENT}%, then tap Retry to check again. ` +
|
||||
"You won't need to confirm on the lens a second time."
|
||||
);
|
||||
}
|
||||
|
||||
private cancelPrompt(): void {
|
||||
this.status = "Cancelling...";
|
||||
try {
|
||||
@@ -502,11 +562,11 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
});
|
||||
}
|
||||
|
||||
private toError(message: string, retry: () => void): void {
|
||||
private toError(message: string, retry: () => void, headline = "Something Went Wrong"): void {
|
||||
this.retryAction = retry;
|
||||
this.status = message;
|
||||
this.setPhase("error");
|
||||
this.headline = "Something Went Wrong";
|
||||
this.headline = headline;
|
||||
}
|
||||
|
||||
private setPhase(phase: FlashPhase): void {
|
||||
|
||||
Reference in new issue
Block a user