MCPcopy Index your code
hub / github.com/callstack/agent-device / handleAndroidAlertAction

Function handleAndroidAlertAction

src/platforms/android/alert.ts:81–107  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  action: 'accept' | 'dismiss',
)

Source from the content-addressed store, hash-verified

79}
80
81async 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
109async function pollAndroidAlertCandidate(
110 device: DeviceInfo,

Callers 1

handleAndroidAlertFunction · 0.85

Calls 5

chooseAndroidAlertButtonFunction · 0.90
pressAndroidFunction · 0.90
backAndroidFunction · 0.90

Tested by

no test coverage detected