(
options: AndroidDeviceDiscoveryOptions = {},
)
| 222 | } |
| 223 | |
| 224 | export async function listAndroidDevices( |
| 225 | options: AndroidDeviceDiscoveryOptions = {}, |
| 226 | ): Promise<DeviceInfo[]> { |
| 227 | await ensureAndroidSdkPathConfigured(); |
| 228 | const adbAvailable = await whichCmd('adb'); |
| 229 | if (!adbAvailable) { |
| 230 | throw new AppError('TOOL_MISSING', 'adb not found in PATH'); |
| 231 | } |
| 232 | const serialAllowlist = options.serialAllowlist ?? resolveAndroidSerialAllowlist(undefined); |
| 233 | |
| 234 | const entries = await listAndroidDeviceEntries(); |
| 235 | const filteredEntries = entries.filter( |
| 236 | (entry) => !serialAllowlist || serialAllowlist.has(entry.serial), |
| 237 | ); |
| 238 | |
| 239 | const devices = await mapWithConcurrency( |
| 240 | filteredEntries, |
| 241 | ANDROID_DISCOVERY_CONCURRENCY, |
| 242 | async ({ serial, rawModel }) => { |
| 243 | const [name, booted, target] = await Promise.all([ |
| 244 | resolveAndroidDeviceName(serial, rawModel), |
| 245 | isAndroidBooted(serial), |
| 246 | resolveAndroidTarget(serial), |
| 247 | ]); |
| 248 | return { |
| 249 | platform: 'android', |
| 250 | id: serial, |
| 251 | name, |
| 252 | kind: isEmulatorSerial(serial) ? 'emulator' : 'device', |
| 253 | target, |
| 254 | booted, |
| 255 | } satisfies DeviceInfo; |
| 256 | }, |
| 257 | ); |
| 258 | |
| 259 | return [...devices, ...(await listStoppedAndroidAvdDevices(devices))]; |
| 260 | } |
| 261 | |
| 262 | type AndroidDeviceEntry = { |
| 263 | serial: string; |
no test coverage detected