Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
60a9984
fix(android): let press reach a foreign app-error dialog's own buttons
kdy1 Nov 26, 2026
956ac70
fix(android): confirm the dialog still has focus before a dialog-butt…
kdy1 Nov 26, 2026
6541ab1
test(android): cover the wait for the dialog focus to clear after a b…
kdy1 Nov 26, 2026
cf6cbbe
fix(android): find app-error dialog buttons in any device language
kdy1 Nov 26, 2026
dd9d8ce
fix(android): exclude a dialog button's right and bottom edges from i…
kdy1 Nov 26, 2026
c839572
fix(android): report dispatched: no when a foreign dialog refuses a c…
kdy1 Nov 26, 2026
329a042
fix(android): refuse a dialog-button tap for a target resolved on an …
kdy1 Nov 26, 2026
bd29004
fix(android): disclose and name each failed focus check before a dial…
kdy1 Nov 26, 2026
78e8721
fix(android): keep alert dismiss out of the foreign-dialog refusal hint
kdy1 Nov 26, 2026
c58a596
fix(android): record why a dialog-button tap found no buttons to admit
kdy1 Nov 26, 2026
7a64d3d
test(android): cover each input shape the dialog-button exception adm…
kdy1 Nov 26, 2026
1f9bfea
fix(android): require the same dialog button at the tap point in both…
kdy1 Nov 26, 2026
09fa660
fix(android): keep the recovery hint when no dialog button can be pre…
kdy1 Nov 26, 2026
f399a1d
test(android): stop the dialog-button readiness tests from waiting re…
kdy1 Nov 26, 2026
5914ddc
docs(android): document the press exception for a foreign ANR dialog
kdy1 Nov 26, 2026
57dc331
refactor(android): pass the dialog tap gate without a branch
kdy1 Nov 26, 2026
20c4c99
fix(mcp): fit the ANR press note in the always-loaded tool budget
kdy1 Nov 26, 2026
808897e
fix(android): send a refused dialog press to a new snapshot first
kdy1 Nov 26, 2026
db76959
docs(android): say which commands a foreign ANR dialog refuses
kdy1 Nov 26, 2026
45b7fa1
refactor(android): check a foreign ANR dialog press once, before disp…
kdy1 Nov 26, 2026
47385f2
fix(android): refuse a held or jittered press on a foreign ANR dialog
kdy1 Nov 26, 2026
93bbc98
fix(android): keep the post-press app check after a dialog button
kdy1 Nov 26, 2026
7ac2567
fix(android): keep the recovery hint for a non-press foreign-dialog r…
kdy1 Nov 26, 2026
75e0e34
test(android): assert the dialog context in each foreign-dialog refusal
kdy1 Nov 26, 2026
3fa8025
docs(android): name the two buttons a foreign ANR dialog admits
kdy1 Nov 26, 2026
575cfca
fix(android): check a dialog-button ref in the tree that issued it
kdy1 Nov 26, 2026
2b00c50
docs(android): say where the dialog focus is confirmed
kdy1 Nov 26, 2026
3d44215
fix(android): recognize the ANR dialog's aerr buttons as dialog buttons
kdy1 Nov 26, 2026
0f047ad
fix(android): find the session app ANR's Close app by its framework id
kdy1 Nov 26, 2026
de93c97
refactor(android): drop the press admission for a foreign ANR dialog
kdy1 Nov 26, 2026
c19df5d
refactor(android): find the ANR dialog by its button ids in the daemon
kdy1 Nov 26, 2026
63e82ac
fix(android): let alert close or wait on an ANR dialog in any language
kdy1 Nov 26, 2026
6b57b42
fix(android): name alert in the refusal hint for another app's ANR
kdy1 Nov 26, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ test('recovery taps the reachable Close app, not a covered one that comes first'
index: 0,
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 300, width: 200, height: 80 },
};
Expand All @@ -75,12 +76,27 @@ test('recovery taps the reachable Close app, not a covered one that comes first'
index: 3,
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 1800, width: 200, height: 80 },
};
const visibleWait = {
index: 4,
type: 'Button',
label: 'Wait',
identifier: 'android:id/aerr_wait',
hittable: true,
rect: { x: 40, y: 1900, width: 200, height: 80 },
};
vi.mocked(snapshotAndroid)
.mockResolvedValueOnce(
makeAndroidSnapshotCapture([staleCloseApp, sheet, dialog, visibleCloseApp]) as never,
makeAndroidSnapshotCapture([
staleCloseApp,
sheet,
dialog,
visibleCloseApp,
visibleWait,
]) as never,
)
.mockResolvedValue(makeAndroidSnapshotCapture([]) as never);
vi.mocked(runAndroidAdb).mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' } as never);
Expand All @@ -106,11 +122,25 @@ test('a fully covered dialog does not trigger recovery', async () => {
index: 1,
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 300, width: 200, height: 80 },
};
const staleWait = {
index: 2,
type: 'Button',
label: 'Wait',
identifier: 'android:id/aerr_wait',
hittable: true,
rect: { x: 40, y: 400, width: 200, height: 80 },
};
vi.mocked(snapshotAndroid).mockResolvedValue(
makeAndroidSnapshotCapture([staleDialog, staleCloseApp, foregroundSheet(2)]) as never,
makeAndroidSnapshotCapture([
staleDialog,
staleCloseApp,
staleWait,
foregroundSheet(3),
]) as never,
);
vi.mocked(runAndroidAdb).mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' } as never);

