Skip to content

Commit 540df59

Browse files
authored
Improve the addons installer progress bars and fix issues (#139)
This PR adds: - Should resolve: #103 - Wait for adb to become available at the right times. Todo: - [x] can the device interaction and waiting time be optimized?
2 parents be8d660 + 3a99084 commit 540df59

File tree

3 files changed

+70
-44
lines changed

3 files changed

+70
-44
lines changed

openandroidinstaller/app_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(
4040
# placeholders
4141
self.advanced = False
4242
self.install_addons = False
43-
self.addon_paths = None
43+
self.addon_paths = []
4444
self.config = None
4545
self.image_path = None
4646
self.recovery_path = None

openandroidinstaller/tooling.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525
import shlex
2626
from time import sleep
27-
from typing import List, Optional, Union, Generator, Callable
27+
from typing import Optional, Union, Generator, Callable
2828

2929
from loguru import logger
3030

@@ -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")
144151
def 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
@@ -262,30 +272,39 @@ def adb_twrp_wipe_and_install(
262272
yield line
263273

264274

265-
def adb_twrp_install_addons(
266-
bin_path: Path, addons: List[str], is_ab: bool
275+
def adb_twrp_install_addon(
276+
bin_path: Path, addon_path: str, is_ab: bool
267277
) -> TerminalResponse:
268-
"""Flash addons through adb and twrp.
278+
"""Flash addon through adb and twrp.
269279
270280
Only works for twrp recovery.
271281
"""
272-
logger.info("Install addons with twrp.")
282+
logger.info(f"Install addon {addon_path} with twrp.")
273283
sleep(0.5)
274284
if is_ab:
275285
adb_wait_for_recovery(bin_path=bin_path)
276-
logger.info("Sideload and install addons.")
277-
for addon in addons:
278-
# activate sideload
279-
logger.info("Activate sideload.")
280-
for line in activate_sideload(bin_path=bin_path):
281-
yield line
282-
# now flash os image
283-
for line in adb_sideload(bin_path=bin_path, target=addon):
284-
yield line
285-
sleep(7)
286+
# activate sideload
287+
logger.info("Activate sideload.")
288+
for line in activate_sideload(bin_path=bin_path):
289+
yield line
290+
logger.info("Sideload and install addon.")
291+
# now flash the addon
292+
for line in adb_sideload(bin_path=bin_path, target=addon_path):
293+
yield line
294+
logger.info("done.")
295+
296+
297+
def adb_twrp_finish_install_addons(bin_path: Path, is_ab: bool) -> TerminalResponse:
298+
"""Finish the process of flashing addons with TWRP and reboot.
299+
300+
Only works for twrp recovery.
301+
"""
286302
sleep(3)
303+
for line in adb_wait_for_recovery(bin_path):
304+
yield line
287305
# finally reboot into os
288306
if is_ab:
307+
logger.info("Switch partitions on a/b-partitioned device.")
289308
# reboot into the bootloader again
290309
for line in adb_reboot_bootloader(bin_path=bin_path):
291310
yield line
@@ -302,6 +321,7 @@ def adb_twrp_install_addons(
302321
yield line
303322
else:
304323
# reboot with adb
324+
logger.info("Reboot into OS.")
305325
for line in adb_reboot(bin_path=bin_path):
306326
yield line
307327

@@ -360,30 +380,17 @@ def fastboot_boot_recovery(
360380
bin_path: Path, recovery: str, is_ab: bool = True
361381
) -> TerminalResponse:
362382
"""Temporarily, boot custom recovery with fastboot."""
363-
# TODO: this can be unified now
364-
if is_ab:
365-
logger.info("Boot custom recovery with fastboot.")
366-
for line in run_command(
367-
"fastboot boot", target=f"{recovery}", bin_path=bin_path
368-
):
369-
yield line
370-
logger.info("Boot into TWRP with fastboot.")
371-
for line in adb_wait_for_recovery(bin_path=bin_path):
372-
yield line
373-
else:
374-
logger.info("Boot custom recovery with fastboot.")
375-
for line in run_command(
376-
"fastboot boot", target=f"{recovery}", bin_path=bin_path
377-
):
378-
yield line
383+
logger.info("Boot custom recovery with fastboot.")
384+
for line in run_command("fastboot boot", target=f"{recovery}", bin_path=bin_path):
385+
yield line
386+
if not is_ab:
379387
if (type(line) == bool) and not line:
380388
logger.error("Booting recovery failed.")
381389
yield False
382390
else:
383391
yield True
384-
logger.info("Boot into TWRP with fastboot.")
385-
for line in adb_wait_for_recovery(bin_path=bin_path):
386-
yield line
392+
for line in adb_wait_for_recovery(bin_path=bin_path):
393+
yield line
387394

388395

389396
def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:

openandroidinstaller/views/install_addons_view.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from loguru import logger
1717
from time import sleep
1818
from typing import Callable
19+
from pathlib import Path
1920

2021
from flet import (
2122
Column,
@@ -33,7 +34,7 @@
3334

3435
from views import BaseView
3536
from app_state import AppState
36-
from tooling import adb_twrp_install_addons, adb_reboot
37+
from tooling import adb_twrp_install_addon, adb_twrp_finish_install_addons, adb_reboot
3738
from widgets import (
3839
confirm_button,
3940
get_title,
@@ -55,6 +56,8 @@ def build(self):
5556
"""Create the content of the view."""
5657
# error text
5758
self.error_text = Text("", color=colors.RED)
59+
# text field to inform about the currently installing addon
60+
self.addon_info_text = Text("", weight="bold")
5861

5962
# switch to enable advanced output - here it means show terminal input/output in tool
6063
def check_advanced_switch(e):
@@ -112,8 +115,9 @@ def check_advanced_switch(e):
112115
# build the view
113116
self.right_view.controls.extend(
114117
[
115-
Row([self.error_text]),
118+
Row([self.addon_info_text]),
116119
Row([self.progress_indicator]),
120+
Row([self.error_text]),
117121
Column(
118122
[
119123
self.advanced_switch,
@@ -150,17 +154,23 @@ def run_install_addons(self, e):
150154
# disable the call button while the command is running
151155
self.install_button.disabled = True
152156
self.error_text.value = ""
153-
# reset the progress indicators
154-
self.progress_indicator.clear()
157+
self.addon_info_text.value = ""
155158
# reset terminal output
156159
if self.state.advanced:
157160
self.terminal_box.clear()
158161
self.right_view.update()
159162

160163
# run the install script
161-
if self.state.addon_paths:
162-
for line in adb_twrp_install_addons(
163-
addons=self.state.addon_paths,
164+
for addon_num, addon_path in enumerate(self.state.addon_paths):
165+
# reset the progress indicators
166+
self.progress_indicator.clear()
167+
# inform about the currently installed addon
168+
self.addon_info_text.value = f"{addon_num + 1}/{len(self.state.addon_paths)}: Installing {Path(addon_path).name} ..."
169+
self.right_view.update()
170+
171+
# install one addon at the time
172+
for line in adb_twrp_install_addon(
173+
addon_path=addon_path,
164174
bin_path=self.state.bin_path,
165175
is_ab=self.state.config.is_ab,
166176
):
@@ -169,6 +179,15 @@ def run_install_addons(self, e):
169179
# in case the install command is run, we want to update the progress bar
170180
self.progress_indicator.display_progress_bar(line)
171181
self.progress_indicator.update()
182+
sleep(7)
183+
184+
if self.state.addon_paths:
185+
# reboot after installing the addons; here we might switch partitions on ab-partitioned devices
186+
for line in adb_twrp_finish_install_addons(
187+
bin_path=self.state.bin_path,
188+
is_ab=self.state.config.is_ab,
189+
):
190+
self.terminal_box.write_line(line)
172191
else:
173192
logger.info("No addons selected. Rebooting to OS.")
174193
for line in adb_reboot(bin_path=self.state.bin_path):

0 commit comments

Comments
 (0)