Skip to content

Commit 4ddb936

Browse files
committed
feat(adb): add automatic ADB keyboard installation
Add comprehensive auto-installation functionality for ADB Keyboard to improve user onboarding experience. The new keyboard_installer module provides automatic download, installation, and enablement of ADB Keyboard without requiring manual intervention. The system now detects missing ADB Keyboard, offers automatic installation, handles enabling when already installed, and provides detailed status reporting throughout the process.
1 parent 34457de commit 4ddb936

File tree

2 files changed

+334
-40
lines changed

2 files changed

+334
-40
lines changed

main.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
import shutil
1919
import subprocess
2020
import sys
21-
from urllib.parse import urlparse
2221

2322
from openai import OpenAI
2423

2524
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+
)
2630
from phone_agent.agent import AgentConfig
2731
from phone_agent.config.apps import list_supported_apps
2832
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:
150154
print("❌ System check failed. Please fix the issues above.")
151155
return False
152156

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()
164167

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:
185171
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+
)
187182
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
192191

193192
print("-" * 50)
194193

@@ -264,7 +263,7 @@ def check_model_api(base_url: str, model_name: str, api_key: str = "EMPTY") -> b
264263
"Name or service not known" in error_msg
265264
or "nodename nor servname" in error_msg
266265
):
267-
print(f" Error: Cannot resolve hostname")
266+
print(" Error: Cannot resolve hostname")
268267
print(" Solution:")
269268
print(" 1. Check the URL is correct")
270269
print(" 2. Verify DNS settings")
@@ -480,9 +479,9 @@ def handle_device_commands(args) -> bool:
480479
# Try to get device IP
481480
ip = conn.get_device_ip(args.device_id)
482481
if ip:
483-
print(f"\nYou can now connect remotely using:")
482+
print("\nYou can now connect remotely using:")
484483
print(f" python main.py --connect {ip}:{port}")
485-
print(f"\nOr via ADB directly:")
484+
print("\nOr via ADB directly:")
486485
print(f" adb connect {ip}:{port}")
487486
else:
488487
print("\nCould not determine device IP. Check device WiFi settings.")

0 commit comments

Comments
 (0)