forked from Blendman974/faceclaw
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
This commit is contained in:
commit
a7684f603d
23 files changed
+121
-47
No files matched your search
+102
-34
@@ -23,6 +23,7 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
|
||||
private final Context context;
|
||||
private final String rightAddress;
|
||||
private final String leftAddress;
|
||||
private final FaceclawBleManager bleManager;
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@@ -35,13 +36,21 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
private byte[] awaitPb = null;
|
||||
private CountDownLatch awaitLatch = null;
|
||||
|
||||
/**
|
||||
* A sid-0x09 frame that carried firmware versions without matching the
|
||||
* awaited magic — some firmware pushes the settings snapshot on a magic it
|
||||
* picked itself instead of (or in addition to) acking the read.
|
||||
*/
|
||||
private volatile byte[] unsolicitedSettingsPb;
|
||||
|
||||
private volatile FaceclawDeviceInfoProbeListener listener;
|
||||
private volatile Thread worker;
|
||||
private volatile boolean cancelled = false;
|
||||
|
||||
public FaceclawDeviceInfoProbe(Context context, String rightAddress) {
|
||||
public FaceclawDeviceInfoProbe(Context context, String rightAddress, String leftAddress) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.rightAddress = rightAddress == null ? "" : rightAddress;
|
||||
this.leftAddress = leftAddress == null ? "" : leftAddress;
|
||||
this.bleManager = new FaceclawBleManager(this.context);
|
||||
this.bleManager.setListener(this);
|
||||
}
|
||||
@@ -83,44 +92,28 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
return;
|
||||
}
|
||||
|
||||
emitState("connecting", "");
|
||||
connectArm(rightAddress);
|
||||
byte[] ack = probeArm(rightAddress, "right");
|
||||
// The right lens is the documented control endpoint, but a silent
|
||||
// right lens has been observed on stock 2.2.9 even after a
|
||||
// successful security auth — run the same probe against the left
|
||||
// lens rather than giving up, and log which lens answered.
|
||||
if (ack == null && !cancelled && !leftAddress.trim().isEmpty()
|
||||
&& !leftAddress.equalsIgnoreCase(rightAddress)) {
|
||||
emitLog("right lens did not answer the settings query; probing the left lens");
|
||||
try {
|
||||
ack = probeArm(leftAddress, "left");
|
||||
} catch (Exception e) {
|
||||
emitLog("left-lens probe failed: " + (e.getMessage() == null ? e.toString() : e.getMessage()));
|
||||
}
|
||||
}
|
||||
if (cancelled) {
|
||||
emitError("Cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Firmware 2.2.9 answers no queries until the security-auth
|
||||
// exchange completes over an encrypted link; on a phone with no
|
||||
// existing bond this is also what triggers SMP pairing (and its
|
||||
// OS prompt), so it must come before the prelude and query. Soft:
|
||||
// this probe also runs against the custom firmware, whose response
|
||||
// to the exchange is not yet hardware-verified, so an unconfirmed
|
||||
// auth falls through to the query and only enriches its error.
|
||||
emitState("authenticating", "");
|
||||
boolean authenticated = authenticate(rightAddress);
|
||||
if (cancelled) {
|
||||
emitError("Cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
emitState("querying", "");
|
||||
// Session prelude, then a settings/device-info read (both arms'
|
||||
// versions and the CFW capability string ride back in one response).
|
||||
if (writeAndAwaitAck(rightAddress, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST,
|
||||
BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD,
|
||||
ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) {
|
||||
throw new IllegalStateException("session prelude not acked");
|
||||
}
|
||||
|
||||
int magic = allocMagic();
|
||||
byte[] ack = writeAndAwaitAck(rightAddress, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST,
|
||||
magic, BleProtocol.buildSettingsQuery(magic), QUERY_TIMEOUT_MS);
|
||||
if (ack == null) {
|
||||
throw new IllegalStateException(authenticated
|
||||
? "no response to the device-info query"
|
||||
: "no response to the device-info query — authentication with the glasses did not complete;"
|
||||
+ " if Android shows a Bluetooth pairing request, accept it and try again");
|
||||
throw new IllegalStateException(
|
||||
"no response to the device-info query on either lens — check `adb logcat -s "
|
||||
+ TAG + "` for the frame trace");
|
||||
}
|
||||
|
||||
BleProtocol.FirmwareInfo info = BleProtocol.parseSettingsFirmwareInfo(ack);
|
||||
@@ -140,6 +133,64 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect + authenticate + prelude + settings read on one lens. Returns the
|
||||
* settings ack protobuf, an unsolicited settings push that carried firmware
|
||||
* versions, or null when the lens never answered the read. Throws on
|
||||
* connect or prelude failure; the caller wraps the fallback lens's attempt
|
||||
* so its failure cannot mask the primary lens's outcome.
|
||||
*/
|
||||
private byte[] probeArm(String address, String label) throws InterruptedException {
|
||||
emitState("connecting", label);
|
||||
connectArm(address);
|
||||
if (cancelled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Firmware 2.2.9 answers no queries until the security-auth exchange
|
||||
// completes over an encrypted link; on a phone with no existing bond
|
||||
// this is also what triggers SMP pairing (and its OS prompt), so it
|
||||
// must come before the prelude and query. Soft: this probe also runs
|
||||
// against the custom firmware, whose response to the exchange is not
|
||||
// yet hardware-verified, so an unconfirmed auth falls through.
|
||||
emitState("authenticating", label);
|
||||
boolean authenticated = authenticate(address);
|
||||
if (cancelled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
emitState("querying", label);
|
||||
// Session prelude, then a settings/device-info read (both arms'
|
||||
// versions and the CFW capability string ride back in one response).
|
||||
if (writeAndAwaitAck(address, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST,
|
||||
BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD,
|
||||
ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) {
|
||||
throw new IllegalStateException("session prelude not acked (" + label + " lens)"
|
||||
+ (authenticated ? "" : "; authentication did not complete —"
|
||||
+ " if Android shows a Bluetooth pairing request, accept it and try again"));
|
||||
}
|
||||
|
||||
// Two attempts: the first read straight after a fresh pairing has been
|
||||
// seen to go unanswered while a later one succeeds.
|
||||
for (int attempt = 0; attempt < 2 && !cancelled; attempt++) {
|
||||
int magic = allocMagic();
|
||||
byte[] ack = writeAndAwaitAck(address, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST,
|
||||
magic, BleProtocol.buildSettingsQuery(magic), QUERY_TIMEOUT_MS);
|
||||
if (ack != null) {
|
||||
return ack;
|
||||
}
|
||||
// A push with the firmware versions on the device's own magic is
|
||||
// as good as the ack we asked for.
|
||||
byte[] pushed = unsolicitedSettingsPb;
|
||||
if (pushed != null) {
|
||||
emitLog("using unsolicited settings push instead of the read ack (" + label + " lens)");
|
||||
return pushed;
|
||||
}
|
||||
emitLog("settings query attempt " + (attempt + 1) + " unanswered (" + label + " lens)");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean authenticate(String address) throws InterruptedException {
|
||||
int magic = allocMagic();
|
||||
byte[] ack = writeAndAwaitAck(address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH,
|
||||
@@ -176,10 +227,13 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
synchronized (lock) {
|
||||
seq = nextSeq++ & 0xff;
|
||||
}
|
||||
emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d",
|
||||
address, sid, flag, magic, seq, payload.length));
|
||||
List<byte[]> frames = BleProtocol.framePb(payload, sid, flag, seq);
|
||||
boolean written = bleManager.writeFrames(
|
||||
address, BleProtocol.WRITE_CHAR_UUID, frames, ConnectionOptions.WRITE_TYPE, ConnectionOptions.WRITE_TIMEOUT_MS);
|
||||
if (!written) {
|
||||
emitLog("tx write FAILED sid=0x" + Integer.toHexString(sid));
|
||||
synchronized (lock) {
|
||||
awaitLatch = null;
|
||||
}
|
||||
@@ -199,8 +253,22 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
}
|
||||
BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(data);
|
||||
if (!frame.ok) {
|
||||
emitLog("rx " + address + " unparseable frame len=" + data.length
|
||||
+ " head=" + FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(data, Math.min(16, data.length))));
|
||||
return;
|
||||
}
|
||||
// Log every control frame while diagnosing 2.2.9: sid/flag/type/magic
|
||||
// plus a payload prefix is enough to reconstruct what the lens said.
|
||||
emitLog(String.format("rx %s sid=0x%02x flag=0x%02x type=%d magic=%d frag=%d/%d len=%d pb=%s",
|
||||
address, frame.sid, frame.flag, frame.msgType, frame.msgSeq,
|
||||
data.length > 5 ? data[5] & 0xff : 0, data.length > 4 ? data[4] & 0xff : 0, frame.pb.length,
|
||||
FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(frame.pb, Math.min(40, frame.pb.length)))));
|
||||
if (frame.sid == BleProtocol.SID_UI_SETTING
|
||||
&& BleProtocol.parseSettingsFirmwareInfo(frame.pb) != null) {
|
||||
// Any settings frame carrying firmware versions answers the probe's
|
||||
// question, whether or not it matches the magic we asked with.
|
||||
unsolicitedSettingsPb = frame.pb;
|
||||
}
|
||||
if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) {
|
||||
return; // async event, not an ack
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user