( device: DeviceInfo, action: 'accept' | 'dismiss', )
| 79 | } |
| 80 | |
| 81 | async function handleAndroidAlertAction( |
| 82 | device: DeviceInfo, |
| 83 | action: 'accept' | 'dismiss', |
| 84 | ): Promise<AndroidAlertResult> { |
| 85 | const candidate = await pollAndroidAlertCandidate(device, ALERT_ACTION_RETRY_MS); |
| 86 | if (!candidate) { |
| 87 | throw new AppError('COMMAND_FAILED', 'alert not found', { |
| 88 | hint: 'If a sheet is visible in snapshot but alert reports no alert, it is likely app-owned UI. Use snapshot -i and press the visible label/ref.', |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | const button = chooseAndroidAlertButton(candidate.buttons, action); |
| 93 | if (button) { |
| 94 | await pressAndroid(device, button.x, button.y); |
| 95 | return buildAndroidAlertHandledResponse(action, candidate.alert, button.label); |
| 96 | } |
| 97 | |
| 98 | if (action === 'dismiss') { |
| 99 | await backAndroid(device); |
| 100 | return buildAndroidAlertHandledResponse(action, candidate.alert, 'Back'); |
| 101 | } |
| 102 | |
| 103 | throw new AppError('COMMAND_FAILED', 'alert accept found an alert but no accept button', { |
| 104 | alert: candidate.alert, |
| 105 | hint: 'Inspect alert get --json for visible buttons, then use press by visible label/ref if needed.', |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | async function pollAndroidAlertCandidate( |
| 110 | device: DeviceInfo, |
no test coverage detected