adb_get_battery_info
Retrieve battery status and health data from Android devices through ADB for monitoring power levels and charging state.
Instructions
Get battery information from the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Device ID (optional) |
Implementation Reference
- src/tools/shell.ts:109-160 (handler)Main handler function for 'adb_get_battery_info' tool. Executes 'adb shell dumpsys battery', parses key battery properties using extractValue helper, and returns structured data.async getBatteryInfo(deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot get battery info - device is not connected' }; } const command = 'shell dumpsys battery'; const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to get battery info' }; } // Parse battery information const output = result.output; const batteryInfo = { level: this.extractValue(output, 'level'), scale: this.extractValue(output, 'scale'), status: this.extractValue(output, 'status'), health: this.extractValue(output, 'health'), present: this.extractValue(output, 'present'), plugged: this.extractValue(output, 'plugged'), voltage: this.extractValue(output, 'voltage'), temperature: this.extractValue(output, 'temperature'), technology: this.extractValue(output, 'technology') }; return { success: true, data: { ...batteryInfo, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: 'Battery information retrieved successfully' }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to get battery info' }; } }
- src/index.ts:387-400 (schema)Tool schema definition including name, description, and input schema (optional deviceId).{ name: 'adb_get_battery_info', description: 'Get battery information from the device', inputSchema: { type: 'object', properties: { deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: [], }, },
- src/index.ts:477-478 (registration)Switch case registration that maps tool name to the shellTools.getBatteryInfo handler.case 'adb_get_battery_info': return await this.handleToolCall(this.shellTools.getBatteryInfo(args?.deviceId as string));
- src/tools/shell.ts:162-166 (helper)Private helper method used by getBatteryInfo to parse key-value pairs from 'dumpsys battery' output.private extractValue(text: string, key: string): string { const regex = new RegExp(`${key}:\\s*(.+)`); const match = text.match(regex); return match ? match[1].trim() : 'N/A'; }