|
3 | 3 | import platform |
4 | 4 | import os |
5 | 5 | from Framework.install_handler.utils import send_response |
| 6 | +from Framework.install_handler.android.android_sdk import update_android_sdk_path |
6 | 7 |
|
7 | 8 |
|
8 | 9 | async def check_status() -> bool: |
9 | 10 | """Check if ADB (Android Debug Bridge) is installed.""" |
10 | 11 | print("[installer][android-adb] Checking status...") |
11 | 12 |
|
12 | | - # Dynamically refresh ANDROID_HOME and PATH from registry on Windows |
13 | | - system = platform.system() |
14 | | - if system == "Windows": |
15 | | - try: |
16 | | - import winreg |
17 | | - with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Environment", 0, winreg.KEY_READ) as key: |
18 | | - try: |
19 | | - android_home_reg, _ = winreg.QueryValueEx(key, "ANDROID_HOME") |
20 | | - if android_home_reg: |
21 | | - # Expand environment variables before checking if path exists |
22 | | - android_home_expanded = os.path.expandvars(android_home_reg) |
23 | | - if os.path.exists(android_home_expanded): |
24 | | - os.environ['ANDROID_HOME'] = android_home_expanded |
25 | | - # Update PATH with platform-tools (where ADB is located) |
26 | | - platform_tools = os.path.join(android_home_expanded, "platform-tools") |
27 | | - current_path = os.environ.get('PATH', '') |
28 | | - if platform_tools not in current_path: |
29 | | - os.environ['PATH'] = f"{platform_tools};{current_path}" |
30 | | - print(f"[installer][android-adb] Refreshed ANDROID_HOME from registry: {android_home_expanded}") |
31 | | - except FileNotFoundError: |
32 | | - pass |
33 | | - |
34 | | - # Also check ANDROID_SDK_ROOT if ANDROID_HOME not found |
35 | | - if 'ANDROID_HOME' not in os.environ or not os.path.exists(os.environ.get('ANDROID_HOME', '')): |
36 | | - try: |
37 | | - android_sdk_root_reg, _ = winreg.QueryValueEx(key, "ANDROID_SDK_ROOT") |
38 | | - if android_sdk_root_reg: |
39 | | - # Expand environment variables before checking if path exists |
40 | | - android_sdk_root_expanded = os.path.expandvars(android_sdk_root_reg) |
41 | | - if os.path.exists(android_sdk_root_expanded): |
42 | | - os.environ['ANDROID_SDK_ROOT'] = android_sdk_root_expanded |
43 | | - # Update PATH with platform-tools (where ADB is located) |
44 | | - platform_tools = os.path.join(android_sdk_root_expanded, "platform-tools") |
45 | | - current_path = os.environ.get('PATH', '') |
46 | | - if platform_tools not in current_path: |
47 | | - os.environ['PATH'] = f"{platform_tools};{current_path}" |
48 | | - print(f"[installer][android-adb] Refreshed ANDROID_SDK_ROOT from registry: {android_sdk_root_expanded}") |
49 | | - except FileNotFoundError: |
50 | | - pass |
51 | | - except Exception as e: |
52 | | - print(f"[installer][android-adb] Failed to refresh from registry: {e}") |
53 | | - |
54 | 13 | try: |
| 14 | + |
55 | 15 | loop = asyncio.get_event_loop() |
56 | 16 | result = await loop.run_in_executor( |
57 | 17 | None, |
|
0 commit comments