Skip to content

Commit 3847f71

Browse files
authored
perf: avoid android hierarchy probe for scroll (#671)
1 parent 66119e2 commit 3847f71

2 files changed

Lines changed: 2 additions & 35 deletions

File tree

src/platforms/android/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ test('scrollAndroid supports explicit pixel travel distance', async () => {
316316
const args = await fs.readFile(argsLogPath, 'utf8');
317317

318318
assert.match(args, /shell\ninput\nswipe\n540\n1080\n540\n840\n300\n/);
319+
assert.doesNotMatch(args, /uiautomator|dump/);
319320
assert.equal(result.pixels, 240);
320321
assert.equal(result.referenceWidth, 1080);
321322
assert.equal(result.referenceHeight, 1920);

src/platforms/android/input-actions.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { buildScrollGesturePlan, type ScrollDirection } from '../../core/scroll-
66
import { runAndroidAdb, sleep } from './adb.ts';
77
import { resolveAndroidTextInjector } from './adb-executor.ts';
88
import { getAndroidKeyboardState, type AndroidKeyboardState } from './device-input-state.ts';
9-
import { captureAndroidUiHierarchyXml } from './snapshot.ts';
10-
import { androidUiNodes } from './ui-hierarchy.ts';
119
import {
1210
androidFillFailureDetails,
1311
androidFillFailureMessage,
@@ -208,7 +206,7 @@ export async function scrollAndroid(
208206
direction: ScrollDirection,
209207
options?: { amount?: number; pixels?: number },
210208
): Promise<Record<string, unknown>> {
211-
const size = await getAndroidGestureViewportSize(device);
209+
const size = await getAndroidScreenSize(device);
212210
const plan = buildScrollGesturePlan({
213211
direction,
214212
amount: options?.amount,
@@ -292,38 +290,6 @@ export async function getAndroidScreenSize(
292290
return { width: Number(match[1]), height: Number(match[2]) };
293291
}
294292

295-
async function getAndroidGestureViewportSize(
296-
device: DeviceInfo,
297-
): Promise<{ width: number; height: number }> {
298-
try {
299-
const xml = await captureAndroidUiHierarchyXml(device);
300-
const viewport = largestAndroidUiNodeRect(xml);
301-
if (viewport) return viewport;
302-
} catch (error) {
303-
emitDiagnostic({
304-
level: 'warn',
305-
phase: 'android_gesture_viewport_probe_failed',
306-
data: {
307-
error: error instanceof Error ? error.message : String(error),
308-
},
309-
});
310-
}
311-
return await getAndroidScreenSize(device);
312-
}
313-
314-
function largestAndroidUiNodeRect(xml: string): { width: number; height: number } | null {
315-
let largest: { width: number; height: number; area: number } | null = null;
316-
for (const node of androidUiNodes(xml)) {
317-
const rect = node.rect;
318-
if (!rect || rect.width <= 0 || rect.height <= 0) continue;
319-
const area = rect.width * rect.height;
320-
if (!largest || area > largest.area) {
321-
largest = { width: rect.x + rect.width, height: rect.y + rect.height, area };
322-
}
323-
}
324-
return largest ? { width: largest.width, height: largest.height } : null;
325-
}
326-
327293
const ANDROID_INPUT_TEXT_CHUNK_SIZE = 8;
328294

329295
async function typeAndroidShell(

0 commit comments

Comments
 (0)