Expand All @@ -135,6 +165,7 @@ test('collectively covered Close app is neither selected nor tapped', async () =
parentIndex: 0,
type: 'android.widget.Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 300, width: 200, height: 80 },
},
Expand Down Expand Up @@ -190,3 +221,63 @@ test('collectively covered Close app is neither selected nor tapped', async () =
expect(result.status).toBe('absent');
expect(tappedPoints()).toEqual([]);
});

test('an ANR dialog in another language is found and closed by its button ids', async () => {
vi.mocked(runAndroidAdb).mockReset();
vi.mocked(snapshotAndroid)
.mockResolvedValueOnce(
makeAndroidSnapshotCapture([
{ index: 0, type: 'TextView', label: 'Demo reagiert nicht', rect: SCREEN },
{
index: 1,
type: 'Button',
label: 'App schließen',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 1800, width: 200, height: 80 },
},
{
index: 2,
type: 'Button',
label: 'Warten',
identifier: 'android:id/aerr_wait',
hittable: true,
rect: { x: 40, y: 1900, width: 200, height: 80 },
},
]) as never,
)
.mockResolvedValue(makeAndroidSnapshotCapture([]) as never);
vi.mocked(runAndroidAdb).mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' } as never);

const result = await recoverAndroidBlockingSystemDialog({
session: recordingSession('anr-localized'),
});

expect(result.status).toBe('recovered');
expect(tappedPoints()).toEqual([{ x: 140, y: 1840 }]);
});

test('a crash dialog, which has Close app but no Wait, is not treated as an ANR', async () => {
vi.mocked(runAndroidAdb).mockReset();
vi.mocked(snapshotAndroid).mockResolvedValue(
makeAndroidSnapshotCapture([
{ index: 0, type: 'TextView', label: 'Demo keeps stopping', rect: SCREEN },
{
index: 1,
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 40, y: 1800, width: 200, height: 80 },
},
]) as never,
);
vi.mocked(runAndroidAdb).mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' } as never);

const result = await recoverAndroidBlockingSystemDialog({
session: recordingSession('crash-dialog'),
});

expect(result.status).toBe('absent');
expect(tappedPoints()).toEqual([]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function anrDialogNodes(): RawSnapshotNode[] {
index: 1,
type: 'android.widget.Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
rect: CLOSE_APP_RECT,
},
];
Expand Down Expand Up @@ -169,6 +170,30 @@ test('an ANR that surfaces between two commands is recovered by the next pre-dis
expect(tapCalls(calls)).toEqual([CLOSE_APP_TAP]);
});

test("the session app's ANR is recovered on a device in another language", async () => {
// Recovery finds Close app by its framework id, so a translated label does not hide it.
const session = makeAndroidSession('readiness-anr-localized', { appBundleId: APP });
const [title, closeApp] = anrDialogNodes();
screenNodes = [
{ ...title!, label: `${APP} reagiert nicht` },
{ ...closeApp!, label: 'App schließen' },
];
const { observation, calls } = makeObservation(anrFocus);

const readiness = await ensureAndroidBlockingSystemDialogReady({
session,
command: 'tap',
phase: 'before-command',
observation,
});

expect(readiness).toEqual({
status: 'recovered',
warning: `Recovered Android app ANR before tap: closed and relaunched ${APP}.`,
});
expect(tapCalls(calls)).toEqual([CLOSE_APP_TAP]);
});

