Skip to content

Commit 8bc84c2

Browse files
strzhaoclaude
andcommitted
fix(harmonyos): refuse the trajectory carrier by default and name the transport in results
Motivation: Integration smoke on a slider page caught the carrier path reporting a green injection that moved nothing: same slider, same coordinates, `uitest uiInput swipe` triggered the ArkUI PanGesture 3/3 while the carrier injected 0/4 across every shape (2-point line, fine steps, burst) - its touches reach system-layer windows but not component-anchored gestures of ordinary app windows. Approach: - the human-trajectory lowering takes the raw evdev sendevent transport first; when the device denies it, `--trajectory human` refuses with trajectory-channel-unavailable (comparison data in the message) instead of reporting a silent green. - the carrier becomes an explicit operator opt-in behind AGENT_DEVICE_HARMONY_CARRIER=1, with a missing carrier refusing via its typed error, and results carry trajectoryTransport so callers can negotiate. Test evidence: - on-device comparison runs recorded in examples/harmony-trajectory-driver/README. - 858 contracts+platform-harmonyos unit tests, including the refusal-instead- of-green cells for denied listings and missing carriers. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 86e6dc4 commit 8bc84c2

3 files changed

Lines changed: 97 additions & 41 deletions

File tree

‎examples/harmony-trajectory-driver/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ hdc -t <serial> shell aa test -b com.stringzhao.adtrajdriver -m entry_test \
6767
Expect `pass: adtraj_injectTrajectory` in the output and one
6868
`ADTRAJ_RESULT {"ok":true,...}` hilog line on tag `AdTrajDriver`.
6969

70+
## Transport status (on-device comparison, 2026-11-04)
71+
72+
The carrier's injected touches reach system-layer windows (they scrolled the OS agreement page)
73+
but do NOT trigger component-anchored gestures of ordinary app windows. Same slider, same
74+
coordinates: `uitest uiInput swipe` triggered the ArkUI PanGesture 3/3 (pass at 350 px/s, a
75+
mis-judged fail at 200 px/s - both prove the gesture fired), while the carrier injected 0/4
76+
across shapes (2-point line, 41-point fine steps, 51-point burst at 40000 px/s).
77+
78+
agent-device therefore treats this carrier as an **experimental, explicit opt-in**: the CLI takes
79+
the raw evdev sendevent transport first, and only `AGENT_DEVICE_HARMONY_CARRIER=1` selects this
80+
carrier when evdev is denied. Without either, `--trajectory human` refuses with
81+
`trajectory-channel-unavailable` instead of reporting a green injection that moves nothing.
82+
7083
## AGC checklist (one-time, for a new bundle)
7184

7285
1. AGC console → My apps → Create app: package name `com.stringzhao.adtrajdriver`.

‎packages/platform-harmonyos/src/__tests__/input-actions.test.ts‎

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,33 @@ test('a human-trajectory plan lowers through the touchscreen node as one sendeve
171171
},
172172
],
173173
};
174-
runHarmonyShell.mockResolvedValueOnce({ stdout: '', stderr: '' });
175174
runHarmonyShell.mockResolvedValueOnce({
176175
stdout: 'N: Name="touchscreen tp"\nH: Handlers=event3',
176+
stderr: '',
177177
});
178178

179179
const result = await performHarmonyGesture(device, humanPlan);
180180

