Add (NOT YET TESTED) firmware flashing/OTA-updating

We're going to extend the Faceclaw app onboarding process to include checking for and installing the custom firmware (currently handled externally with the scripts in ../g2flash). We'll add script scripts/resetOnboarding.sh that uses adb to reset the app on the attached phone to default/pre-onboarding state for testing. The onboarding process will explain that it's only compatible with custom firmware, with options to either skip and try out the app using only the phone-screen preview (instead of pairing with glasses), or proceed with flashing.
If the user proceeds with flashing, we first connect to the glasses (with the existing mechanism), and display an on-glasses confirmation prompt. Because this prompt needs compatibility with stock firmware, it will use a different subset of the BLE protocol than the main app does (in particular, no image containers), so we'll have a separate bluetooth communication class rather than extending FaceclawBleCommunicator. We'll send an init message to start a Hub app, initialize a layout with a text container and a list, populate the text container with a message saying that flashing will void warranty and the list with No and Yes, set up a keepalive/heartbeat message timer, and wait for a menu selection. (Refer to ../g2-kit-unofficial/ble/docs and ../g2-kit-unofficial/ble/gen for protocol details). If the prompt is approved, we go to the flashing screen.
On the flashing screen, we first download the official firmware, apply patches to it, and check that it has the expected result hash. See ../g2flash/build_cfw.sh and ../g2flash/apply_patches.py for details.
Let's implement everything prior to the update itself now, ie, the on-device confirmation prompt, and downloading, patching and verifying the modded firmware.
scripts/resetOnboarding.sh is meant to reset a pref so that Faceclaw reruns its first-run onboarding on next launch, but fails with "No onboarding keys were set. App is already in pre-onboarding state." (And onboarding doesn't trigger on next launch)
Thanks. I tested the on-glasses prompt on real hardware and it worked as expected. Next up, let's port the flashing procedure itself.
One detail of the flashing procedure worth noting: the two lenses get updated separately, and at the end of updating either lens, both lenses get rebooted, creating a brief period when neither is reachable, so the timeout to look for the second lens should not be too short.
This commit is contained in:
James Babcock committed 2026-07-10 12:07:15 -07:00
1 parent 2c04d99dfb
commit cb78841a9d
17 files changed
+2464 -10

No files matched your search

+108
View File
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
#
# resetOnboarding.sh — reset Faceclaw on an attached phone back to its
# pre-onboarding state, for testing the onboarding flow repeatedly.
#
# By default this only clears the onboarding-related preference keys
# (onboarding.complete, onboarding.previewOnly, ...) and leaves everything
# else — notably the saved glasses/ring MAC addresses — intact, so you don't
# have to re-scan devices on every test pass. Pass --all to wipe ALL app data
# (a true fresh-install state, addresses included).
#
# Usage:
# scripts/resetOnboarding.sh # reset onboarding flags only
# scripts/resetOnboarding.sh --all # full `pm clear` (wipes everything)
# scripts/resetOnboarding.sh -s <device-id> # target a specific adb device
#
# The device id defaults to $FACECLAW_DEVICE_ID, then to the id used by
# build_and_run.sh. adb is located the same way build.sh finds its tools.
set -euo pipefail
PACKAGE="com.faceclaw.app"
PREF_KEY_PREFIX="onboarding."
DEVICE_ID="${FACECLAW_DEVICE_ID:-3A101JEHN12330}"
WIPE_ALL=0
# Match build.sh's tool locations so adb is on PATH even from a bare shell.
export ANDROID_HOME="${ANDROID_HOME:-/Users/jbabcock/Library/Android/sdk}"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
while [ $# -gt 0 ]; do
case "$1" in
--all) WIPE_ALL=1; shift ;;
-s|--device) DEVICE_ID="$2"; shift 2 ;;
-h|--help)
sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
exit 0 ;;
*)
echo "unknown option: $1 (try --help)" >&2
exit 2 ;;
esac
done
command -v adb >/dev/null 2>&1 || { echo "error: adb not found on PATH" >&2; exit 1; }
ADB="adb -s $DEVICE_ID"
# Confirm the device is actually there before doing anything.
if ! $ADB get-state >/dev/null 2>&1; then
echo "error: adb device '$DEVICE_ID' not connected." >&2
echo " Connected devices:" >&2
adb devices -l | sed '1d' >&2
exit 1
fi
if [ "$WIPE_ALL" -eq 1 ]; then
echo "Wiping ALL app data for $PACKAGE (fresh-install state)..."
$ADB shell pm clear "$PACKAGE"
echo "Done. The next launch starts from a clean onboarding."
exit 0
fi
# Surgical reset: strip only the onboarding.* keys from the app's
# SharedPreferences XML, preserving saved device addresses and other settings.
# This needs run-as, which works for debuggable (sideloaded/dev) builds.
if ! $ADB shell run-as "$PACKAGE" true >/dev/null 2>&1; then
echo "run-as is unavailable for $PACKAGE (release build?)." >&2
echo "Falling back to a full data wipe; re-run with --all to silence this." >&2
$ADB shell pm clear "$PACKAGE"
echo "Done (full wipe)."
exit 0
fi
echo "Clearing onboarding preference keys ($PREF_KEY_PREFIX*) for $PACKAGE..."
# Force-stop first so the running app can't flush its in-memory preferences
# back over the files after we edit them.
$ADB shell am force-stop "$PACKAGE"
# List the shared_prefs XML files, then strip matching <... name="onboarding...">
# entries from each. toybox sed (present on modern Android) supports -i.
# Note: each remote command is passed to `adb shell` as ONE quoted string --
# adb joins multiple args with spaces without re-quoting, so inner quoting
# (e.g. sh -c '...') gets flattened and re-tokenized by the device shell.
FILES="$($ADB shell "run-as $PACKAGE ls shared_prefs 2>/dev/null" | tr -d '\r' || true)"
if [ -z "$FILES" ]; then
echo "No shared_prefs found; the app may not have run yet. Nothing to do."
exit 0
fi
CHANGED=0
for f in $FILES; do
case "$f" in
*.xml) ;;
*) continue ;;
esac
if $ADB shell "run-as $PACKAGE grep -q 'name=\"$PREF_KEY_PREFIX' shared_prefs/$f" >/dev/null 2>&1; then
$ADB shell "run-as $PACKAGE sed -i '/name=\"$PREF_KEY_PREFIX/d' shared_prefs/$f"
echo " cleared onboarding keys in shared_prefs/$f"
CHANGED=1
fi
done
if [ "$CHANGED" -eq 1 ]; then
echo "Done. Relaunch Faceclaw to go through onboarding again."
else
echo "No onboarding keys were set. App is already in pre-onboarding state."
fi