@@ -452,13 +452,20 @@ type AndroidNodeInclusionInfo = {
452452 isVisual : boolean ;
453453} ;
454454
455+ type AndroidFootprint = {
456+ /** Bounding box of what the subtree presents (agent targets and labelled leaves), if anything. */
457+ rect : Rect | null ;
458+ hasAgentTarget : boolean ;
459+ } ;
460+
455461type AndroidTreePruneState = {
456- actionableContentMemo : WeakMap < AndroidNode , boolean > ;
462+ footprintMemo : WeakMap < AndroidNode , AndroidFootprint > ;
457463} ;
458464
459- type AndroidCoveringCandidate = AndroidNode & {
460- rect : Rect ;
465+ type AndroidCoveringCandidate = {
466+ node : AndroidNode ;
461467 drawingOrder : number ;
468+ footprint : Rect ;
462469} ;
463470
464471const ANDROID_WINDOW_TYPE_APPLICATION = 1 ;
@@ -525,7 +532,7 @@ export function parseUiHierarchyTree(xml: string): AndroidUiHierarchy {
525532 discardInactiveAndroidApplicationWindows ( root ) ;
526533 // UiAutomation can expose covered React Native navigation surfaces in the same accessibility
527534 // window. If a higher drawing-order sibling covers them, agents should see the foreground surface.
528- pruneAndroidCoveredSubtrees ( root , { actionableContentMemo : new WeakMap ( ) } ) ;
535+ pruneAndroidCoveredSubtrees ( root , { footprintMemo : new WeakMap ( ) } ) ;
529536 applyAndroidScrollActionHints ( root ) ;
530537 return root ;
531538}
@@ -550,22 +557,59 @@ function hasSemanticContent(node: AndroidNode): boolean {
550557 return hasMeaningfulLabel ( node ) || hasMeaningfulIdentifier ( node ) ;
551558}
552559
553- /** Focusability is traversal, not paint, so it is not evidence a node hides anything (#1733). */
560+ /**
561+ * Focusability is traversal, not paint (#1733), and a label is an announcement, not paint (#1806):
562+ * a container's content-desc describes its children and an empty labelled View draws nothing. Only
563+ * a touch target is direct evidence that a node hides what lies under its box.
564+ */
554565function hasDirectOcclusionEvidence ( node : AndroidNode ) : boolean {
555- return node . visibleToUser !== false && ( isTouchTarget ( node ) || hasSemanticContent ( node ) ) ;
566+ return node . visibleToUser !== false && isTouchTarget ( node ) ;
556567}
557568
558569/** Evidence the node is a real surface because it contains something an agent could drive. */
559570function hasDescendantOcclusionEvidence ( node : AndroidNode , state : AndroidTreePruneState ) : boolean {
560- const cached = state . actionableContentMemo . get ( node ) ;
561- if ( cached !== undefined ) return cached ;
562- const result = node . children . some (
563- ( child ) =>
564- child . visibleToUser !== false &&
565- ( isAgentTarget ( child ) || hasDescendantOcclusionEvidence ( child , state ) ) ,
571+ return node . children . some (
572+ ( child ) => child . visibleToUser !== false && subtreeFootprint ( child , state ) . hasAgentTarget ,
566573 ) ;
567- state . actionableContentMemo . set ( node , result ) ;
568- return result ;
574+ }
575+
576+ /**
577+ * Where a subtree visibly presents something: the bounding box of its agent targets and labelled
578+ * leaves. A full-screen debug overlay holding one floating icon presents only that icon, so it can
579+ * only hide what sits under the icon, never the whole app behind it (#1806).
580+ */
581+ function subtreeFootprint ( node : AndroidNode , state : AndroidTreePruneState ) : AndroidFootprint {
582+ const cached = state . footprintMemo . get ( node ) ;
583+ if ( cached !== undefined ) return cached ;
584+ let hasAgentTarget = isAgentTarget ( node ) ;
585+ let rect : Rect | null =
586+ ( isAgentTarget ( node ) || isLabelledLeaf ( node ) ) && hasPositiveRect ( node ) ? node . rect : null ;
587+ for ( const child of node . children ) {
588+ if ( child . visibleToUser === false ) continue ;
589+ const childFootprint = subtreeFootprint ( child , state ) ;
590+ hasAgentTarget ||= childFootprint . hasAgentTarget ;
591+ rect = unionRect ( rect , childFootprint . rect ) ;
592+ }
593+ const footprint = { rect, hasAgentTarget } ;
594+ state . footprintMemo . set ( node , footprint ) ;
595+ return footprint ;
596+ }
597+
598+ function isLabelledLeaf ( node : AndroidNode ) : boolean {
599+ return node . children . length === 0 && hasMeaningfulLabel ( node ) ;
600+ }
601+
602+ function unionRect ( left : Rect | null , right : Rect | null ) : Rect | null {
603+ if ( ! left ) return right ;
604+ if ( ! right ) return left ;
605+ const x = Math . min ( left . x , right . x ) ;
606+ const y = Math . min ( left . y , right . y ) ;
607+ return {
608+ x,
609+ y,
610+ width : Math . max ( left . x + left . width , right . x + right . width ) - x ,
611+ height : Math . max ( left . y + left . height , right . y + right . height ) - y ,
612+ } ;
569613}
570614
571615/**
@@ -598,32 +642,45 @@ function pruneAndroidCoveredSubtrees(node: AndroidNode, state: AndroidTreePruneS
598642 return ;
599643 }
600644 const siblings = node . children ;
601- const coveringCandidates = siblings . filter ( ( sibling ) => canCoverSibling ( sibling , state ) ) ;
645+ const coveringCandidates = siblings
646+ . map ( ( sibling ) => coveringCandidateOf ( sibling , state ) )
647+ . filter ( ( candidate ) => candidate !== null ) ;
602648 if ( coveringCandidates . length === 0 ) return ;
603- node . children = siblings . filter ( ( child ) => shouldKeepAndroidSibling ( child , coveringCandidates ) ) ;
649+ node . children = siblings . filter ( ( child ) =>
650+ shouldKeepAndroidSibling ( child , coveringCandidates , state ) ,
651+ ) ;
604652}
605653
606654function shouldKeepAndroidSibling (
607655 node : AndroidNode ,
608656 coveringCandidates : AndroidCoveringCandidate [ ] ,
657+ state : AndroidTreePruneState ,
609658) : boolean {
610659 return (
611- isPresentationLeaf ( node ) || ! isCoveredByHigherDrawingOrderSibling ( node , coveringCandidates )
660+ isPresentationLeaf ( node ) ||
661+ ! isCoveredByHigherDrawingOrderSibling ( node , coveringCandidates , state )
612662 ) ;
613663}
614664
665+ /**
666+ * Covered means the sibling's presented content lies under the candidate's presented content.
667+ * Comparing footprints rather than boxes lets two stacked screens with the same layout margins
668+ * still register as covered, while a sparse overlay never condemns a rich screen.
669+ */
615670function isCoveredByHigherDrawingOrderSibling (
616671 node : AndroidNode ,
617672 coveringCandidates : AndroidCoveringCandidate [ ] ,
673+ state : AndroidTreePruneState ,
618674) : boolean {
619675 if ( node . visibleToUser === false || node . drawingOrder === undefined || ! hasPositiveRect ( node ) ) {
620676 return false ;
621677 }
622- for ( const sibling of coveringCandidates ) {
623- if ( sibling === node || sibling . drawingOrder <= node . drawingOrder ) {
678+ const coveredRect = subtreeFootprint ( node , state ) . rect ?? node . rect ;
679+ for ( const candidate of coveringCandidates ) {
680+ if ( candidate . node === node || candidate . drawingOrder <= node . drawingOrder ) {
624681 continue ;
625682 }
626- if ( rectCoverage ( sibling . rect , node . rect ) >= 0.9 ) {
683+ if ( rectCoverage ( candidate . footprint , coveredRect ) >= 0.9 ) {
627684 return true ;
628685 }
629686 }
@@ -635,21 +692,20 @@ function hasMeaningfulIdentifier(node: AndroidNode): boolean {
635692 return Boolean ( identifier && ! isGenericAndroidId ( identifier ) ) ;
636693}
637694
638- function canCoverSibling (
695+ /** The single occlusion classification. Covering is never re-derived from a raw attribute. */
696+ function coveringCandidateOf (
639697 node : AndroidNode ,
640698 state : AndroidTreePruneState ,
641- ) : node is AndroidCoveringCandidate {
642- return (
643- node . visibleToUser !== false &&
644- node . drawingOrder !== undefined &&
645- hasPositiveRect ( node ) &&
646- hasOcclusionEvidence ( node , state )
647- ) ;
648- }
649-
650- /** The single occlusion classification. Covering is never re-derived from a raw attribute. */
651- function hasOcclusionEvidence ( node : AndroidNode , state : AndroidTreePruneState ) : boolean {
652- return hasDirectOcclusionEvidence ( node ) || hasDescendantOcclusionEvidence ( node , state ) ;
699+ ) : AndroidCoveringCandidate | null {
700+ const { drawingOrder } = node ;
701+ if ( node . visibleToUser === false || drawingOrder === undefined || ! hasPositiveRect ( node ) ) {
702+ return null ;
703+ }
704+ if ( ! hasDirectOcclusionEvidence ( node ) && ! hasDescendantOcclusionEvidence ( node , state ) ) {
705+ return null ;
706+ }
707+ const footprint = subtreeFootprint ( node , state ) . rect ;
708+ return footprint ? { node, drawingOrder, footprint } : null ;
653709}
654710
655711function hasMeaningfulLabel ( node : AndroidNode ) : boolean {
0 commit comments