181-
assert.deepEqual(result, {
182-
backend: 'harmonyos-sendevent-trajectory',
183-
deviceNode: '/dev/input/event3',
184-
sampleCount: 3,
185-
durationMs: 500,
186-
viewport: humanPlan.viewport,
187-
});
188-
assert.equal(runHarmonyShell.mock.calls.length, 3);
189-
const [, resolutionCall, injectionCall] = runHarmonyShell.mock.calls;
181+
assert.deepEqual(
182+
{
183+
backend: result.backend,
184+
trajectoryTransport: result.trajectoryTransport,
185+
sampleCount: result.sampleCount,
186+
},
187+
{
188+
backend: 'harmonyos-sendevent-trajectory',
189+
trajectoryTransport: 'sendevent',
190+
sampleCount: 3,
191+
},
192+
);
193+
assert.equal(runHarmonyShell.mock.calls.length, 2);
194+
const [resolutionCall, injectionCall] = runHarmonyShell.mock.calls;
190195
assert.deepEqual(resolutionCall?.[1], ['cat', '/proc/bus/input/devices']);
191196
assert.equal(injectionCall?.[1]?.[0], 'sh');
192197
assert.equal(injectionCall?.[1]?.[1], '-c');
193198
const script = injectionCall?.[1]?.[2] as string;
194199
assert.equal(typeof script, 'string');
195200
assert.ok(script.includes("'/dev/input/event3'"));
196-
assert.ok(script.includes('uinput sendevent'));
197201
assert.ok(injectionCall?.[2]?.timeoutMs > 500);
198202
});
199203

@@ -216,7 +220,6 @@ test('the resolved touchscreen node is cached per device across gestures', async
216220
},
217221
],
218222
};
219-
// One answer serves every probe: no carrier bundle in it, a touch panel for the node parse.
220223
runHarmonyShell.mockResolvedValue({
221224
stdout: 'N: Name="touchscreen tp"\nH: Handlers=event3',
222225
stderr: '',
@@ -248,13 +251,18 @@ test('a human-trajectory plan without a touchscreen node refuses with the typed
248251
},
249252
],
250253
};
251-
runHarmonyShell.mockResolvedValueOnce({ stdout: '', stderr: '' });
252-
runHarmonyShell.mockResolvedValueOnce({ stdout: 'N: Name="gpio-keys"\nH: Handlers=event2' });
254+
runHarmonyShell.mockResolvedValueOnce({
255+
stdout: 'N: Name="gpio-keys"\nH: Handlers=event2',
256+
stderr: '',
257+
});
253258

254-
await assert.rejects(() => performHarmonyGesture(device, humanPlan), /no touchscreen evdev node/);
259+
await assert.rejects(
260+
() => performHarmonyGesture(device, humanPlan),
261+
/No effective HarmonyOS trajectory transport/,
262+
);
255263
});
256264

