Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/platforms/android/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ test('scrollAndroid supports explicit pixel travel distance', async () => {
const args = await fs.readFile(argsLogPath, 'utf8');

assert.match(args, /shell\ninput\nswipe\n540\n1080\n540\n840\n300\n/);
assert.doesNotMatch(args, /uiautomator|dump/);
assert.equal(result.pixels, 240);
assert.equal(result.referenceWidth, 1080);
assert.equal(result.referenceHeight, 1920);
Expand Down
36 changes: 1 addition & 35 deletions src/platforms/android/input-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { buildScrollGesturePlan, type ScrollDirection } from '../../core/scroll-
import { runAndroidAdb, sleep } from './adb.ts';
import { resolveAndroidTextInjector } from './adb-executor.ts';
import { getAndroidKeyboardState, type AndroidKeyboardState } from './device-input-state.ts';
import { captureAndroidUiHierarchyXml } from './snapshot.ts';
import { androidUiNodes } from './ui-hierarchy.ts';
import {
androidFillFailureDetails,
androidFillFailureMessage,
Expand Down Expand Up @@ -208,7 +206,7 @@ export async function scrollAndroid(
direction: ScrollDirection,
options?: { amount?: number; pixels?: number },
): Promise<Record<string, unknown>> {
const size = await getAndroidGestureViewportSize(device);
const size = await getAndroidScreenSize(device);
const plan = buildScrollGesturePlan({
direction,
amount: options?.amount,
Expand Down Expand Up @@ -292,38 +290,6 @@ export async function getAndroidScreenSize(
return { width: Number(match[1]), height: Number(match[2]) };
}

async function getAndroidGestureViewportSize(
device: DeviceInfo,
): Promise<{ width: number; height: number }> {
try {
const xml = await captureAndroidUiHierarchyXml(device);
const viewport = largestAndroidUiNodeRect(xml);
if (viewport) return viewport;
} catch (error) {
emitDiagnostic({
level: 'warn',
phase: 'android_gesture_viewport_probe_failed',
data: {
error: error instanceof Error ? error.message : String(error),
},
});
}
return await getAndroidScreenSize(device);
}

function largestAndroidUiNodeRect(xml: string): { width: number; height: number } | null {
let largest: { width: number; height: number; area: number } | null = null;
for (const node of androidUiNodes(xml)) {
const rect = node.rect;
if (!rect || rect.width <= 0 || rect.height <= 0) continue;
const area = rect.width * rect.height;
if (!largest || area > largest.area) {
largest = { width: rect.x + rect.width, height: rect.y + rect.height, area };
}
}
return largest ? { width: largest.width, height: largest.height } : null;
}

const ANDROID_INPUT_TEXT_CHUNK_SIZE = 8;

async function typeAndroidShell(
Expand Down
Loading