From 54f5f51955ac70d8ccc2c69c76ce5325b18b79cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Tue, 12 May 2026 00:53:11 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D0=BD=D1=8B=D0=B5=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20Android=20=D1=83=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B9=D1=81=D1=82=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/android_tools.py | 81 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/backend/android_tools.py b/backend/android_tools.py index e3199b9..c0a53bd 100644 --- a/backend/android_tools.py +++ b/backend/android_tools.py @@ -9,7 +9,86 @@ PROJECTS_DIR = DATA_DIR / 'projects' def list_devices() -> dict: - return run_command('adb devices -l', PROJECTS_DIR.as_posix(), timeout=60) + result = run_command('adb devices -l', PROJECTS_DIR.as_posix(), timeout=60) + result['devices'] = parse_devices(result.get('stdout', '')) + return result + + +def parse_devices(stdout: str) -> list[dict]: + devices: list[dict] = [] + + for line in stdout.splitlines(): + line = line.strip() + if not line or line.startswith('List of devices'): + continue + + parts = line.split() + if len(parts) < 2: + continue + + serial = parts[0] + state = parts[1] + + if state != 'device': + devices.append({ + 'serial': serial, + 'state': state, + 'title': f'{serial} ({state})', + 'subtitle': 'Устройство не готово', + }) + continue + + props = get_device_props(serial) + brand = props.get('brand') or '' + model = props.get('model') or '' + device = props.get('device') or '' + android = props.get('android') or '' + sdk = props.get('sdk') or '' + + title = ' '.join(part for part in [brand, model] if part).strip() or serial + subtitle_parts = [] + if android: + subtitle_parts.append(f'Android {android}') + if sdk: + subtitle_parts.append(f'SDK {sdk}') + if device: + subtitle_parts.append(device) + subtitle_parts.append(serial) + + devices.append({ + 'serial': serial, + 'state': state, + 'brand': brand, + 'model': model, + 'device': device, + 'android': android, + 'sdk': sdk, + 'title': title, + 'subtitle': ' · '.join(subtitle_parts), + }) + + return devices + + +def get_device_props(serial: str) -> dict: + commands = { + 'brand': f'adb -s {serial} shell getprop ro.product.brand', + 'model': f'adb -s {serial} shell getprop ro.product.model', + 'device': f'adb -s {serial} shell getprop ro.product.device', + 'android': f'adb -s {serial} shell getprop ro.build.version.release', + 'sdk': f'adb -s {serial} shell getprop ro.build.version.sdk', + } + + props: dict[str, str] = {} + + for key, command in commands.items(): + try: + result = run_command(command, PROJECTS_DIR.as_posix(), timeout=20) + props[key] = (result.get('stdout') or '').strip() + except Exception: + props[key] = '' + + return props def find_apks(workspace: str) -> list[str]: