Skip to content

Commit b0277a7

Browse files
committed
fix(android): ignore emulator log lines in -list-avds output
`emulator -list-avds` can print its crashdata INFO banner on stdout with exit code 0. The inventory treated every non-empty stdout line as an AVD, so a machine with zero AVDs listed a phantom emulator named after the banner. Accept only lines matching avdmanager's AVD-name grammar. Fixes #3716
1 parent 0149438 commit b0277a7

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎packages/platform-android/src/inventory-parsers.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ export function parseAndroidDeviceDescription(rawOutput: string): {
3939
};
4040
}
4141

42+
/** avdmanager restricts AVD names to these characters; other stdout lines are emulator logging. */
43+
const ANDROID_AVD_NAME = /^[A-Za-z0-9._-]+$/;
44+
4245
export function parseAndroidAvdList(rawOutput: string): string[] {
4346
return rawOutput
4447
.split('\n')
4548
.map((line) => line.trim())
46-
.filter((line) => line.length > 0);
49+
.filter((line) => ANDROID_AVD_NAME.test(line));
4750
}
4851

4952
export function parseAndroidEmulatorAvdNameOutput(rawOutput: string): string | undefined {

‎packages/platform-android/src/inventory.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,37 @@ test.each([
7777
},
7878
);
7979

80+
const EMULATOR_CRASHDATA_BANNER =
81+
'INFO | Storing crashdata in: /tmp/user/emu-crash-34.2.16.db, detection is enabled for process: 98765';
82+
83+
test.each([
84+
['only the crashdata banner', `${EMULATOR_CRASHDATA_BANNER}\n`, []],
85+
[
86+
'the crashdata banner beside AVD names',
87+
`${EMULATOR_CRASHDATA_BANNER}\r\nPixel_9_Pro_XL\r\nwear-os.36\r\n`,
88+
['Pixel_9_Pro_XL', 'wear-os.36'],
89+
],
90+
] as const)(
91+
'Android inventory lists only AVD names when emulator -list-avds prints %s',
92+
async (_case, listAvdsStdout, expectedAvds) => {
93+
const host = createHost(async (request) => {
94+
if (request.executable === 'emulator') return result(listAvdsStdout);
95+
if (request.args.join('\0') === 'devices\0-l') return result('List of devices attached\n');
96+
throw new Error(`Unexpected command: ${request.executable} ${request.args.join(' ')}`);
97+
});
98+
99+
const devices = await createAndroidInventory(host).discover(
100+
{ androidAvdSelection: 'include-stopped' },
101+
scope,
102+
);
103+
104+
assert.deepEqual(
105+
devices.map((device) => device.id),
106+
expectedAvds,
107+
);
108+
},
109+
);
110+
80111
test.each([
81112
['exits non-zero', async () => result('', 'error: closed', 1)],
82113
[

0 commit comments

Comments
 (0)