257-
test('a device that denies the input listing refuses with the typed commercial gap', async () => {
265+
test('a device that denies the input listing refuses instead of going green', async () => {
258266
const device = { ...DEVICE, id: 'harmony-traj-denied' };
259267
const humanPlan: GesturePlan = {
260268
topology: 'single',
@@ -273,7 +281,6 @@ test('a device that denies the input listing refuses with the typed commercial g
273281
},
274282
],
275283
};
276-
runHarmonyShell.mockResolvedValueOnce({ stdout: '', stderr: '' });
277284
// hdc never carries a remote failure to the client exit and merges remote stderr into stdout.
278285
runHarmonyShell.mockResolvedValueOnce({
279286
stdout: '/bin/sh: cat: /proc/bus/input/devices: Permission denied',
@@ -282,14 +289,15 @@ test('a device that denies the input listing refuses with the typed commercial g
282289

283290
await assert.rejects(
284291
() => performHarmonyGesture(device, humanPlan),
285-
/could not read the input device listing/,
292+
/No effective HarmonyOS trajectory transport/,
286293
);
287294
// The refusal must not poison the cache: the same device can still run the endpoint transport.
288295
await pressHarmony(device, 5, 6);
289296
assert.deepEqual(runHarmonyShell.mock.calls.at(-1)?.[1], ['uitest', 'uiInput', 'click', 5, 6]);
290297
});
291298

292-
test('an installed carrier lowers the human plan through one aa test injection', async () => {
299+
test('an installed carrier is an explicit opt-in path behind AGENT_DEVICE_HARMONY_CARRIER=1', async () => {
300+
vi.stubEnv('AGENT_DEVICE_HARMONY_CARRIER', '1');
293301
const device = { ...DEVICE, id: 'harmony-traj-carrier' };
294302
const humanPlan: GesturePlan = {
295303
topology: 'single',
@@ -309,13 +317,18 @@ test('an installed carrier lowers the human plan through one aa test injection',
309317
},
310318
],
311319
};
320+
// The probe cat fails the sendevent transport first; the carrier probe and injection follow.
321+
runHarmonyShell.mockResolvedValueOnce({
322+
stdout: '/bin/sh: cat: /proc/bus/input/devices: Permission denied',
323+
stderr: '',
324+
});
312325
runHarmonyShell.mockResolvedValueOnce({
313326
stdout: 'Bundle name: com.stringzhao.adtrajdriver\nappId: 1',
314327
stderr: '',
315328
});
316329
runHarmonyShell.mockResolvedValueOnce({
317330
stdout:
318-
'OHOS_REPORT_RESULT: stream=Tests run: 1, Failure: 0, Error: 0, Pass: 1\nADTRAJ_RESULT {"ok":true,"sampleCount":3,"speed":283,"error":"elapsed 1624ms"}',
331+
'ADTRAJ_RESULT {"ok":true,"sampleCount":3,"speed":283,"error":"elapsed 1624ms"}\nTests run: 1, Failure: 0, Error: 0, Pass: 1',
319332
stderr: '',
320333
});
321334

@@ -324,22 +337,23 @@ test('an installed carrier lowers the human plan through one aa test injection',
324337
assert.deepEqual(
325338
{
326339
backend: result.backend,
327-
sampleCount: result.sampleCount,
340+
trajectoryTransport: result.trajectoryTransport,
328341
speed: result.speed,
329342
},
330-
{ backend: 'harmonyos-uitest-inputpointer', sampleCount: 3, speed: 283 },
343+
{
344+
backend: 'harmonyos-uitest-inputpointer',
345+
trajectoryTransport: 'carrier-experimental',
346+
speed: 283,
347+
},
331348
);
332-
const [installProbe, injection] = runHarmonyShell.mock.calls;
349+
const [, installProbe, injectionCall] = runHarmonyShell.mock.calls;
333350
assert.deepEqual(installProbe?.[1], ['bm', 'dump', '-n', 'com.stringzhao.adtrajdriver']);
334-
assert.deepEqual(injection?.[1]?.slice(0, 2), ['sh', '-c']);
335-
const script = injection?.[1]?.[2] as string;
336-
assert.match(script, /uitest start-daemon adtraj &\n/);
337-
const request = JSON.parse(/-s traj '([^']+)'/.exec(script)![1]);
338-
assert.equal(request.steps.length, 3);
351+
assert.deepEqual(injectionCall?.[1]?.slice(0, 2), ['sh', '-c']);
352+
vi.unstubAllEnvs();
339353
});
340354

341-
test('a carrier-refused injection fails with the typed reason and the carrier detail', async () => {
342-
const device = { ...DEVICE, id: 'harmony-traj-refused' };
355+
test('without the carrier opt-in a commercial device refuses instead of reporting a silent green', async () => {
356+
const device = { ...DEVICE, id: 'harmony-traj-nogreen' };
343357
const humanPlan: GesturePlan = {
344358
topology: 'single',
345359
intent: 'pan',
@@ -358,17 +372,16 @@ test('a carrier-refused injection fails with the typed reason and the carrier de
358372
],
359373
};
360374
runHarmonyShell.mockResolvedValueOnce({
361-
stdout: 'Bundle name: com.stringzhao.adtrajdriver\nappId: 1',
362-
stderr: '',
363-
});
364-
runHarmonyShell.mockResolvedValueOnce({
365-
stdout:
366-
'ohosTest run: fail: [adtraj] injectTrajectory injectMultiPointerAction returned false\n',
375+
stdout: '/bin/sh: cat: /proc/bus/input/devices: Permission denied',
367376
stderr: '',
368377
});
369378

370379
await assert.rejects(
371380
() => performHarmonyGesture(device, humanPlan),
372-
/trajectory injection was refused by the carrier/,
381+
(error: Error) => {
382+
assert.match(error.message, /No effective HarmonyOS trajectory transport/);
383+
assert.match(error.message, /uiInput triggered 3\/3, carrier 0\/4/);
384+
return true;
385+
},
373386
);
374387
});

‎packages/platform-harmonyos/src/input-actions.ts‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import {
2121
injectHarmonyTrajectoryViaDriver,
2222
isHarmonyTrajectoryDriverInstalled,
23+
trajectoryDriverMissingError,
2324
} from './trajectory-driver.ts';
2425
import { invalidateHarmonyGestureViewport, readHarmonyGestureViewport } from './snapshot.ts';
2526

@@ -69,16 +70,43 @@ async function resolveHarmonyTouchDeviceNode(device: DeviceInfo): Promise<string
6970
return node;
7071
}
7172

73+
/** Whether the raw evdev transport can run: the touchscreen node must resolve and be writable. */
74+
async function probeHarmonySendEventTransport(device: DeviceInfo): Promise<boolean> {
75+
try {
76+
await resolveHarmonyTouchDeviceNode(device);
77+
return true;
78+
} catch {
79+
return false;
80+
}
81+
}
82+
7283
/**
73-
* Lowers a human-trajectory plan to the best transport this device exposes: the carrier HAP's
74-
* `injectMultiPointerAction` (the commercial-device path) first, then the panel evdev node for
75-
* builds where shell can write input, and the typed refusals name the remaining gap.
84+
* Lowers a human-trajectory plan to the best transport this device exposes. The panel evdev node
85+
* (raw touch event stream, full field fidelity) is the default path. The carrier HAP's
86+
* `injectMultiPointerAction` is an explicit operator opt-in: on-device comparison runs showed its
87+
* touches reach system-layer windows but NOT component-anchored gestures of ordinary app windows
88+
* (slider PanGesture: uiInput 3/3 triggered, carrier 0/4, shape-independent), so a silent
89+
* carrier-first path would report a green injection that moves nothing.
7690
*/
7791
async function performHarmonyHumanTrajectoryGesture(
7892
device: DeviceInfo,
7993
plan: SinglePointerGesturePlan,
8094
): Promise<Record<string, unknown>> {
81-
if (await isHarmonyTrajectoryDriverInstalled(device)) {
95+
const sendeventUsable = await probeHarmonySendEventTransport(device);
96+
if (!sendeventUsable && process.env.AGENT_DEVICE_HARMONY_CARRIER !== '1') {
97+
throw new AppError(
98+
'UNSUPPORTED_OPERATION',
99+
'No effective HarmonyOS trajectory transport on this device (comparison runs: uiInput triggered 3/3, carrier 0/4)',
100+
{
101+
reason: 'trajectory-channel-unavailable',
102+
hint: 'Raw evdev is denied by this build and the carrier HAP route does not reach component-anchored gestures. Set AGENT_DEVICE_HARMONY_CARRIER=1 to force the experimental carrier path, or run the endpoint swipe transport.',
103+
},
104+
);
105+
}
106+
if (!sendeventUsable) {
107+
if (!(await isHarmonyTrajectoryDriverInstalled(device))) {
108+
throw trajectoryDriverMissingError();
109+
}
82110
const outcome = await injectHarmonyTrajectoryViaDriver(device, plan);
83111
if (!outcome.accepted) {
84112
throw new AppError(
@@ -93,6 +121,7 @@ async function performHarmonyHumanTrajectoryGesture(
93121
}
94122
return {
95123
backend: outcome.backend,
124+
trajectoryTransport: 'carrier-experimental',
96125
sampleCount: outcome.sampleCount,
97126
speed: outcome.speed,
98127
durationMs: plan.durationMs,
@@ -112,6 +141,7 @@ async function performHarmonyHumanTrajectoryGesture(
112141
await runHarmonyShell(device, ['sh', '-c', script], { timeoutMs });
113142
return {
114143
backend: 'harmonyos-sendevent-trajectory',
144+
trajectoryTransport: 'sendevent',
115145
deviceNode,
116146
sampleCount: trajectory.sampleCount,
117147
durationMs: trajectory.durationMs,

0 commit comments

Comments
 (0)