Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the addons installer progress bars and fix issues #139

Merged
merged 4 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openandroidinstaller/app_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
# placeholders
self.advanced = False
self.install_addons = False
self.addon_paths = None
self.addon_paths = []
self.config = None
self.image_path = None
self.recovery_path = None
Expand Down
79 changes: 43 additions & 36 deletions openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
import shlex
from time import sleep
from typing import List, Optional, Union, Generator, Callable
from typing import Optional, Union, Generator, Callable

from loguru import logger

Expand Down Expand Up @@ -140,6 +140,13 @@ def activate_sideload(bin_path: Path) -> TerminalResponse:
yield line


@add_logging("Wait for device")
def adb_wait_for_device(bin_path: Path) -> TerminalResponse:
"""Use adb to wait for the device to become available."""
for line in run_command("adb wait-for-device", bin_path):
yield line


@add_logging("Wait for recovery")
def adb_wait_for_recovery(bin_path: Path) -> TerminalResponse:
"""Use adb to wait for the recovery to become available."""
Expand Down Expand Up @@ -229,7 +236,7 @@ def adb_twrp_wipe_and_install(
for partition in ["dalvik", "cache"]:
for line in run_command(f"adb shell twrp wipe {partition}", bin_path):
yield line
sleep(1)
sleep(3)
if (type(line) == bool) and not line:
logger.error(f"Wiping {partition} failed.")
# TODO: if this fails, a fix can be to just sideload something and then adb reboot
Expand All @@ -238,17 +245,20 @@ def adb_twrp_wipe_and_install(
bin_path=bin_path,
):
yield line
sleep(1)
if (type(line) == bool) and not line:
yield False
break
sleep(2)
# finally reboot into os or to fastboot for flashing addons
sleep(7)
for line in adb_wait_for_recovery(bin_path):
yield line
if install_addons:
if is_ab:
# reboot into the bootloader again
for line in adb_reboot_bootloader(bin_path):
yield line
sleep(3)
# boot to TWRP again
for line in fastboot_boot_recovery(
bin_path=bin_path, recovery=recovery, is_ab=is_ab
Expand All @@ -262,30 +272,39 @@ def adb_twrp_wipe_and_install(
yield line


def adb_twrp_install_addons(
bin_path: Path, addons: List[str], is_ab: bool
def adb_twrp_install_addon(
bin_path: Path, addon_path: str, is_ab: bool
) -> TerminalResponse:
"""Flash addons through adb and twrp.
"""Flash addon through adb and twrp.

Only works for twrp recovery.
"""
logger.info("Install addons with twrp.")
logger.info(f"Install addon {addon_path} with twrp.")
sleep(0.5)
if is_ab:
adb_wait_for_recovery(bin_path=bin_path)
logger.info("Sideload and install addons.")
for addon in addons:
# activate sideload
logger.info("Activate sideload.")
for line in activate_sideload(bin_path=bin_path):
yield line
# now flash os image
for line in adb_sideload(bin_path=bin_path, target=addon):
yield line
sleep(7)
# activate sideload
logger.info("Activate sideload.")
for line in activate_sideload(bin_path=bin_path):
yield line
logger.info("Sideload and install addon.")
# now flash the addon
for line in adb_sideload(bin_path=bin_path, target=addon_path):
yield line
logger.info("done.")


def adb_twrp_finish_install_addons(bin_path: Path, is_ab: bool) -> TerminalResponse:
"""Finish the process of flashing addons with TWRP and reboot.

Only works for twrp recovery.
"""
sleep(3)
for line in adb_wait_for_recovery(bin_path):
yield line
# finally reboot into os
if is_ab:
logger.info("Switch partitions on a/b-partitioned device.")
# reboot into the bootloader again
for line in adb_reboot_bootloader(bin_path=bin_path):
yield line
Expand All @@ -302,6 +321,7 @@ def adb_twrp_install_addons(
yield line
else:
# reboot with adb
logger.info("Reboot into OS.")
for line in adb_reboot(bin_path=bin_path):
yield line

Expand Down Expand Up @@ -360,30 +380,17 @@ def fastboot_boot_recovery(
bin_path: Path, recovery: str, is_ab: bool = True
) -> TerminalResponse:
"""Temporarily, boot custom recovery with fastboot."""
# TODO: this can be unified now
if is_ab:
logger.info("Boot custom recovery with fastboot.")
for line in run_command(
"fastboot boot", target=f"{recovery}", bin_path=bin_path
):
yield line
logger.info("Boot into TWRP with fastboot.")
for line in adb_wait_for_recovery(bin_path=bin_path):
yield line
else:
logger.info("Boot custom recovery with fastboot.")
for line in run_command(
"fastboot boot", target=f"{recovery}", bin_path=bin_path
):
yield line
logger.info("Boot custom recovery with fastboot.")
for line in run_command("fastboot boot", target=f"{recovery}", bin_path=bin_path):
yield line
if not is_ab:
if (type(line) == bool) and not line:
logger.error("Booting recovery failed.")
yield False
else:
yield True
logger.info("Boot into TWRP with fastboot.")
for line in adb_wait_for_recovery(bin_path=bin_path):
yield line
for line in adb_wait_for_recovery(bin_path=bin_path):
yield line


def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:
Expand Down
33 changes: 26 additions & 7 deletions openandroidinstaller/views/install_addons_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from loguru import logger
from time import sleep
from typing import Callable
from pathlib import Path

from flet import (
Column,
Expand All @@ -33,7 +34,7 @@

from views import BaseView
from app_state import AppState
from tooling import adb_twrp_install_addons, adb_reboot
from tooling import adb_twrp_install_addon, adb_twrp_finish_install_addons, adb_reboot
from widgets import (
confirm_button,
get_title,
Expand All @@ -55,6 +56,8 @@ def build(self):
"""Create the content of the view."""
# error text
self.error_text = Text("", color=colors.RED)
# text field to inform about the currently installing addon
self.addon_info_text = Text("", weight="bold")

# switch to enable advanced output - here it means show terminal input/output in tool
def check_advanced_switch(e):
Expand Down Expand Up @@ -112,8 +115,9 @@ def check_advanced_switch(e):
# build the view
self.right_view.controls.extend(
[
Row([self.error_text]),
Row([self.addon_info_text]),
Row([self.progress_indicator]),
Row([self.error_text]),
Column(
[
self.advanced_switch,
Expand Down Expand Up @@ -150,17 +154,23 @@ def run_install_addons(self, e):
# disable the call button while the command is running
self.install_button.disabled = True
self.error_text.value = ""
# reset the progress indicators
self.progress_indicator.clear()
self.addon_info_text.value = ""
# reset terminal output
if self.state.advanced:
self.terminal_box.clear()
self.right_view.update()

# run the install script
if self.state.addon_paths:
for line in adb_twrp_install_addons(
addons=self.state.addon_paths,
for addon_num, addon_path in enumerate(self.state.addon_paths):
# reset the progress indicators
self.progress_indicator.clear()
# inform about the currently installed addon
self.addon_info_text.value = f"{addon_num + 1}/{len(self.state.addon_paths)}: Installing {Path(addon_path).name} ..."
self.right_view.update()

# install one addon at the time
for line in adb_twrp_install_addon(
addon_path=addon_path,
bin_path=self.state.bin_path,
is_ab=self.state.config.is_ab,
):
Expand All @@ -169,6 +179,15 @@ def run_install_addons(self, e):
# in case the install command is run, we want to update the progress bar
self.progress_indicator.display_progress_bar(line)
self.progress_indicator.update()
sleep(7)

if self.state.addon_paths:
# reboot after installing the addons; here we might switch partitions on ab-partitioned devices
for line in adb_twrp_finish_install_addons(
bin_path=self.state.bin_path,
is_ab=self.state.config.is_ab,
):
self.terminal_box.write_line(line)
else:
logger.info("No addons selected. Rebooting to OS.")
for line in adb_reboot(bin_path=self.state.bin_path):
Expand Down