Skip to content

Commit 4496561

Browse files
authored
fix: strip trailing OK from android emulator names (#242)
1 parent 3d50d9b commit 4496561

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/platforms/android/__tests__/devices.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from 'node:path';
66
import {
77
ensureAndroidEmulatorBooted,
88
parseAndroidAvdList,
9+
parseAndroidEmulatorAvdNameOutput,
910
parseAndroidFeatureListForTv,
1011
parseAndroidTargetFromCharacteristics,
1112
resolveAndroidAvdName,
@@ -121,6 +122,12 @@ test('parseAndroidAvdList drops empty lines', () => {
121122
assert.deepEqual(listed, ['Pixel_9_Pro_XL', 'Wear_OS']);
122123
});
123124

125+
test('parseAndroidEmulatorAvdNameOutput drops trailing adb protocol status', () => {
126+
assert.equal(parseAndroidEmulatorAvdNameOutput('Pixel_9_Pro_XL\r\nOK\r\n'), 'Pixel_9_Pro_XL');
127+
assert.equal(parseAndroidEmulatorAvdNameOutput('Pixel_9_Pro_XL\n'), 'Pixel_9_Pro_XL');
128+
assert.equal(parseAndroidEmulatorAvdNameOutput('\r\nOK\r\n'), undefined);
129+
});
130+
124131
test('resolveAndroidAvdName supports space vs underscore matching', () => {
125132
const avdNames = ['Pixel_9_Pro_XL', 'Medium_Tablet_API_35'];
126133
assert.equal(resolveAndroidAvdName(avdNames, 'Pixel_9_Pro_XL'), 'Pixel_9_Pro_XL');

src/platforms/android/devices.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ function normalizeAndroidName(value: string): string {
3838
return value.toLowerCase().replace(/_/g, ' ').replace(/\s+/g, ' ').trim();
3939
}
4040

41+
export function parseAndroidEmulatorAvdNameOutput(rawOutput: string): string | undefined {
42+
const lines = rawOutput
43+
.split('\n')
44+
.map((line) => line.trim())
45+
.filter((line) => line.length > 0);
46+
if (lines.length === 0) return undefined;
47+
if (lines.at(-1) === 'OK') {
48+
lines.pop();
49+
}
50+
return lines.join('\n').trim() || undefined;
51+
}
52+
4153
async function readAndroidBootProp(
4254
serial: string,
4355
timeoutMs = TIMEOUT_PROFILES.android_boot.operationMs,
@@ -72,8 +84,8 @@ async function resolveAndroidEmulatorAvdName(serial: string): Promise<string | u
7284
allowFailure: true,
7385
timeoutMs: ANDROID_EMULATOR_AVD_NAME_TIMEOUT_MS,
7486
});
75-
const emuValue = emuResult.stdout.trim();
76-
if (emuResult.exitCode === 0 && emuValue.length > 0) {
87+
const emuValue = parseAndroidEmulatorAvdNameOutput(emuResult.stdout);
88+
if (emuResult.exitCode === 0 && emuValue) {
7789
return emuValue;
7890
}
7991
return undefined;

0 commit comments

Comments
 (0)