test('an ANR whose Close app is covered is not tapped, and recovery reports failure', async () => {
// #1832: recovery reads the presentation's occlusion result, so a "Close app" that a foreground
// surface covers is unreachable. Tapping it anyway would land the tap on whatever is on top.
Expand Down Expand Up @@ -209,7 +234,12 @@ test('a system dialog that surfaces between two commands blocks the next command
phase: 'before-command',
observation,
}),
).rejects.toMatchObject({ code: 'COMMAND_FAILED' });
).rejects.toMatchObject({
code: 'COMMAND_FAILED',
details: {
hint: 'Run alert dismiss to close the app that is not responding, or alert accept to wait for it, then retry.',
},
});
});

test('an ANR the command itself provoked still fails that command', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ test('android blocking-dialog recovery expires the ref frame before its recovery
index: 1,
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
hittable: true,
rect: { x: 20, y: 200, width: 120, height: 44 },
};
const wait = {
index: 2,
type: 'Button',
label: 'Wait',
identifier: 'android:id/aerr_wait',
hittable: true,
rect: { x: 20, y: 260, width: 120, height: 44 },
};
// First read: the blocking dialog is present (drives recovery). Post-tap poll:
// the dialog is gone, so recovery completes without sleeping through retries.
vi.mocked(snapshotAndroid)
.mockResolvedValueOnce(makeAndroidSnapshotCapture([dialog, closeApp]) as never)
.mockResolvedValueOnce(makeAndroidSnapshotCapture([dialog, closeApp, wait]) as never)
.mockResolvedValue(makeAndroidSnapshotCapture([]) as never);
vi.mocked(runAndroidAdb).mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' } as never);

Expand Down
55 changes: 21 additions & 34 deletions packages/daemon/src/execution/android-system-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ import { expireRefFrame } from '../core/ref-frame.ts';
import type { SessionState } from '../core/session-state.ts';
import { isActiveProviderDevice } from '../core/provider-device-admission.ts';

const ANDROID_BLOCKING_MODAL_PATTERN = /\bis(?:n(?:'|'|')?t| not)\s+responding\b/i;
const ANDROID_CLOSE_APP_PATTERN = /^close app$/i;
/**
* The framework ids of the ANR dialog's Close app and Wait buttons. They do not depend on the
* device language, and only the ANR dialog has Wait: the crash dialog also has Close app.
*/
const ANDROID_ANR_CLOSE_BUTTON_ID = 'android:id/aerr_close';
const ANDROID_ANR_WAIT_BUTTON_ID = 'android:id/aerr_wait';
const ANDROID_MODAL_POLL_MS = 500;
const ANDROID_MODAL_POLL_ATTEMPTS = 12;
const ANDROID_BLOCKING_DIALOG_HINT =
'Wait for Android to recover, close the dialog, restart the app, or reboot the emulator, then retry.';
/** `alert` is not stopped by this guard, and it presses the ANR dialog's buttons by their ids. */
const ANDROID_FOREIGN_ANR_HINT =
'Run alert dismiss to close the app that is not responding, or alert accept to wait for it, then retry.';
const ANDROID_BLOCKING_DIALOG_INSPECTION_WARNING =
'Android blocking-dialog readiness could not be inspected; the command continued.';
const ANDROID_BLOCKING_DIALOG_WARNING_TEXT_LIMIT = 240;
Expand Down Expand Up @@ -232,7 +239,7 @@ export async function ensureAndroidBlockingSystemDialogReady(params: {
command,
focus,
message: `Android system dialog is blocking ${command}: ${formatAndroidBlockingDialogFocus(focus)}.`,
hint: ANDROID_BLOCKING_DIALOG_HINT,
hint: ANDROID_FOREIGN_ANR_HINT,
});
}

Expand Down Expand Up @@ -379,11 +386,16 @@ function findCloseAppButton(
if (options.requireDialogSignal !== false && !containsBlockingDialog(nodes)) {
return undefined;
}
return nodes.filter(isTouchableDialogNode).find((node) => {
return (
readNodeTextParts(node).some((text) => ANDROID_CLOSE_APP_PATTERN.test(text)) && node.rect
);
});
return findTouchableDialogButton(nodes, ANDROID_ANR_CLOSE_BUTTON_ID);
}

function findTouchableDialogButton(
nodes: SnapshotNode[],
identifier: string,
): SnapshotNode | undefined {
return nodes.find(
(node) => node.identifier === identifier && node.rect && isTouchableDialogNode(node),
);
}

/** A node the recovery tap can actually reach: present in the tree and not covered by a surface above it. */
Expand Down Expand Up @@ -439,31 +451,6 @@ function isProviderOwnedSession(session: SessionState): boolean {
return Boolean(session.lease?.leaseProvider) || isActiveProviderDevice(session.device);
}

function readNodeText(node: {
label?: string;
value?: string | number | boolean | null;
identifier?: string;
}): string {
return readNodeTextParts(node).join(' ').trim();
}

function readNodeTextParts(node: {
label?: string;
value?: string | number | boolean | null;
identifier?: string;
}): string[] {
const parts = [node.label, node.identifier];
if (typeof node.value === 'string' && node.value.trim().length > 0) {
parts.push(node.value);
}
return parts
.filter((part): part is string => typeof part === 'string' && part.trim().length > 0)
.map((part) => part.trim());
}

function containsBlockingDialog(nodes: SnapshotNode[]): boolean {
return nodes.filter(isTouchableDialogNode).some((node) => {
const text = readNodeText(node);
return text.length > 0 && ANDROID_BLOCKING_MODAL_PATTERN.test(text);
});
return findTouchableDialogButton(nodes, ANDROID_ANR_WAIT_BUTTON_ID) !== undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ async function refRefusedAfterAndroidRecovery(command: 'press' | 'gesture'): Pro
ref: 'e0',
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
rect: { x: 10, y: 20, width: 100, height: 40 },
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ for (const canceled of [false, true]) {
ref: 'e0',
type: 'Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
rect: { x: 10, y: 20, width: 100, height: 40 },
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ vi.mock('@agent-device/platform-android/mechanics', async (importOriginal) => {
index: 1,
type: 'android.widget.Button',
label: 'Close app',
identifier: 'android:id/aerr_close',
rect: { x: 100, y: 600, width: 220, height: 80 },
},
{
index: 2,
type: 'android.widget.Button',
label: 'Wait',
identifier: 'android:id/aerr_wait',
rect: { x: 100, y: 700, width: 220, height: 80 },
},
]);
}
return capture([]);
Expand Down
20 changes: 20 additions & 0 deletions packages/platform-android/src/__tests__/alert-detection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,23 @@ test('shared Apple label additions also name ordinary Android dialog actions', (
);
}
});

