forked from Blendman974/faceclaw
Forward ring input events before filtering, and include swipe info
This commit is contained in:
1 parent
b972cd7682
commit
7b19c00443
20 files changed
+368
-75
No files matched your search
@@ -20,12 +20,13 @@ const event = (type, timestampMs = 1000) => ({ type, source: 'ring', timestampMs
|
||||
|
||||
function shellDeclarations() {
|
||||
const source = ts.createSourceFile('shell.ts', read('app/ui/shell/shell.ts'), ts.ScriptTarget.Latest, true);
|
||||
const names = new Set(['rawInputEventToPayload', 'eventSourceToString', 'scrollEvent']);
|
||||
const names = new Set(['rawInputEventToInputEvent', 'rawInputEventToPayload', 'eventSourceToString', 'scrollEvent']);
|
||||
const declarations = source.statements.filter((s) => ts.isFunctionDeclaration(s) && names.has(s.name?.text));
|
||||
assert.equal(declarations.length, names.size);
|
||||
const shell = source.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === 'Shell');
|
||||
const methods = shell.members.filter((s) => ['receiveInput', 'routeInput'].includes(s.name?.getText(source)));
|
||||
const context = { exports: {}, notifyInputListeners: monitor.notifyInputListeners,
|
||||
const context = { exports: {}, acceptInput: monitor.acceptInput,
|
||||
makeInputEvent: (payload) => ({ ...payload, timestampMs: 12345678 }),
|
||||
...load('app/g2/events.ts') };
|
||||
vm.createContext(context);
|
||||
vm.runInContext(js(declarations.map((s) => s.getText(source)).join('\n') +
|
||||
@@ -103,11 +104,16 @@ test('Input events captures while visible, pauses for history, and unsubscribes
|
||||
pop: () => pops++, popThrough: (page) => { assert.equal(page, layer); page.onRemoved(); } } };
|
||||
try {
|
||||
for (const type of ['ring-press','click','ring-press','ring-press','double-click','long-press','long-press-release','short-then-long-press']) {
|
||||
const e = event(type, 1000 + renders * 75); monitor.notifyInputListeners(e); layer.handleInput(e);
|
||||
const e = { ...event(type, 1000 + renders * 75), ringInput: { tick: 4294967200 + renders, type: 1, aux:0, speed:0 } };
|
||||
monitor.notifyInputListeners(e, renders > 0); layer.handleInput(e);
|
||||
}
|
||||
assert.equal(renders, 8); assert.equal(layer.log.count, 8); assert.equal(pops, 0);
|
||||
visible = false; monitor.notifyInputListeners(event('click')); assert.equal(renders, 8); visible = true;
|
||||
const image = layer.paint(ctx);
|
||||
assert.ok(image.texts.some(t => t.text.startsWith("R4294967")));
|
||||
assert.ok(image.texts.some(t => t.text.startsWith("*")));
|
||||
layer.menuItems()[2].onSelect(ctx);
|
||||
assert.ok(layer.paint(ctx).texts.some(t => t.text.startsWith("Phone receive time")));
|
||||
for (const text of image.texts) {
|
||||
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
|
||||
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
|
||||
@@ -120,7 +126,69 @@ test('Input events captures while visible, pauses for history, and unsubscribes
|
||||
layer.menuItems()[1].onSelect(ctx); assert.equal(layer.log.count, 0);
|
||||
layer.menuItems()[0].onSelect(ctx); monitor.notifyInputListeners(event('ring-press'));
|
||||
assert.equal(layer.log.count, 1);
|
||||
layer.menuItems()[2].onSelect(ctx); monitor.notifyInputListeners(event('click'));
|
||||
layer.menuItems()[3].onSelect(ctx); monitor.notifyInputListeners(event('click'));
|
||||
assert.equal(removed, 1); assert.equal(layer.log.count, 1);
|
||||
} finally { layer.onRemoved(); }
|
||||
});
|
||||
|
||||
const ring = (type, tick, received = 1000) => ({ ...event('click', received),
|
||||
ringInput: { type, tick, aux: 17, speed: 29 } });
|
||||
|
||||
test('filter matches stock timing boundaries, exemptions, wrap, reset and zero sentinel', () => {
|
||||
const f = new monitor.RingInputFilter();
|
||||
for (const [type, tick, accepted] of [
|
||||
[1,1000,true], [1,1099,false], [10,1099,true], [1,1100,true],
|
||||
[8,1101,true], [2,1200,false], [2,1201,true], [2,1201,false],
|
||||
[10,1201,true], [10,1202,true], [9,1301,true],
|
||||
]) assert.equal(f.accept(ring(type, tick)), accepted, `${type}@${tick}`);
|
||||
f.reset(); assert.equal(f.accept(ring(1,1)), true);
|
||||
f.reset(); assert.equal(f.accept(ring(1,0xffffffd0)),true);
|
||||
assert.equal(f.accept(ring(1,0x33)),false); assert.equal(f.accept(ring(1,0x34)),true);
|
||||
// Backward timestamps / ring restart pass using unsigned subtraction.
|
||||
assert.equal(f.accept(ring(1,5)),true);
|
||||
f.reset(); assert.equal(f.accept(ring(1,0)),true); assert.equal(f.accept(ring(1,1)),true);
|
||||
assert.equal(f.accept(event('click')),true);
|
||||
assert.equal(f.accept({ ...event('click'), source: 'watch' }),true);
|
||||
// Host scheduling does not affect decisions; filtered events do not extend the window.
|
||||
f.reset(); assert.equal(f.accept(ring(4,1000,100000)),true);
|
||||
assert.equal(f.accept(ring(4,1050,999999)),false);
|
||||
assert.equal(f.accept(ring(4,1100,999999)),true);
|
||||
f.reset(); assert.equal(f.accept(ring(99,2000)),true);
|
||||
assert.equal(f.accept(ring(1,2050)),false);
|
||||
});
|
||||
|
||||
test('raw debug observer sees suppressed reports once before app routing', async () => {
|
||||
monitor.resetRingInputFilter();
|
||||
const { exports: { Shell } } = shellDeclarations(), s = new Shell(), seen = [], routed = [];
|
||||
s.routeInput = async (e) => { routed.push(e); return { shell:false,window:true }; };
|
||||
s.syncInputFocus = () => {};
|
||||
const off = monitor.addInputListener((e, filtered) => seen.push([e, filtered]));
|
||||
try {
|
||||
const first = ring(1,1000), second = ring(1,1050);
|
||||
assert.equal(monitor.acceptInput(first),true); await s.receiveInput(first);
|
||||
assert.equal(monitor.acceptInput(second),false); await s.receiveInput(second);
|
||||
assert.equal(seen.length,2); assert.equal(routed.length,1);
|
||||
assert.deepEqual(seen.map((e) => e[1]),[false,true]);
|
||||
assert.equal(seen[1][0].ringInput.tick,1050);
|
||||
assert.equal(Object.isFrozen(seen[1][0].ringInput),true);
|
||||
} finally { off(); monitor.resetRingInputFilter(); }
|
||||
});
|
||||
|
||||
test('raw-to-app conversion retains the unsigned ring clock and explicit scroll source', () => {
|
||||
const d = shellDeclarations();
|
||||
for (const [wire,eventType,direction] of [[4,1,'scroll-up'],[5,2,'scroll-down']]) {
|
||||
const raw = { kind:'sys-event', eventType, eventSource:2, ringInput: ring(wire,0xffffffff).ringInput };
|
||||
const input = d.exports.rawInputEventToInputEvent(raw);
|
||||
assert.equal(input.type,direction); assert.equal(input.source,'ring');
|
||||
assert.equal(input.timestampMs,12345678); assert.equal(input.ringInput.tick,0xffffffff);
|
||||
assert.notEqual(input.ringInput,raw.ringInput);
|
||||
}
|
||||
});
|
||||
|
||||
test('debug history retains both clocks and uses unsigned gaps across counter wrap', () => {
|
||||
const log = new monitor.InputEventLog();
|
||||
log.add(ring(1,0xfffffff0,5000)); log.add(ring(1,0x10,5001),true);
|
||||
assert.equal(log.entries[0].gapMs,1); assert.equal(log.entries[0].ringGapTicks,32);
|
||||
assert.equal(log.entries[0].filtered,true);
|
||||
log.clear(); log.add(ring(1,500)); assert.equal(log.entries[0].ringGapTicks,null);
|
||||
});
|
||||
@@ -15,6 +15,7 @@ test('iOS installed apps launch, recover missing packages, and close before unin
|
||||
const calls = [], app = { packageId: 'test.app', name: 'Test' };
|
||||
let present = true;
|
||||
const modules = {
|
||||
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
|
||||
'../apps/all-apps': { ALL_APPS: [{ appId: 'evenhub' }] },
|
||||
'../apps/evenhub/installed-apps': { getInstalledEvenHubAppById: id => id === 'installed' ? app : null,
|
||||
installedEvenHubPackageId: id => id === 'installed' ? app.packageId : null,
|
||||
@@ -190,6 +191,7 @@ test('background glasses input still composites frames; phone resume preserves t
|
||||
}
|
||||
const settings = { lockScreenEnabledSetting: { get: () => true }, onAnySettingChanged: () => () => {}, previewColorSetting: { get: () => 'white' } };
|
||||
const modules = {
|
||||
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
|
||||
'../assistant/system-tools': { registerSystemTools() {} },
|
||||
'../assistant/window-tools': { registerWindowTools() {} },
|
||||
'../assistant/navigate-tools': { registerNavigateTools() {} },
|
||||
@@ -271,6 +273,7 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
|
||||
on: (key, fn) => appEvents.set(key, fn), off: key => appEvents.delete(key) },
|
||||
Button: View, Color: class {}, Dialogs: {}, GridLayout: View, Image: View, Label: View, Page: View, StackLayout: View };
|
||||
const modules = {
|
||||
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
|
||||
'../assistant/system-tools': { registerSystemTools() {} },
|
||||
'../assistant/window-tools': { registerWindowTools() {} },
|
||||
'../assistant/navigate-tools': { registerNavigateTools() {} },
|
||||
|
||||
@@ -70,7 +70,9 @@ function fixture() {
|
||||
createBoard: () => ({ start: () => boardStats.starts++, stop: () => boardStats.stops++,
|
||||
paint: () => { boardStats.paints++; return new images.GrayImage(100, 80, 200); } }),
|
||||
};
|
||||
const inputMonitor = load("app/ui/input-monitor.ts", {});
|
||||
const modules = {
|
||||
"../ui/input-monitor": inputMonitor,
|
||||
'../assistant/system-tools': { registerSystemTools() {} },
|
||||
'../assistant/window-tools': { registerWindowTools() {} },
|
||||
'../assistant/navigate-tools': { registerNavigateTools() {} },
|
||||
@@ -103,6 +105,7 @@ function fixture() {
|
||||
'../ui/gestures': { makeInputEvent: event => event }, '../ui/layers': { noopLayerActions: {} },
|
||||
'../apps/files/text-viewer': {},
|
||||
'../ui/shell/shell': { shell, rawInputEventToInputEvent: event => ({
|
||||
ringInput: event.ringInput, timestampMs: now,
|
||||
type: event.kind === 'display-wake' ? 'display-wake'
|
||||
: ({ 0: 'click', 1: 'scroll-up', 2: 'scroll-down', 3: 'double-click', 9: 'long-press',
|
||||
10: 'long-press-release', 11: 'short-then-long-press' })[event.eventType] ?? 'unknown', source: 'ring',
|
||||
@@ -127,9 +130,11 @@ function fixture() {
|
||||
await drain();
|
||||
}
|
||||
async function render() { await drain(); await advance(33); assert.deepEqual(errors, []); }
|
||||
async function hardware(type, source = 2) {
|
||||
async function hardware(type, source = 2, ringTick) {
|
||||
const payload = protocol.bytes(13, protocol.bytes(3, protocol.concat(protocol.integer(1, type), protocol.integer(2, source))));
|
||||
session.onInput(protocol.decodeGlassesInput({ sid: protocol.SID.hub, flag: 1, payload }));
|
||||
const input = protocol.decodeGlassesInput({ sid: protocol.SID.hub, flag: 1, payload });
|
||||
if (ringTick !== undefined) input.ringInput = { type: type === 3 ? 2 : 1, tick: ringTick, aux:0, speed:0 };
|
||||
session.onInput(input);
|
||||
await render();
|
||||
}
|
||||
async function phone(type, origin = 'ring') { controller.gesture(type, origin); await render(); }
|
||||
@@ -273,3 +278,24 @@ test('iOS locked phone controls cannot dispatch mirror, voice, or keyboard input
|
||||
await f.render();
|
||||
assert.ok(f.sent.at(-1).every(p => p === 123));
|
||||
});
|
||||
|
||||
|
||||
test('iOS deduplicates original ring ticks before apps, lock toggles and Glanceboard', async () => {
|
||||
const f = fixture(); await f.controller.connect();
|
||||
await f.hardware(0,2,1000); await f.hardware(0,2,1050);
|
||||
assert.equal(f.received.length,1);
|
||||
await f.hardware(0,2,1100); assert.equal(f.received.length,2);
|
||||
// A filtered click cannot open a sleep-time board.
|
||||
f.shell.sleep(); await f.hardware(0,2,1150);
|
||||
assert.equal(f.controller.glance.isVisible(),false);
|
||||
await f.hardware(0,2,1200); assert.equal(f.controller.glance.isVisible(),true);
|
||||
// A duplicated double tap must not wake and immediately re-sleep a lock screen.
|
||||
f.observers.get('lock')(); f.wear(false); await f.render();
|
||||
f.shell.sleep(); await f.hardware(3,2,2000);
|
||||
assert.equal(f.shell.isScreenOn(),true);
|
||||
await f.hardware(3,2,2050); assert.equal(f.shell.isScreenOn(),true);
|
||||
// A new transport session starts a fresh suppression window.
|
||||
f.controller.session.onState({ phase:'retrying' });
|
||||
f.controller.session.onState({ phase:'connected' });
|
||||
await f.hardware(3,2,2051); assert.equal(f.shell.isScreenOn(),false);
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class RingInputTest {
|
||||
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
// Exact packet emitted by the emulated CFW receiver, including a tick > INT_MAX.
|
||||
private val packet = hex("08026a151a13080e1002a2060c524901010aabcd00efcdab89")
|
||||
|
||||
@Test fun preservesOriginalClockAndRawFieldsThroughTheNativeDecoder() {
|
||||
val decoded = assertNotNull(G2Event.decodePayload(224, packet))
|
||||
assertEquals("sys-event", decoded.kind)
|
||||
assertEquals(14, decoded.eventType)
|
||||
assertEquals(2, decoded.eventSource)
|
||||
assertEquals(0x89abcdefL, decoded.ringTick)
|
||||
assertEquals(10, decoded.ringType)
|
||||
assertEquals(171, decoded.ringAux)
|
||||
assertEquals(205, decoded.ringSpeed)
|
||||
// Exercise framing and CRC removal too (Android's entry point).
|
||||
val frame = BleProtocol.framePb(packet, 224, 1, 1).single()
|
||||
val native = assertNotNull(G2Event.decode(BleProtocol.parseFrame(frame)))
|
||||
assertEquals(decoded.ringTick, native.ringTick)
|
||||
}
|
||||
|
||||
@Test fun legacyAndInvalidExtensionsNeverInventATimestamp() {
|
||||
assertEquals(-1L, assertNotNull(G2Event.decodePayload(224, hex("08026a041a02080e"))).ringTick)
|
||||
for (offset in listOf(9,13,14,15,16,20)) {
|
||||
val bad = packet.copyOf(); bad[offset] = (bad[offset].toInt() + 1).toByte()
|
||||
assertEquals(-1L, assertNotNull(G2Event.decodePayload(224, bad)).ringTick)
|
||||
}
|
||||
for (tick in listOf(0L,1L,0xffffffffL)) {
|
||||
val p = packet.copyOf()
|
||||
for (i in 0..3) p[21+i] = (tick shr (i*8)).toByte()
|
||||
assertEquals(tick, assertNotNull(G2Event.decodePayload(224,p)).ringTick)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const protocol = require('../.test-build/app/g2/ble-protocol.js');
|
||||
const decode = (payload) => protocol.decodeGlassesInput({ sid:224,flag:1,payload });
|
||||
const packet = Buffer.from('08026a151a13080e1002a2060c524901010aabcd00efcdab89','hex');
|
||||
|
||||
test('timestamped CFW packet decodes atomically with source and original unsigned tick', () => {
|
||||
const input = decode(packet);
|
||||
assert.equal(input.eventType,14); assert.equal(input.eventSource,2);
|
||||
assert.deepEqual(input.ringInput,{tick:0x89abcdef,type:10,aux:171,speed:205});
|
||||
for (const tick of [0,1,0xffffffff]) {
|
||||
const p = Buffer.from(packet); p.writeUInt32LE(tick,21);
|
||||
assert.equal(decode(p).ringInput.tick,tick);
|
||||
}
|
||||
});
|
||||
test('legacy/invalid metadata leaves input intact without inventing a clock', () => {
|
||||
assert.equal(decode(Buffer.from('08026a041a02080e','hex')).ringInput,undefined);
|
||||
for (const offset of [9,13,14,15,16,20]) {
|
||||
const p = Buffer.from(packet); p[offset]++;
|
||||
assert.equal(decode(p).ringInput,undefined);
|
||||
}
|
||||
});
|
||||
|
||||
// Firmware regression: MsgPbTxByBle sets flag 0; Thread_MsgPbNotifyByBle
|
||||
// (also used by stock SysEvent) sets flag 1. Payload validity is insufficient.
|
||||
test('ring input must use the notification envelope, never the reply envelope', () => {
|
||||
assert.equal(protocol.decodeGlassesInput({ sid:224,flag:0,payload:packet }),null);
|
||||
for (const flag of [1,6]) {
|
||||
const input = protocol.decodeGlassesInput({ sid:224,flag,payload:packet });
|
||||
assert.equal(input.eventType,14); assert.equal(input.ringInput.tick,0x89abcdef);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user