Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/platforms/android/__tests__/devices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from 'node:path';
import {
ensureAndroidEmulatorBooted,
parseAndroidAvdList,
parseAndroidEmulatorAvdNameOutput,
parseAndroidFeatureListForTv,
parseAndroidTargetFromCharacteristics,
resolveAndroidAvdName,
Expand All @@ -31,6 +32,12 @@ test('parseAndroidAvdList drops empty lines', () => {
assert.deepEqual(listed, ['Pixel_9_Pro_XL', 'Wear_OS']);
});

test('parseAndroidEmulatorAvdNameOutput drops trailing adb protocol status', () => {
assert.equal(parseAndroidEmulatorAvdNameOutput('Pixel_9_Pro_XL\r\nOK\r\n'), 'Pixel_9_Pro_XL');
assert.equal(parseAndroidEmulatorAvdNameOutput('Pixel_9_Pro_XL\n'), 'Pixel_9_Pro_XL');
assert.equal(parseAndroidEmulatorAvdNameOutput('\r\nOK\r\n'), undefined);
});

test('resolveAndroidAvdName supports space vs underscore matching', () => {
const avdNames = ['Pixel_9_Pro_XL', 'Medium_Tablet_API_35'];
assert.equal(resolveAndroidAvdName(avdNames, 'Pixel_9_Pro_XL'), 'Pixel_9_Pro_XL');
Expand Down
16 changes: 14 additions & 2 deletions src/platforms/android/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ function normalizeAndroidName(value: string): string {
return value.toLowerCase().replace(/_/g, ' ').replace(/\s+/g, ' ').trim();
}

export function parseAndroidEmulatorAvdNameOutput(rawOutput: string): string | undefined {
const lines = rawOutput
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0);
if (lines.length === 0) return undefined;
if (lines.at(-1) === 'OK') {
lines.pop();
}
return lines.join('\n').trim() || undefined;
}

async function readAndroidBootProp(
serial: string,
timeoutMs = TIMEOUT_PROFILES.android_boot.operationMs,
Expand Down Expand Up @@ -71,8 +83,8 @@ async function resolveAndroidEmulatorAvdName(serial: string): Promise<string | u
allowFailure: true,
timeoutMs: ANDROID_EMULATOR_AVD_NAME_TIMEOUT_MS,
});
const emuValue = emuResult.stdout.trim();
if (emuResult.exitCode === 0 && emuValue.length > 0) {
const emuValue = parseAndroidEmulatorAvdNameOutput(emuResult.stdout);
if (emuResult.exitCode === 0 && emuValue) {
return emuValue;
}
return undefined;
Expand Down
Loading