Skip to content

Commit ddba75f

Browse files
committed
fix(android): preserve lazy helper loading and align regression fixtures
1 parent 1aa6798 commit ddba75f

12 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎docs/evidence/android-automation-performance-2026-10-19.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ Full-suite investigation exposed a pre-existing Android live-text bug on both ba
6363
An early native-fill implementation omitted the keyboard-opening tap; the lifecycle scenario detected it and the focus tap was restored. One checkout submission miss occurred before the final synchronization and freshness hardening; six isolated checkout replays passed, so its cause was not established. The final combined suite passed, including every replay without retries.
6464

6565
Input-socket and screenshot-default regressions failed on unchanged production code (`3 failed, 17 passed`) and passed with the implementation. The focus-path regression also failed on unchanged base. The text-identity regression was observed red and green at its owning hierarchy seam, and its contract and daemon forwarding tests passed.
66+
67+
The broad unit selection initially exposed stale screenshot expectations, an inconsistent foreground fixture, and added eager imports. Their fixes passed 1,016 focused tests. The Android TV provider timeout also reproduced on unchanged base: its accepted IME installation was followed by an empty registration list. The fixture now reports the installed service; both Android provider scenario files passed seven tests without a timeout increase.

‎packages/daemon/src/execution/interaction/internal/interaction-dispatch-disclosure.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ async function pressThenForegroundReadRefused(): Promise<unknown> {
336336
const readRefusal = new AppError('COMMAND_FAILED', 'adb device offline', { dispatched: 'no' });
337337
const androidObservation: AndroidObservationAdapter = {
338338
...clearAndroidObservationFixture,
339+
readAppFocus: async () => false,
339340
readAppState: async () => {
340341
if (mockTapPoint.mock.calls.length > 0) throw readRefusal;
341342
return { package: 'com.example.app' };

‎packages/platform-android/src/__tests__/snapshot-helper-session.fixtures.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function createPersistentSnapshotHelperProvider(
146146
process.stdout.write(
147147
[
148148
'INSTRUMENTATION_STATUS: agentDeviceProtocol=android-snapshot-helper-v1',
149-
'INSTRUMENTATION_STATUS: sessionCommands=input,screenshot,focus,snapshot-immediate',
149+
`INSTRUMENTATION_STATUS: sessionCommands=${options.sessionInput ? 'input,' : ''}snapshot-immediate`,
150150
'INSTRUMENTATION_STATUS: sessionReady=true',
151151
'INSTRUMENTATION_STATUS_CODE: 2',
152152
'',
@@ -280,7 +280,7 @@ export function createSessionProvider(options: SessionProviderOptions): AndroidA
280280
process.stdout.write(
281281
[
282282
'INSTRUMENTATION_STATUS: agentDeviceProtocol=android-snapshot-helper-v1',
283-
'INSTRUMENTATION_STATUS: sessionCommands=input,screenshot,focus,snapshot-immediate',
283+
'INSTRUMENTATION_STATUS: sessionCommands=snapshot-immediate',
284284
'INSTRUMENTATION_STATUS: sessionReady=true',
285285
'INSTRUMENTATION_STATUS_CODE: 2',
286286
'',

‎packages/platform-android/src/__tests__/snapshot.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ afterEach(async () => {
112112
await resetAndroidSnapshotHelperSessions();
113113
});
114114

115-
test('screenshotAndroid waits for transient UI to settle before capture', async () => {
115+
test('screenshotAndroid waits for transient UI when stabilization is requested', async () => {
116116
const events: string[] = [];
117117
await withTempScreenshot('screenshot-settle-', async (outPath) => {
118118
mockScreenshotEvents(events);
119-
await screenshotAndroid(device, outPath);
119+
await screenshotAndroid(device, outPath, { stabilize: true });
120120

121121
// Demo mode is one setting and two broadcasts, all before the settle.
122122
assert.deepEqual(events, ['enable', 'enable', 'enable', 'settle:1000', 'capture', 'disable']);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { runAndroidShell } from './adb.ts';
2828
import { androidAdbResultError, discloseAdbInputDispatch } from './adb-failure.ts';
2929
import { executeAndroidTouchPlan, readAndroidGestureViewportReading } from './touch-executor.ts';
3030
import type { AndroidHelperSessionOptions } from './snapshot-helper-types.ts';
31-
import { runAndroidAutomationHelper } from './automation-helper.ts';
3231

3332
export async function pressAndroid(device: DeviceInfo, x: number, y: number): Promise<void> {
33+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
3434
try {
3535
if (await runAndroidAutomationHelper(device, 'input', { kind: 'tap', x, y })) return;
3636
await runAndroidShell(device, ['input', 'tap', x, y]);
@@ -60,16 +60,19 @@ export async function pressAndroidTvRemote(
6060
}
6161

6262
export async function backAndroid(device: DeviceInfo): Promise<void> {
63+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
6364
if (await runAndroidAutomationHelper(device, 'input', { kind: 'key', keyCode: 4 })) return;
6465
await runAndroidShell(device, ['input', 'keyevent', '4']);
6566
}
6667

6768
export async function homeAndroid(device: DeviceInfo): Promise<void> {
69+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
6870
if (await runAndroidAutomationHelper(device, 'input', { kind: 'key', keyCode: 3 })) return;
6971
await runAndroidShell(device, ['input', 'keyevent', '3']);
7072
}
7173

7274
export async function pressAndroidEnter(device: DeviceInfo): Promise<void> {
75+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
7376
if (await runAndroidAutomationHelper(device, 'input', { kind: 'key', keyCode: 66 })) return;
7477
await runAndroidShell(device, ['input', 'keyevent', 'ENTER']);
7578
}
@@ -187,6 +190,7 @@ export async function probeAndroidDisplayRotation(
187190
}
188191

189192
export async function appSwitcherAndroid(device: DeviceInfo): Promise<void> {
193+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
190194
if (await runAndroidAutomationHelper(device, 'input', { kind: 'key', keyCode: 187 })) return;
191195
await runAndroidShell(device, ['input', 'keyevent', '187']);
192196
}

‎packages/platform-android/src/observation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-ru
77
import type { DeviceInfo } from '@agent-device/kernel/device';
88
import { deviceShellArgv } from '@agent-device/kernel/device-shell';
99
import { AppError } from '@agent-device/kernel/errors';
10-
import { runAndroidAutomationHelper } from './automation-helper.ts';
1110
import {
1211
ANDROID_FOCUS_MARKERS,
1312
ANDROID_FOCUSED_WINDOW_MARKER,
@@ -44,6 +43,7 @@ export function createAndroidObservationAdapter(
4443
readAppState: async (device) => await readAppState(host, device),
4544
readBlockingDialog: async (device) => await readBlockingDialog(host, device),
4645
async readAppFocus(device, appBundleId, options = {}) {
46+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
4747
const focus = await runAndroidAutomationHelper(device, 'focus');
4848
if (focus?.focusedPackage === appBundleId && focus.windowType === '1') return true;
4949
const read = createDumpReader(host, device);
@@ -113,6 +113,7 @@ async function readBlockingDialog(
113113
device: DeviceInfo,
114114
read: DumpReader = createDumpReader(host, device),
115115
): Promise<AndroidBlockingDialogObservation> {
116+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
116117
const focus = await runAndroidAutomationHelper(device, 'focus');
117118
if (focus?.windowType === '1' && focus.focusedPackage && focus.focusedPackage !== 'android') {
118119
return { status: 'clear' };

‎packages/platform-android/src/screenshot.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { ShellWord } from '@agent-device/kernel/device-shell';
55
import { runAndroidExecOut, runAndroidShell, sleep } from './adb.ts';
66
import { requireAndroidAdbHost } from './adb-host.ts';
77
import { probeAndroidDisplayRotation } from './input-actions.ts';
8-
import { runAndroidAutomationHelper } from './automation-helper.ts';
98

109
// PNG file signature: 0x89 P N G \r \n 0x1A \n
1110
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
@@ -100,6 +99,7 @@ async function settledWithin<T>(pending: Promise<T>, graceMs: number): Promise<T
10099
}
101100

102101
async function captureAndroidScreenshot(device: DeviceInfo, outPath: string): Promise<void> {
102+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
103103
const helper = await runAndroidAutomationHelper(device, 'screenshot');
104104
const bytes = helper
105105
? Buffer.from(helper.payloadBase64 ?? '', 'base64')

‎packages/platform-android/src/text-input.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { getAndroidTestImeOwnership } from './ime-state.ts';
3636
import { discloseAdbInputDispatch } from './adb-failure.ts';
3737
import { focusAndroid } from './input-actions.ts';
3838
import type { AndroidHelperSessionOptions } from './snapshot-helper-types.ts';
39-
import { runAndroidAutomationHelper } from './automation-helper.ts';
4039

4140
/**
4241
* `input text` truncates long strings in some app/IME states (#531), so ASCII is written in short
@@ -85,6 +84,7 @@ export async function fillAndroid(
8584
const verification = await verifyAndroidFilledText(device, x, y, text, helper);
8685
return completeAndroidFillVerification(text, beforeTarget, verification);
8786
}
87+
const { runAndroidAutomationHelper } = await import('./automation-helper.ts');
8888
if (
8989
delayMs === 0 &&
9090
(await runAndroidAutomationHelper(device, 'input', { kind: 'fill', x, y, text }))

‎packages/platform-android/src/touch-helper.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
prepareAndroidAutomationHelper,
3-
androidAutomationHelperIdentity,
4-
} from './automation-helper-artifact.ts';
51
import type { PointerTrajectory } from '@agent-device/contracts/gesture-plan-types';
62
import type { DeviceInfo } from '@agent-device/kernel/device';
73
import type { Rect } from '@agent-device/kernel/snapshot';
@@ -57,6 +53,8 @@ export async function executeAndroidTouchHelperPlan(
5753
device: DeviceInfo,
5854
plan: AndroidLoweredTouchPlan,
5955
): Promise<Record<string, unknown>> {
56+
const { prepareAndroidAutomationHelper, androidAutomationHelperIdentity } =
57+
await import('./automation-helper-artifact.ts');
6058
const prepared = await prepareAndroidAutomationHelper(device);
6159
const request = normalizeAndroidTouchHelperGestureRequest(plan);
6260
const timeoutMs = Math.max(
@@ -111,6 +109,8 @@ export async function readAndroidTouchHelperViewportReading(
111109
device: DeviceInfo,
112110
helper: AndroidHelperSessionOptions = {},
113111
): Promise<AndroidGestureViewportReading> {
112+
const { prepareAndroidAutomationHelper, androidAutomationHelperIdentity } =
113+
await import('./automation-helper-artifact.ts');
114114
const prepared = await prepareAndroidAutomationHelper(device);
115115
if (helper.helperSessionScope === 'daemon-session') {
116116
// Without a live session both this read and the gesture that follows would each start their

‎src/commands/schema/cli-help-command-usage.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ test('usageForCommand documents screenshot web aliases and stabilization flags',
2525
assert.match(help, /--fullscreen, --full, -f/);
2626
assert.match(help, /entire page/i);
2727
assert.match(help, /--no-stabilize/);
28-
assert.match(help, /low-latency Android capture loops/);
28+
assert.match(help, /Android captures immediately by default/);
2929
assert.match(help, /--normalize-status-bar/);
30-
assert.match(help, /deterministic iOS simulator chrome/);
30+
assert.match(help, /deterministic iOS simulator or Android chrome/);
3131
assert.match(help, /--crop-on <selector-expression>/);
3232
assert.match(help, /crop the capture to the frame of the selector/);
3333
});

0 commit comments

Comments
 (0)