Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(emulator): reject reported Android activity launch failures (#35623)

OrcaWinf6d4381a79d9
diff --git a/src/main/emulator/android/android-adb-result.ts b/src/main/emulator/android/android-adb-result.ts
index 704c733e091..cd9d1889c48 100644
--- a/src/main/emulator/android/android-adb-result.ts
+++ b/src/main/emulator/android/android-adb-result.ts
@@ -2,12 +2,22 @@ import { EmulatorError } from '../emulator-errors'
import type { AndroidCommandResult } from './android-command-runner'
// The runner resolves nonzero exits; callers must explicitly reject unsuccessful actions.
-export function ensureAdbOk(result: AndroidCommandResult, label: string): AndroidCommandResult {
+export function ensureAdbOk(
+ result: AndroidCommandResult,
+ label: string,
+ options?: { checkErrorOutput?: boolean }
+): AndroidCommandResult {
if (result.code !== 0) {
throw new EmulatorError(
'emulator_error',
`${label} failed: ${(result.stderr || result.stdout).trim() || 'unknown error'}`
)
}
+ if (options?.checkErrorOutput) {
+ const failure = `${result.stdout}\n${result.stderr}`.match(/^\s*ERROR:.*$/im)?.[0]
+ if (failure) {
+ throw new EmulatorError('emulator_error', `${label} failed: ${failure.trim()}`)
+ }
+ }
return result
}
diff --git a/src/main/emulator/android/android-capability-operations.test.ts b/src/main/emulator/android/android-capability-operations.test.ts
index 615524c0c69..a888c9d7fc9 100644
--- a/src/main/emulator/android/android-capability-operations.test.ts
+++ b/src/main/emulator/android/android-capability-operations.test.ts
@@ -1,7 +1,11 @@
import { describe, expect, it, vi } from 'vitest'
import type { AndroidCommandResult, AndroidCommandRunner } from './android-command-runner'
import type { AndroidSdkPaths } from './android-sdk-discovery'
-import { installAndroidApk } from './android-capability-operations'
+import {
+ dumpAndroidAccessibilityTree,
+ installAndroidApk,
+ launchAndroidApp
+} from './android-capability-operations'
const SDK: AndroidSdkPaths = {
sdkRoot: '/sdk',
@@ -29,3 +33,59 @@ describe('installAndroidApk', () => {
})
})
})
+
+describe('dumpAndroidAccessibilityTree', () => {
+ it.each([
+ { stdout: '', stderr: 'ERROR: could not get idle state.' },
+ { stdout: 'ERROR: could not get idle state.', stderr: 'WARNING: diagnostic output' }
+ ])('rejects a zero-exit dump failure before reading stale XML: %j', async (diagnostic) => {
+ const runner = vi.fn<AndroidCommandRunner>().mockResolvedValueOnce({ ...diagnostic, code: 0 })
+ runner.mockResolvedValue(ok('<hierarchy><node text="Old screen"/></hierarchy>'))
+
+ await expect(dumpAndroidAccessibilityTree(runner, SDK, 's')).rejects.toMatchObject({
+ code: 'emulator_error',
+ message: expect.stringContaining('ERROR:')
+ })
+ expect(runner).toHaveBeenCalledTimes(1)
+ })
+
+ it('reads a successful dump despite unrelated stderr warnings', async () => {
+ const runner = vi.fn<AndroidCommandRunner>()
+ runner.mockResolvedValueOnce({
+ code: 0,
+ stdout: 'UI hierchary dumped to: /sdcard/window_dump.xml',
+ stderr: 'WARNING: diagnostic output'
+ })
+ runner.mockResolvedValueOnce(ok('<hierarchy><node text="Current screen"/></hierarchy>'))
+
+ const tree = await dumpAndroidAccessibilityTree(runner, SDK, 's')
+ expect(tree.children[0]).toMatchObject({ text: 'Current screen' })
+ expect(runner).toHaveBeenCalledTimes(2)
+ })
+})
+
+describe('launchAndroidApp', () => {
+ it.each([
+ { stdout: '', stderr: 'Error type 3\nError: Activity class {com.x/.Missing} does not exist.' },
+ { stdout: 'Error: Activity class {com.x/.Missing} does not exist.', stderr: '' }
+ ])('rejects a zero-exit activity launch failure: %j', async (diagnostic) => {
+ const runner = vi.fn<AndroidCommandRunner>().mockResolvedValue({ ...diagnostic, code: 0 })
+
+ await expect(launchAndroidApp(runner, SDK, 's', 'com.x', '.Missing')).rejects.toMatchObject({
+ code: 'emulator_error',
+ message: expect.stringContaining('Error:')
+ })
+ })
+
+ it('accepts a successful launch with a brought-to-front warning', async () => {
+ const runner = vi.fn<AndroidCommandRunner>().mockResolvedValue({
+ code: 0,
+ stdout: 'Starting: Intent { cmp=com.Error/.ErrorActivity }',
+ stderr: 'Warning: Activity not started, its current task has been brought to the front'
+ })
+
+ await expect(
+ launchAndroidApp(runner, SDK, 's', 'com.Error', '.ErrorActivity')
+ ).resolves.toBeUndefined()
+ })
+})
diff --git a/src/main/emulator/android/android-capability-operations.ts b/src/main/emulator/android/android-capability-operations.ts
index 9cf6525e5bc..1b847ebb06c 100644
--- a/src/main/emulator/android/android-capability-operations.ts
+++ b/src/main/emulator/android/android-capability-operations.ts
@@ -33,7 +33,10 @@ export async function launchAndroidApp(
packageName: string,
activity?: string
): Promise<void> {
- ensureAdbOk(await runner(sdk.adb, launchAppArgs(serial, packageName, activity)), 'adb launch')
+ // Older Android releases return exit 0 after am start reports an activity launch failure.
+ ensureAdbOk(await runner(sdk.adb, launchAppArgs(serial, packageName, activity)), 'adb launch', {
+ checkErrorOutput: true
+ })
}
export async function setAndroidPermission(
@@ -55,10 +58,11 @@ export async function dumpAndroidAccessibilityTree(
sdk: AndroidSdkPaths,
serial: string
): Promise<AndroidAxNode> {
- // Check the dump before reading its file to avoid returning stale XML.
+ // uiautomator reports idle/root failures with exit 0 and leaves the previous XML untouched.
ensureAdbOk(
await runner(sdk.adb, ['-s', serial, 'shell', 'uiautomator', 'dump', UIAUTOMATOR_DUMP_PATH]),
- 'uiautomator dump'
+ 'uiautomator dump',
+ { checkErrorOutput: true }
)
const xml = ensureAdbOk(
await runner(sdk.adb, ['-s', serial, 'shell', 'cat', UIAUTOMATOR_DUMP_PATH]),