|
18 | 18 | import shutil |
19 | 19 | import subprocess |
20 | 20 | import sys |
21 | | -from urllib.parse import urlparse |
22 | 21 |
|
23 | 22 | from openai import OpenAI |
24 | 23 |
|
25 | 24 | from phone_agent import PhoneAgent |
| 25 | +from phone_agent.adb import ADBConnection, list_devices |
| 26 | +from phone_agent.adb.keyboard_installer import ( |
| 27 | + ADBKeyboardInstaller, |
| 28 | + auto_setup_adb_keyboard, |
| 29 | +) |
26 | 30 | from phone_agent.agent import AgentConfig |
27 | 31 | from phone_agent.config.apps import list_supported_apps |
28 | 32 | from phone_agent.config.apps_harmonyos import list_supported_apps as list_harmonyos_apps |
@@ -150,45 +154,40 @@ def check_system_requirements(device_type: DeviceType = DeviceType.ADB) -> bool: |
150 | 154 | print("❌ System check failed. Please fix the issues above.") |
151 | 155 | return False |
152 | 156 |
|
153 | | - # Check 3: ADB Keyboard installed (only for ADB) |
154 | | - if device_type == DeviceType.ADB: |
155 | | - print("3. Checking ADB Keyboard...", end=" ") |
156 | | - try: |
157 | | - result = subprocess.run( |
158 | | - ["adb", "shell", "ime", "list", "-s"], |
159 | | - capture_output=True, |
160 | | - text=True, |
161 | | - timeout=10, |
162 | | - ) |
163 | | - ime_list = result.stdout.strip() |
| 157 | + # Check 3: ADB Keyboard installed |
| 158 | + print("3. Checking ADB Keyboard...", end=" ") |
| 159 | + try: |
| 160 | + result = subprocess.run( |
| 161 | + ["adb", "shell", "ime", "list", "-s"], |
| 162 | + capture_output=True, |
| 163 | + text=True, |
| 164 | + timeout=10, |
| 165 | + ) |
| 166 | + ime_list = result.stdout.strip() |
164 | 167 |
|
165 | | - if "com.android.adbkeyboard/.AdbIME" in ime_list: |
166 | | - print("✅ OK") |
167 | | - else: |
168 | | - print("❌ FAILED") |
169 | | - print(" Error: ADB Keyboard is not installed on the device.") |
170 | | - print(" Solution:") |
171 | | - print(" 1. Download ADB Keyboard APK from:") |
172 | | - print( |
173 | | - " https://github.com/senzhk/ADBKeyBoard/blob/master/ADBKeyboard.apk" |
174 | | - ) |
175 | | - print(" 2. Install it on your device: adb install ADBKeyboard.apk") |
176 | | - print( |
177 | | - " 3. Enable it in Settings > System > Languages & Input > Virtual Keyboard" |
178 | | - ) |
179 | | - all_passed = False |
180 | | - except subprocess.TimeoutExpired: |
181 | | - print("❌ FAILED") |
182 | | - print(" Error: ADB command timed out.") |
183 | | - all_passed = False |
184 | | - except Exception as e: |
| 168 | + if "com.android.adbkeyboard/.AdbIME" in ime_list: |
| 169 | + print("✅ OK") |
| 170 | + else: |
185 | 171 | print("❌ FAILED") |
186 | | - print(f" Error: {e}") |
| 172 | + print(" Error: ADB Keyboard is not installed on the device.") |
| 173 | + print(" Solution:") |
| 174 | + print(" 1. Download ADB Keyboard APK from:") |
| 175 | + print( |
| 176 | + " https://github.com/senzhk/ADBKeyBoard/blob/master/ADBKeyboard.apk" |
| 177 | + ) |
| 178 | + print(" 2. Install it on your device: adb install ADBKeyboard.apk") |
| 179 | + print( |
| 180 | + " 3. Enable it in Settings > System > Languages & Input > Virtual Keyboard" |
| 181 | + ) |
187 | 182 | all_passed = False |
188 | | - else: |
189 | | - # For HDC, skip keyboard check as it uses different input method |
190 | | - print("3. Skipping keyboard check for HarmonyOS...", end=" ") |
191 | | - print("✅ OK (using native input)") |
| 183 | + except subprocess.TimeoutExpired: |
| 184 | + print("❌ FAILED") |
| 185 | + print(" Error: ADB command timed out.") |
| 186 | + all_passed = False |
| 187 | + except Exception as e: |
| 188 | + print("❌ FAILED") |
| 189 | + print(f" Error: {e}") |
| 190 | + all_passed = False |
192 | 191 |
|
193 | 192 | print("-" * 50) |
194 | 193 |
|
@@ -264,7 +263,7 @@ def check_model_api(base_url: str, model_name: str, api_key: str = "EMPTY") -> b |
264 | 263 | "Name or service not known" in error_msg |
265 | 264 | or "nodename nor servname" in error_msg |
266 | 265 | ): |
267 | | - print(f" Error: Cannot resolve hostname") |
| 266 | + print(" Error: Cannot resolve hostname") |
268 | 267 | print(" Solution:") |
269 | 268 | print(" 1. Check the URL is correct") |
270 | 269 | print(" 2. Verify DNS settings") |
@@ -480,9 +479,9 @@ def handle_device_commands(args) -> bool: |
480 | 479 | # Try to get device IP |
481 | 480 | ip = conn.get_device_ip(args.device_id) |
482 | 481 | if ip: |
483 | | - print(f"\nYou can now connect remotely using:") |
| 482 | + print("\nYou can now connect remotely using:") |
484 | 483 | print(f" python main.py --connect {ip}:{port}") |
485 | | - print(f"\nOr via ADB directly:") |
| 484 | + print("\nOr via ADB directly:") |
486 | 485 | print(f" adb connect {ip}:{port}") |
487 | 486 | else: |
488 | 487 | print("\nCould not determine device IP. Check device WiFi settings.") |
|
0 commit comments