Skip to content

Commit 144bd59

Browse files
wongcallumclaude
andauthored
fix(android): keep popup windows above the active window in snapshots (#4037)
* fix(android): keep popup windows above the active window in snapshots A popup that does not take focus, such as an AutoCompleteTextView dropdown, is an application window that is neither active nor focused. The stale-window filter hid every such window, so the popup's items were missing from snapshots and selectors could not match them. Keep inactive application windows that sit above the foreground application layer: they are drawn over it, so they are not hidden from users. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(android): inline the single-use window layer comparison * test(android): pin stale windows at or below the active layer as hidden --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 9e4bc2d commit 144bd59

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎packages/platform-android/src/ui-hierarchy-visibility.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function collectInactiveApplicationWindows(
5555

5656
// Android can keep stale application windows in the accessibility tree after drawer and
5757
// navigation transitions. Keep dialogs/system windows, but expose only the foreground
58-
// application layer so agents do not act on content that is hidden from users.
58+
// application layer and the windows above it, so agents do not act on content that is hidden
59+
// from users. A popup that does not take focus sits above that layer but is never active or
60+
// focused.
5961
const foregroundApplicationWindows = windows.filter(
6062
(window) => isAndroidApplicationWindow(window) && isAndroidForegroundWindow(window),
6163
);
@@ -66,8 +68,11 @@ function collectInactiveApplicationWindows(
6668
presentationBudget?.check('work');
6769
if (!isAndroidApplicationWindow(window)) continue;
6870
const keep =
69-
isAndroidForegroundWindow(window) &&
70-
(foregroundLayer === undefined || window.windowLayer === foregroundLayer);
71+
(foregroundLayer !== undefined &&
72+
window.windowLayer !== undefined &&
73+
window.windowLayer > foregroundLayer) ||
74+
(isAndroidForegroundWindow(window) &&
75+
(foregroundLayer === undefined || window.windowLayer === foregroundLayer));
7176
if (!keep) hidden.add(window);
7277
}
7378
}

‎src/__tests__/android-ui-hierarchy.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,29 @@ test('parseUiHierarchy keeps only the top active Android application window', ()
358358
);
359359
});
360360

361+
test('parseUiHierarchy keeps an inactive Android popup window above the active window only', () => {
362+
const xml = `<hierarchy>
363+
<node class="android.widget.FrameLayout" package="com.example.app" bounds="[0,0][390,844]" window-index="0" window-type="1" window-layer="0" window-active="false" window-focused="false" window-bounds="[0,0][390,844]">
364+
<node class="android.widget.TextView" text="Stale below content" bounds="[10,300][200,340]" enabled="true"/>
365+
</node>
366+
<node class="android.widget.FrameLayout" package="com.example.app" bounds="[0,0][390,844]" window-index="1" window-type="1" window-layer="1" window-active="false" window-focused="false" window-bounds="[0,0][390,844]">
367+
<node class="android.widget.TextView" text="Stale same-layer content" bounds="[10,400][200,440]" enabled="true"/>
368+
</node>
369+
<node class="android.widget.FrameLayout" package="com.example.app" bounds="[0,0][390,844]" window-index="2" window-type="1" window-layer="1" window-active="true" window-focused="true" window-bounds="[0,0][390,844]">
370+
<node class="android.widget.AutoCompleteTextView" text="a" bounds="[10,20][380,80]" enabled="true" focused="true"/>
371+
</node>
372+
<node class="android.widget.FrameLayout" package="com.example.app" bounds="[10,80][380,200]" window-index="3" window-type="1" window-layer="2" window-active="false" window-focused="false" window-bounds="[10,80][380,200]">
373+
<node class="android.widget.TextView" text="alpha" bounds="[10,80][380,140]" clickable="true" enabled="true"/>
374+
</node>
375+
</hierarchy>`;
376+
377+
const result = parseUiHierarchy(xml, 800, {});
378+
const labels = new Set(result.nodes.map((node) => node.label));
379+
assert.equal(labels.has('alpha'), true);
380+
assert.equal(labels.has('Stale same-layer content'), false);
381+
assert.equal(labels.has('Stale below content'), false);
382+
});
383+
361384
test('parseUiHierarchy excludes Android nodes that are not visible to the user', () => {
362385
const xml = `<hierarchy>
363386
<node class="android.widget.FrameLayout" bounds="[0,0][390,844]" enabled="true" visible-to-user="true">

0 commit comments

Comments
 (0)