1111 setup_keyboard ,
1212 A11Y_SERVICE_NAME as DROIDRUN_A11Y_SERVICE_NAME ,
1313)
14- from adbutils import adb , AdbDevice
14+ from async_adbutils import adb , AdbDevice
1515import time
1616
1717logger = logging .getLogger (__name__ )
2222)
2323DEFAULT_OVERLAY_OFFSET = - 126
2424
25- def ensure_connected (serial : str ) -> AdbDevice :
25+ async def ensure_connected (serial : str ) -> AdbDevice :
2626 try :
2727 # For emulator devices (emulator-*), they're already connected locally
2828 # Only try network connect for IP addresses
@@ -32,27 +32,27 @@ def ensure_connected(serial: str) -> AdbDevice:
3232 raise RuntimeError (f"Failed to connect: { res } " )
3333
3434 # Verify device is available
35- device = adb .device (serial )
35+ device = await adb .device (serial )
3636 # Test if device is accessible
37- device .shell ("echo test" )
37+ await device .shell ("echo test" )
3838 return device
3939 except Exception as e :
4040 raise RuntimeError (f"Device { serial } is not connected: { e } " )
4141
4242
43- def install_portal (device : AdbDevice ):
43+ async def install_portal (device : AdbDevice ):
4444 logger .info ("Installing portal..." )
4545
4646 try :
4747 with download_portal_apk () as apk_path :
48- device .install (apk_path , uninstall = True , flags = ["-g" ], silent = False )
48+ await device .install (apk_path , uninstall = True , flags = ["-g" ], silent = False )
4949 logger .info ("Portal APK installed successfully" )
5050 except Exception as e :
5151 raise RuntimeError (f"Failed to download and install portal APK: { e } " )
5252
5353 try :
5454 logger .info ("Enabling portal as accessibility service..." )
55- enable_portal_accessibility (
55+ await enable_portal_accessibility (
5656 device , service_name = DROIDRUN_X_GOOGLE_A11Y_SERVICE_NAME
5757 )
5858 logger .info ("Portal accessibility enabled successfully" )
@@ -61,36 +61,36 @@ def install_portal(device: AdbDevice):
6161
6262 try :
6363 logger .info ("Setting up keyboard for environment..." )
64- setup_keyboard (device )
64+ await setup_keyboard (device )
6565 logger .info ("Keyboard setup completed successfully!" )
6666 except Exception as e :
6767 raise RuntimeError (f"Failed to setup keyboard: { e } " )
6868
6969
70- def check_portal (device : AdbDevice ):
71- if not check_portal_accessibility (
70+ async def check_portal (device : AdbDevice ):
71+ if not await check_portal_accessibility (
7272 device , service_name = DROIDRUN_X_GOOGLE_A11Y_SERVICE_NAME
7373 ):
7474 raise RuntimeError ("Accessibility settings invalid" )
7575
7676 try :
77- set_overlay_offset (device , DEFAULT_OVERLAY_OFFSET )
77+ await set_overlay_offset (device , DEFAULT_OVERLAY_OFFSET )
7878 logger .info ("Overlay offset set successfully" )
7979 except Exception as e :
8080 raise RuntimeError (f"Failed to set overlay offset: { e } " )
8181
8282 try :
83- ping_portal (device )
83+ await ping_portal (device )
8484 except Exception as e :
8585 raise RuntimeError (f"Failed to ping portal: { e } " )
8686
8787 try :
88- ping_portal_content (device )
88+ await ping_portal_content (device )
8989 except Exception as e :
9090 raise RuntimeError (f"Failed to ping portal content: { e } " )
9191
9292 try :
93- ping_portal_tcp (device )
93+ await ping_portal_tcp (device )
9494 except Exception as e :
9595 raise RuntimeError (f"Failed to ping portal TCP: { e } " )
9696
@@ -124,7 +124,7 @@ def wait_ready(env: AndroidEnvClient, timeout: int = 300):
124124 )
125125
126126
127- def boot_environment (env : AndroidEnvClient , serial : str ):
127+ async def boot_environment (env : AndroidEnvClient , serial : str ):
128128 try :
129129 logger .info (f"Waiting for environment { env .base_url } to be ready..." )
130130 wait_ready (env , timeout = 600 )
@@ -134,15 +134,15 @@ def boot_environment(env: AndroidEnvClient, serial: str):
134134 raise e
135135
136136 try :
137- device = ensure_connected (serial )
137+ device = await ensure_connected (serial )
138138 except Exception as e :
139139 logger .error (f"Environment { env .base_url } failed to connect via adb: { e } " )
140140 raise e
141141
142142 # check if portal is already installed
143143 try :
144144 logger .info (f"Checking portal for environment { env .base_url } ..." )
145- check_portal (device )
145+ await check_portal (device )
146146 logger .info ("Portal is installed and accessible. You're good to go!" )
147147 return
148148 except Exception as e :
@@ -152,15 +152,15 @@ def boot_environment(env: AndroidEnvClient, serial: str):
152152
153153 try :
154154 logger .info (f"Installing portal for environment { env .base_url } ..." )
155- install_portal (device )
155+ await install_portal (device )
156156 logger .info (f"Portal installed successfully for environment { env .base_url } !" )
157157 except Exception as e :
158158 logger .error (f"Environment { env .base_url } failed to install portal: { e } " )
159159 raise e
160160
161161 try :
162162 logger .info (f"Checking portal for environment { env .base_url } ..." )
163- check_portal (device )
163+ await check_portal (device )
164164 logger .info ("Portal is installed and accessible. You're good to go!" )
165165 except Exception as e :
166166 logger .error (f"Environment { env .base_url } failed to check portal: { e } " )
0 commit comments