android_list_devices
List connected Android devices and emulators to manage development environments, using ADB or native-run for detection.
Instructions
List connected Android devices and emulators (supports ADB fallback to native-run)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/android.ts:689-751 (handler)Handler function that lists connected Android devices and emulators by running 'adb devices -l' via fallback system, parsing the output to extract detailed device information including serial, state, product, model, device type, and transport ID, then returning structured data with counts and fallback info.handler: async () => { const fallbackResult = await fallbackManager.executeAdbWithFallback( ['devices', '-l'], { platform: 'android' } ); if (!fallbackResult.success) { throw new Error(fallbackResult.error || 'Failed to list devices'); } const result = fallbackResult.data; // Parse adb devices output const devices = []; const lines = result.stdout.split('\n').slice(1); // Skip header for (const line of lines) { const trimmed = line.trim(); if (trimmed && !trimmed.startsWith('*')) { const parts = trimmed.split(/\s+/); if (parts.length >= 2) { const device = { serial: parts[0], state: parts[1], product: '', model: '', device: '', transport_id: '', }; // Parse additional info for (let i = 2; i < parts.length; i++) { const part = parts[i]; if (part && part.startsWith('product:')) { device.product = part.split(':')[1] || ''; } else if (part && part.startsWith('model:')) { device.model = part.split(':')[1] || ''; } else if (part && part.startsWith('device:')) { device.device = part.split(':')[1] || ''; } else if (part && part.startsWith('transport_id:')) { device.transport_id = part.split(':')[1] || ''; } } devices.push(device); } } } return { success: true, data: { devices, totalCount: devices.length, onlineCount: devices.filter(d => d.state === 'device').length, fallbackInfo: fallbackResult.usedFallback ? { usedFallback: true, fallbackTool: fallbackResult.fallbackTool, message: fallbackResult.message } : undefined }, }; }
- src/tools/android.ts:681-752 (registration)Registration of the 'android_list_devices' tool within createAndroidTools function, including name, description, empty input schema (no parameters required), and reference to the handler function.tools.set('android_list_devices', { name: 'android_list_devices', description: 'List connected Android devices and emulators (supports ADB fallback to native-run)', inputSchema: { type: 'object', properties: {}, required: [] }, handler: async () => { const fallbackResult = await fallbackManager.executeAdbWithFallback( ['devices', '-l'], { platform: 'android' } ); if (!fallbackResult.success) { throw new Error(fallbackResult.error || 'Failed to list devices'); } const result = fallbackResult.data; // Parse adb devices output const devices = []; const lines = result.stdout.split('\n').slice(1); // Skip header for (const line of lines) { const trimmed = line.trim(); if (trimmed && !trimmed.startsWith('*')) { const parts = trimmed.split(/\s+/); if (parts.length >= 2) { const device = { serial: parts[0], state: parts[1], product: '', model: '', device: '', transport_id: '', }; // Parse additional info for (let i = 2; i < parts.length; i++) { const part = parts[i]; if (part && part.startsWith('product:')) { device.product = part.split(':')[1] || ''; } else if (part && part.startsWith('model:')) { device.model = part.split(':')[1] || ''; } else if (part && part.startsWith('device:')) { device.device = part.split(':')[1] || ''; } else if (part && part.startsWith('transport_id:')) { device.transport_id = part.split(':')[1] || ''; } } devices.push(device); } } } return { success: true, data: { devices, totalCount: devices.length, onlineCount: devices.filter(d => d.state === 'device').length, fallbackInfo: fallbackResult.usedFallback ? { usedFallback: true, fallbackTool: fallbackResult.fallbackTool, message: fallbackResult.message } : undefined }, }; } });
- src/utils/fallbacks.ts:61-98 (helper)FallbackManager.executeAdbWithFallback helper method called by the handler. Executes ADB commands with automatic fallback to native-run tool if ADB is unavailable. Specifically for 'devices -l', it maps to 'native-run android --list' when falling back.async executeAdbWithFallback( adbArgs: string[], context: { deviceId?: string; platform?: 'android' | 'ios' } = {} ): Promise<FallbackResult> { const adbAvailable = await this.checkToolAvailability(RequiredTool.ADB); const nativeRunAvailable = await this.checkToolAvailability(RequiredTool.NATIVE_RUN); // Try ADB first if available if (adbAvailable) { try { const result = await processExecutor.execute('adb', adbArgs); return { success: true, usedFallback: false, originalTool: 'adb', data: result }; } catch (error: any) { // ADB failed, try fallback if (nativeRunAvailable) { return await this.executeNativeRunFallback(adbArgs, context, error.message); } throw error; } } // Use native-run as fallback if (nativeRunAvailable) { return await this.executeNativeRunFallback(adbArgs, context, 'ADB not available'); } return { success: false, usedFallback: false, originalTool: 'adb', error: 'Neither ADB nor native-run are available' }; }
- src/utils/tool-categories.ts:80-88 (schema)Metadata schema/definition for android_list_devices tool categorizing it as essential Android tool requiring ADB, safe for testing, with performance expectations.'android_list_devices': { name: 'android_list_devices', category: ToolCategory.ESSENTIAL, platform: 'android', requiredTools: [RequiredTool.ADB], description: 'List connected Android devices and emulators', safeForTesting: true, performance: { expectedDuration: 500, timeout: 10000 } },