11import type { AndroidSnapshotBackendMetadata } from './snapshot-types.ts' ;
22import { isAndroidInputMethodOwnedNode } from '../../contracts/android-input-ownership.ts' ;
3+ import { classifyAndroidAlertIdentifier } from './alert-detection.ts' ;
34import { androidUiNodes , type AndroidUiNodeMetadata } from './ui-hierarchy.ts' ;
45
56const ANDROID_WINDOW_TYPE_APPLICATION = 1 ;
@@ -48,6 +49,7 @@ export function classifyAndroidHelperContentRecovery(
4849 ) ;
4950 }
5051
52+ if ( hasRecognizedAndroidAlertSurface ( summary ) ) return undefined ;
5153 if ( isForegroundAppContentHiddenByInputMethod ( summary ) ) return undefined ;
5254 if ( isForegroundAppContentPoor ( summary ) ) {
5355 return buildRecoveryDecision (
@@ -143,6 +145,10 @@ function isSystemWindowOnly(summary: AndroidHelperXmlSummary): boolean {
143145 ) ;
144146}
145147
148+ function hasRecognizedAndroidAlertSurface ( summary : AndroidHelperXmlSummary ) : boolean {
149+ return summary . hasAlertButtonIdentifier && summary . hasAlertContentIdentifier ;
150+ }
151+
146152function buildRecoveryDecision (
147153 summary : AndroidHelperXmlSummary ,
148154 metadata : AndroidSnapshotBackendMetadata ,
@@ -165,6 +171,8 @@ type AndroidHelperXmlSummary = {
165171 applicationMeaningfulNodeCount : number ;
166172 nonSystemMeaningfulNodeCount : number ;
167173 inputMethodMeaningfulNodeCount : number ;
174+ hasAlertButtonIdentifier : boolean ;
175+ hasAlertContentIdentifier : boolean ;
168176 foregroundAppPackage ?: string ;
169177 foregroundAppMeaningfulNodeCount ?: number ;
170178 windowTypes : number [ ] ;
@@ -200,6 +208,8 @@ function createAndroidHelperXmlSummaryState(
200208 applicationMeaningfulNodeCount : 0 ,
201209 nonSystemMeaningfulNodeCount : 0 ,
202210 inputMethodMeaningfulNodeCount : 0 ,
211+ hasAlertButtonIdentifier : false ,
212+ hasAlertContentIdentifier : false ,
203213 ...( foregroundAppPackage !== undefined
204214 ? { foregroundAppPackage, foregroundAppMeaningfulNodeCount : 0 }
205215 : { } ) ,
@@ -213,10 +223,20 @@ function recordAndroidHelperSummaryNode(
213223) : void {
214224 summary . nodeCount += 1 ;
215225 if ( node . packageName === ANDROID_SYSTEM_UI_PACKAGE ) summary . systemUiNodeCount += 1 ;
226+ if ( node . visibleToUser !== false ) recordAndroidAlertIdentifier ( summary , node . resourceId ) ;
216227 recordAndroidHelperWindowNode ( summary , node ) ;
217228 recordAndroidHelperMeaningfulNode ( summary , node ) ;
218229}
219230
231+ function recordAndroidAlertIdentifier (
232+ summary : AndroidHelperXmlSummaryState ,
233+ resourceId : string | null ,
234+ ) : void {
235+ const kind = classifyAndroidAlertIdentifier ( resourceId ) ;
236+ if ( kind === 'button' ) summary . hasAlertButtonIdentifier = true ;
237+ if ( kind === 'content' ) summary . hasAlertContentIdentifier = true ;
238+ }
239+
220240function recordAndroidHelperWindowNode (
221241 summary : AndroidHelperXmlSummaryState ,
222242 node : AndroidUiNodeMetadata ,
@@ -275,6 +295,8 @@ function finalizeAndroidHelperXmlSummary(
275295 applicationMeaningfulNodeCount : summary . applicationMeaningfulNodeCount ,
276296 nonSystemMeaningfulNodeCount : summary . nonSystemMeaningfulNodeCount ,
277297 inputMethodMeaningfulNodeCount : summary . inputMethodMeaningfulNodeCount ,
298+ hasAlertButtonIdentifier : summary . hasAlertButtonIdentifier ,
299+ hasAlertContentIdentifier : summary . hasAlertContentIdentifier ,
278300 ...( summary . foregroundAppPackage !== undefined
279301 ? {
280302 foregroundAppPackage : summary . foregroundAppPackage ,
0 commit comments