diff --git a/packages/capture-kit/src/snapshot/snapshot-presentation/android/helper.test.ts b/packages/capture-kit/src/snapshot/snapshot-presentation/android/helper.test.ts new file mode 100644 index 0000000000..adb8978382 --- /dev/null +++ b/packages/capture-kit/src/snapshot/snapshot-presentation/android/helper.test.ts @@ -0,0 +1,99 @@ +import { expect, test } from 'vitest'; +import type { SnapshotNode } from '@agent-device/kernel/snapshot'; +import { buildAndroidHelperPresentationInput } from './helper.ts'; +import settingsHome from './settings-home.fixture.json' with { type: 'json' }; + +const helperData = { androidSnapshot: { backend: 'android-helper' } }; + +test('Settings categories retain separate actionable refs inside nested scroll containers', () => { + const { nodes } = buildAndroidHelperPresentationInput(helperData, settingsHome.nodes, {}); + + for (const [ref, label] of Object.entries({ + e10: 'Network & internet', + e13: 'Connected devices', + e16: 'Apps', + })) { + expect(nodes.find((node) => node.ref === ref)).toMatchObject({ + label: expect.stringContaining(label), + hittable: true, + }); + } + const outerScroll = nodes.find((node) => node.ref === 'e4'); + expect(outerScroll).toBeDefined(); + expect(outerScroll?.label).toBeUndefined(); +}); + +test('a row keeps its own passive label alongside an independent button', () => { + const input: SnapshotNode[] = [ + { index: 0, type: 'root' }, + { + index: 1, + parentIndex: 0, + type: 'android.view.View', + hittable: true, + rect: { x: 0, y: 0, width: 100, height: 40 }, + }, + { + index: 2, + parentIndex: 1, + type: 'android.widget.TextView', + label: 'Account', + rect: { x: 2, y: 2, width: 50, height: 30 }, + }, + { + index: 3, + parentIndex: 1, + type: 'android.widget.Button', + label: 'Edit', + hittable: true, + rect: { x: 60, y: 2, width: 30, height: 30 }, + }, + ]; + const { nodes } = buildAndroidHelperPresentationInput(helperData, input, {}); + + expect(nodes.find((node) => node.index === 1)?.label).toBe('Account'); + expect(nodes.find((node) => node.index === 3)?.label).toBe('Edit'); + expect(nodes.some((node) => node.index === 2)).toBe(false); +}); + +test.each([ + { type: 'android.widget.EditText', editable: undefined }, + { type: 'com.example.ProfileField', editable: true }, +])('a row does not absorb content owned by an editable $type descendant', (field) => { + const input: SnapshotNode[] = [ + { index: 0, type: 'root' }, + { + index: 1, + parentIndex: 0, + type: 'android.view.View', + hittable: true, + rect: { x: 0, y: 0, width: 200, height: 80 }, + }, + { + index: 2, + parentIndex: 1, + type: 'android.widget.TextView', + label: 'Profile', + rect: { x: 2, y: 2, width: 50, height: 30 }, + }, + { + index: 3, + parentIndex: 1, + ...field, + label: 'Name', + rect: { x: 60, y: 2, width: 100, height: 60 }, + }, + { + index: 4, + parentIndex: 3, + type: 'android.widget.TextView', + label: 'Nested value', + rect: { x: 65, y: 5, width: 90, height: 30 }, + }, + ]; + const { nodes } = buildAndroidHelperPresentationInput(helperData, input, {}); + + expect(nodes.find((node) => node.index === 1)?.label).toBe('Profile'); + expect(nodes.find((node) => node.index === 3)?.label).toBe('Name'); + expect(nodes.find((node) => node.index === 4)?.label).toBe('Nested value'); +}); diff --git a/packages/capture-kit/src/snapshot/snapshot-presentation/android/predicates.ts b/packages/capture-kit/src/snapshot/snapshot-presentation/android/predicates.ts index 2a8aa52433..712f988fcc 100644 --- a/packages/capture-kit/src/snapshot/snapshot-presentation/android/predicates.ts +++ b/packages/capture-kit/src/snapshot/snapshot-presentation/android/predicates.ts @@ -7,7 +7,12 @@ export function isRootNode(node: SnapshotNode): boolean { export function isEditableNode(node: SnapshotNode): boolean { const type = (node.type ?? '').toLowerCase(); const identifier = (node.identifier ?? '').trim().toLowerCase(); - return type.includes('edittext') || type.includes('textfield') || identifier === 'composer'; + return ( + node.editable === true || + type.includes('edittext') || + type.includes('textfield') || + identifier === 'composer' + ); } export function isScrollableNode(node: SnapshotNode): boolean { diff --git a/packages/capture-kit/src/snapshot/snapshot-presentation/android/settings-home.fixture.json b/packages/capture-kit/src/snapshot/snapshot-presentation/android/settings-home.fixture.json new file mode 100644 index 0000000000..8c075c3609 --- /dev/null +++ b/packages/capture-kit/src/snapshot/snapshot-presentation/android/settings-home.fixture.json @@ -0,0 +1,754 @@ +{ + "nodes": [ + { + "index": 0, + "type": "android.widget.ScrollView", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/settings_homepage_container", + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 0, + "width": 1080, + "height": 2337 + }, + "visibleToUser": true, + "depth": 0, + "ref": "e1", + "kind": "scroll-area" + }, + { + "index": 1, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/search_action_bar", + "bundleId": "com.android.settings", + "rect": { + "x": 42, + "y": 157, + "width": 996, + "height": 189 + }, + "visibleToUser": true, + "hittable": true, + "depth": 1, + "parentIndex": 0, + "ref": "e2", + "kind": "group" + }, + { + "index": 2, + "type": "android.widget.TextView", + "label": "Search Settings", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/search_bar_title", + "bundleId": "com.android.settings", + "rect": { + "x": 189, + "y": 216, + "width": 389, + "height": 71 + }, + "visibleToUser": true, + "depth": 2, + "parentIndex": 1, + "ref": "e3", + "kind": "text" + }, + { + "index": 3, + "type": "android.widget.ScrollView", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/main_content_scrollable_container", + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 388, + "width": 1080, + "height": 1949 + }, + "visibleToUser": true, + "hittable": true, + "depth": 1, + "parentIndex": 0, + "hiddenContentBelow": true, + "ref": "e4", + "kind": "scroll-area" + }, + { + "index": 4, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/homepage_container", + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 388, + "width": 1080, + "height": 1949 + }, + "visibleToUser": true, + "hittable": true, + "depth": 2, + "parentIndex": 3, + "ref": "e5", + "kind": "group" + }, + { + "index": 5, + "type": "androidx.recyclerview.widget.RecyclerView", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "com.android.settings:id/recycler_view", + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 388, + "width": 1080, + "height": 1949 + }, + "visibleToUser": true, + "hittable": true, + "depth": 3, + "parentIndex": 4, + "hiddenContentAbove": true, + "ref": "e6", + "kind": "list" + }, + { + "index": 6, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 388, + "width": 1080, + "height": 248 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e7", + "kind": "group" + }, + { + "index": 7, + "type": "android.widget.TextView", + "label": "Google", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 430, + "width": 167, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 6, + "ref": "e8", + "kind": "text" + }, + { + "index": 8, + "type": "android.widget.TextView", + "label": "Services & preferences", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 501, + "width": 379, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 6, + "ref": "e9", + "kind": "text" + }, + { + "index": 9, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 636, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e10", + "kind": "group" + }, + { + "index": 10, + "type": "android.widget.TextView", + "label": "Network & internet", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 678, + "width": 436, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 9, + "ref": "e11", + "kind": "text" + }, + { + "index": 11, + "type": "android.widget.TextView", + "label": "Mobile, Wi\u2011Fi, hotspot", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 749, + "width": 351, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 9, + "ref": "e12", + "kind": "text" + }, + { + "index": 12, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 842, + "width": 1080, + "height": 248 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e13", + "kind": "group" + }, + { + "index": 13, + "type": "android.widget.TextView", + "label": "Connected devices", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 884, + "width": 447, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 12, + "ref": "e14", + "kind": "text" + }, + { + "index": 14, + "type": "android.widget.TextView", + "label": "Bluetooth, pairing", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 955, + "width": 287, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 12, + "ref": "e15", + "kind": "text" + }, + { + "index": 15, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 1090, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e16", + "kind": "group" + }, + { + "index": 16, + "type": "android.widget.TextView", + "label": "Apps", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1132, + "width": 122, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 15, + "ref": "e17", + "kind": "text" + }, + { + "index": 17, + "type": "android.widget.TextView", + "label": "Assistant, recent apps, default apps", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1203, + "width": 585, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 15, + "ref": "e18", + "kind": "text" + }, + { + "index": 18, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 1296, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e19", + "kind": "group" + }, + { + "index": 19, + "type": "android.widget.TextView", + "label": "Notifications", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1338, + "width": 300, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 18, + "ref": "e20", + "kind": "text" + }, + { + "index": 20, + "type": "android.widget.TextView", + "label": "Notification history, conversations", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1409, + "width": 556, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 18, + "ref": "e21", + "kind": "text" + }, + { + "index": 21, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 1502, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e22", + "kind": "group" + }, + { + "index": 22, + "type": "android.widget.TextView", + "label": "Sound & vibration", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1544, + "width": 412, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 21, + "ref": "e23", + "kind": "text" + }, + { + "index": 23, + "type": "android.widget.TextView", + "label": "Volume and haptics", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1615, + "width": 325, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 21, + "ref": "e24", + "kind": "text" + }, + { + "index": 24, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 1708, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e25", + "kind": "group" + }, + { + "index": 25, + "type": "android.widget.TextView", + "label": "Modes", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1750, + "width": 161, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 24, + "ref": "e26", + "kind": "text" + }, + { + "index": 26, + "type": "android.widget.TextView", + "label": "Do Not Disturb, Bedtime", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1821, + "width": 393, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 24, + "ref": "e27", + "kind": "text" + }, + { + "index": 27, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 1914, + "width": 1080, + "height": 206 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e28", + "kind": "group" + }, + { + "index": 28, + "type": "android.widget.TextView", + "label": "Display & touch", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 1956, + "width": 364, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 27, + "ref": "e29", + "kind": "text" + }, + { + "index": 29, + "type": "android.widget.TextView", + "label": "Dark theme, font size, touch", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 2027, + "width": 454, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 27, + "ref": "e30", + "kind": "text" + }, + { + "index": 30, + "type": "android.widget.LinearLayout", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "bundleId": "com.android.settings", + "rect": { + "x": 0, + "y": 2120, + "width": 1080, + "height": 217 + }, + "visibleToUser": true, + "hittable": true, + "depth": 4, + "parentIndex": 5, + "ref": "e31", + "kind": "group" + }, + { + "index": 31, + "type": "android.widget.TextView", + "label": "Wallpaper & style", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/title", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 2162, + "width": 406, + "height": 71 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 30, + "ref": "e32", + "kind": "text" + }, + { + "index": 32, + "type": "android.widget.TextView", + "label": "Colors, themed icons, app grid", + "enabled": true, + "selected": false, + "editable": false, + "password": false, + "hintShowing": false, + "identifier": "android:id/summary", + "bundleId": "com.android.settings", + "rect": { + "x": 210, + "y": 2233, + "width": 496, + "height": 51 + }, + "visibleToUser": true, + "depth": 5, + "parentIndex": 30, + "ref": "e33", + "kind": "text" + } + ] +} diff --git a/packages/capture-kit/src/snapshot/snapshot-presentation/android/structural-noise.ts b/packages/capture-kit/src/snapshot/snapshot-presentation/android/structural-noise.ts index 0aa0fc39ff..0b7949b8ef 100644 --- a/packages/capture-kit/src/snapshot/snapshot-presentation/android/structural-noise.ts +++ b/packages/capture-kit/src/snapshot/snapshot-presentation/android/structural-noise.ts @@ -113,7 +113,17 @@ function collectPromotableRowContent( const labels: string[] = []; const removableIndexes: number[] = []; const seen = new Set(); + const independentActionSubtrees = new Set(); for (const descendant of descendants) { + if ( + descendant.hittable === true || + isEditableNode(descendant) || + (descendant.parentIndex !== undefined && + independentActionSubtrees.has(descendant.parentIndex)) + ) { + independentActionSubtrees.add(descendant.index); + continue; + } if ( removed.has(descendant.index) || !isPromotableRowContent(descendant, descendants) ||