forked from Blendman974/faceclaw
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
This commit is contained in:
1 parent
ee022cdc84
commit
17182532f4
24 files changed
+537
-250
No files matched your search
@@ -31,11 +31,12 @@ import java.util.Set;
|
||||
* its company identifier restored so the "ER"+serial+MAC layout survives
|
||||
* intact, RSSI, advertised TX power, and connectability.
|
||||
*
|
||||
* Admission is deliberately loose — a name containing G2 or R1, or the Even
|
||||
* "ER" manufacturer signature — because renamed custom firmware may drop the
|
||||
* stock name. Side, serial, and pair matching are decided in TypeScript
|
||||
* (app/g2/even-advertisement.ts, app/g2/pairing-candidates.ts) where they can
|
||||
* be unit-tested.
|
||||
* Admission is deliberately loose — a name containing G2, the stock
|
||||
* "EVEN R1…" ring prefix, or the Even "ER" manufacturer signature — because
|
||||
* renamed custom firmware may drop the stock name. Side, serial, and pair
|
||||
* matching are decided in TypeScript (app/g2/even-advertisement.ts,
|
||||
* app/g2/pairing-candidates.ts) where they can be unit-tested; this filter
|
||||
* must stay a superset of the TS classifier's admission.
|
||||
*
|
||||
* Ported from the discovery path of SybilSight's Bluetooth SDK (G2.didDiscover
|
||||
* and R1's advertisement snapshot), reduced to what Android exposes.
|
||||
@@ -288,7 +289,7 @@ public class FaceclawDeviceDiscovery {
|
||||
Integer rssiValue = (rssi == 127 || rssi == 0) ? null : rssi;
|
||||
boolean bonded = device.getBondState() == BluetoothDevice.BOND_BONDED;
|
||||
return buildJson(
|
||||
device.getAddress(), name, toHex(manufacturerData), rssiValue, txPower,
|
||||
device.getAddress(), name, FaceclawFirmwareUtil.bytesToHex(manufacturerData), rssiValue, txPower,
|
||||
connectable, bonded, "scan", System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@@ -332,7 +333,9 @@ public class FaceclawDeviceDiscovery {
|
||||
return false;
|
||||
}
|
||||
String upper = name.toUpperCase();
|
||||
return upper.contains("G2") || upper.contains("R1");
|
||||
// A bare "R1" substring also matches unrelated hardware ("Oppo Enco
|
||||
// R1"), and TS only classifies rings from the stock name prefix.
|
||||
return upper.contains("G2") || upper.startsWith("EVEN R1");
|
||||
}
|
||||
|
||||
private static JSONObject buildJson(
|
||||
@@ -358,17 +361,6 @@ public class FaceclawDeviceDiscovery {
|
||||
}
|
||||
}
|
||||
|
||||
private static String toHex(byte[] bytes) {
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
for (byte b : bytes) {
|
||||
sb.append(String.format("%02X", b & 0xff));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String describeScanError(int errorCode) {
|
||||
switch (errorCode) {
|
||||
case ScanCallback.SCAN_FAILED_ALREADY_STARTED:
|
||||
|
||||
@@ -11,24 +11,32 @@ import java.security.NoSuchAlgorithmException;
|
||||
* Native helpers for the on-device custom-firmware build: SHA-256 hashing and
|
||||
* binary file writing. Both take a java.nio.ByteBuffer so NativeScript can
|
||||
* marshal a JS ArrayBuffer straight across without a per-element copy of the
|
||||
* ~4 MB firmware image (and with no overload ambiguity).
|
||||
* ~4 MB firmware image (and with no overload ambiguity). Also home of the one
|
||||
* shared byte→hex encoder for com.faceclaw.app.
|
||||
*/
|
||||
public final class FaceclawFirmwareUtil {
|
||||
private FaceclawFirmwareUtil() {}
|
||||
|
||||
/** Lowercase hex of the bytes. The TS-side decoder is case-insensitive. */
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
for (byte b : bytes) {
|
||||
int v = b & 0xff;
|
||||
sb.append(Character.forDigit(v >>> 4, 16));
|
||||
sb.append(Character.forDigit(v & 0x0f, 16));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** Lowercase hex SHA-256 of the buffer's remaining bytes. */
|
||||
public static String sha256Hex(ByteBuffer data) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(data.duplicate());
|
||||
byte[] digest = md.digest();
|
||||
StringBuilder sb = new StringBuilder(digest.length * 2);
|
||||
for (byte b : digest) {
|
||||
int v = b & 0xff;
|
||||
sb.append(Character.forDigit(v >>> 4, 16));
|
||||
sb.append(Character.forDigit(v & 0x0f, 16));
|
||||
}
|
||||
return sb.toString();
|
||||
return bytesToHex(md.digest());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("SHA-256 unavailable", e);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class FaceclawModelDownloader {
|
||||
+ expectedTotalBytes + " bytes); try again to resume");
|
||||
return;
|
||||
}
|
||||
String actualSha = toHex(digest.digest());
|
||||
String actualSha = FaceclawFirmwareUtil.bytesToHex(digest.digest());
|
||||
if (!expectedSha256.isEmpty() && !actualSha.equals(expectedSha256)) {
|
||||
partFile.delete();
|
||||
postError("Model download was corrupted (checksum mismatch); download it again");
|
||||
@@ -177,12 +177,6 @@ public class FaceclawModelDownloader {
|
||||
return hashed;
|
||||
}
|
||||
|
||||
private static String toHex(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
for (byte b : bytes) sb.append(String.format("%02x", b));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void post(Runnable runnable) {
|
||||
callbackHandler.post(runnable);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user