test('an ANR dialog in another language is found, and its buttons are chosen, by their ids', () => {
const system = { bundleId: 'android' };
const candidate = findAndroidAlertCandidate([
node(0, 'android.widget.FrameLayout', system),
node(1, 'android.widget.TextView', {
...system,
label: 'System UI reagiert nicht',
identifier: 'android:id/alertTitle',
}),
{ ...button(2, 'App schließen', 'android:id/aerr_close', { x: 70, y: 1210 }), ...system },
{ ...button(3, 'Warten', 'android:id/aerr_wait', { x: 70, y: 1336 }), ...system },
]);

assert.equal(candidate?.alert.source, 'system-dialog');
assert.equal(candidate?.alert.title, 'System UI reagiert nicht');
const buttons = candidate?.buttons ?? [];
assert.equal(chooseAndroidAlertButton(buttons, 'dismiss')?.label, 'App schließen');
assert.equal(chooseAndroidAlertButton(buttons, 'accept')?.label, 'Warten');
});
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,43 @@ test('keeps a recognized system dialog without window metadata', () => {
expect(decision).toBeUndefined();
});

test('keeps an ANR dialog whose buttons carry the framework aerr ids', () => {
// The ANR dialog (`AppNotRespondingDialog`) names its buttons aerr_close and aerr_wait, not
// button1..3, in every device language.
const decision = unusableDecisionFor(
helperXml([
node({
text: 'System UI reagiert nicht',
resourceId: 'android:id/alertTitle',
packageName: 'com.android.systemui',
className: 'android.widget.TextView',
}),
node({
text: 'App schließen',
resourceId: 'android:id/aerr_close',
packageName: 'com.android.systemui',
className: 'android.widget.Button',
}),
node({
text: 'Warten',
resourceId: 'android:id/aerr_wait',
packageName: 'com.android.systemui',
className: 'android.widget.Button',
}),
]),
{
backend: 'android-helper',
nodeCount: 3,
rootPresent: true,
windowCount: 1,
captureMode: 'interactive-windows',
},
{ foregroundAppPackage: 'com.pagerviewexample' },
);

expect(decision).toBeUndefined();
});

test('rejects system chrome inherited under an empty application window', () => {
const decision = unusableDecisionFor(
helperXml([
Expand Down
Loading
Loading