@@ -140,6 +140,13 @@ def activate_sideload(bin_path: Path) -> TerminalResponse:
140140 yield line
141141
142142
143+ @add_logging ("Wait for device" )
144+ def adb_wait_for_device (bin_path : Path ) -> TerminalResponse :
145+ """Use adb to wait for the device to become available."""
146+ for line in run_command ("adb wait-for-device" , bin_path ):
147+ yield line
148+
149+
143150@add_logging ("Wait for recovery" )
144151def adb_wait_for_recovery (bin_path : Path ) -> TerminalResponse :
145152 """Use adb to wait for the recovery to become available."""
@@ -229,7 +236,7 @@ def adb_twrp_wipe_and_install(
229236 for partition in ["dalvik" , "cache" ]:
230237 for line in run_command (f"adb shell twrp wipe { partition } " , bin_path ):
231238 yield line
232- sleep (1 )
239+ sleep (3 )
233240 if (type (line ) == bool ) and not line :
234241 logger .error (f"Wiping { partition } failed." )
235242 # TODO: if this fails, a fix can be to just sideload something and then adb reboot
@@ -238,17 +245,20 @@ def adb_twrp_wipe_and_install(
238245 bin_path = bin_path ,
239246 ):
240247 yield line
248+ sleep (1 )
241249 if (type (line ) == bool ) and not line :
242250 yield False
243251 break
244252 sleep (2 )
245253 # finally reboot into os or to fastboot for flashing addons
246- sleep (7 )
254+ for line in adb_wait_for_recovery (bin_path ):
255+ yield line
247256 if install_addons :
248257 if is_ab :
249258 # reboot into the bootloader again
250259 for line in adb_reboot_bootloader (bin_path ):
251260 yield line
261+ sleep (3 )
252262 # boot to TWRP again
253263 for line in fastboot_boot_recovery (
254264 bin_path = bin_path , recovery = recovery , is_ab = is_ab
@@ -281,7 +291,6 @@ def adb_twrp_install_addon(
281291 # now flash the addon
282292 for line in adb_sideload (bin_path = bin_path , target = addon_path ):
283293 yield line
284- sleep (7 )
285294 logger .info ("done." )
286295
287296
@@ -293,6 +302,8 @@ def adb_twrp_finish_install_addons(
293302 Only works for twrp recovery.
294303 """
295304 sleep (3 )
305+ for line in adb_wait_for_recovery (bin_path ):
306+ yield line
296307 # finally reboot into os
297308 if is_ab :
298309 logger .info ("Switch partitions on a/b-partitioned device." )
0 commit comments