Commit 0b53acca authored by Tobias Sterbak's avatar Tobias Sterbak
Browse files

ADd workflows to not flash the recovery and still work

parent ff5c2a11
......@@ -16,8 +16,9 @@
import copy
from pathlib import Path
from typing import List, Optional
from loguru import logger
from installer_config import _load_config
from installer_config import _load_config, Step
class AppState:
......@@ -37,6 +38,10 @@ class AppState:
self.test = test
self.test_config = test_config
# store state
self.unlock_bootloader = True
self.flash_recovery = True
# placeholders
self.advanced = False
self.install_addons = False
......@@ -72,3 +77,48 @@ class AppState:
self.steps = copy.deepcopy(self.config.unlock_bootloader) + copy.deepcopy(
self.config.boot_recovery
)
def toggle_flash_unlock_bootloader(self):
"""Toggle flashing of unlock bootloader."""
self.unlock_bootloader = not self.unlock_bootloader
if self.unlock_bootloader:
logger.info("Enabled unlocking the bootloader again.")
self.steps = copy.deepcopy(self.config.unlock_bootloader)
else:
logger.info("Skipping bootloader unlocking.")
self.steps = []
# if the recovery is already flashed, skip flashing it again
if self.flash_recovery:
self.steps += copy.deepcopy(self.config.boot_recovery)
else:
self.steps = [
Step(
title="Boot custom recovery",
type="confirm_button",
content="If you already flashed TWRP, boot into it by pressing 'Confirm and run'. Otherwise restart the process. Once your phone screen looks like the picture on the left, continue.",
command="adb_reboot_recovery",
img="twrp-start.jpeg",
)
]
def toggle_flash_recovery(self):
"""Toggle flashing of recovery."""
self.flash_recovery = not self.flash_recovery
if self.unlock_bootloader:
self.steps = copy.deepcopy(self.config.unlock_bootloader)
else:
self.steps = []
if self.flash_recovery:
logger.info("Enabled flashing recovery again.")
self.steps += copy.deepcopy(self.config.boot_recovery)
else:
logger.info("Skipping flashing recovery.")
self.steps = [
Step(
title="Boot custom recovery",
type="confirm_button",
content="If you already flashed TWRP, boot into it by pressing 'Confirm and run'. Otherwise restart the process. Once your phone screen looks like the picture on the left, continue.",
command="adb_reboot_recovery",
img="twrp-start.jpeg",
)
]
......@@ -161,6 +161,15 @@ def adb_wait_for_sideload(bin_path: Path) -> TerminalResponse:
yield line
@add_logging("Reboot to recovery with adb")
def adb_reboot_recovery(bin_path: Path) -> TerminalResponse:
"""Reboot to recovery with adb."""
for line in run_command("adb reboot recovery", bin_path):
yield line
for line in adb_wait_for_recovery(bin_path=bin_path):
yield line
def adb_twrp_copy_partitions(bin_path: Path, config_path: Path) -> TerminalResponse:
# some devices like one plus 6t or motorola moto g7 power need the partitions copied to prevent a hard brick
logger.info("Sideload copy_partitions script with adb.")
......
......@@ -251,33 +251,38 @@ The image file should look something like `lineage-19.1-20221101-nightly-{self.s
),
self.selected_image,
Divider(),
Text("Select a TWRP recovery image:", style="titleSmall"),
Markdown(
f"""
]
)
if self.state.flash_recovery:
self.right_view.controls.extend(
[
Text("Select a TWRP recovery image:", style="titleSmall"),
Markdown(
f"""
The recovery image should look something like `twrp-3.7.0_12-0-{self.state.config.device_code}.img`.
**Note:** This tool **only supports TWRP recoveries**.""",
extension_set="gitHubFlavored",
),
Row(
[
FilledButton(
"Pick TWRP recovery file",
icon=icons.UPLOAD_FILE,
on_click=lambda _: self.pick_recovery_dialog.pick_files(
allow_multiple=False,
file_type="custom",
allowed_extensions=["img"],
extension_set="gitHubFlavored",
),
Row(
[
FilledButton(
"Pick TWRP recovery file",
icon=icons.UPLOAD_FILE,
on_click=lambda _: self.pick_recovery_dialog.pick_files(
allow_multiple=False,
file_type="custom",
allowed_extensions=["img"],
),
expand=True,
),
expand=True,
),
]
),
self.selected_recovery,
Divider(),
self.additional_image_selection,
]
)
]
),
self.selected_recovery,
Divider(),
self.additional_image_selection,
]
)
# attach the bottom buttons
self.right_view.controls.extend(
......@@ -296,11 +301,11 @@ The recovery image should look something like `twrp-3.7.0_12-0-{self.state.confi
notes = []
brand = self.state.config.metadata.get("brand", "")
if brand in "xiaomi":
if brand == "xiaomi":
notes.append(
"- If something goes wrong, you can reinstall MiUI here:\n<https://xiaomifirmwareupdater.com/>\n"
)
elif brand in "poco":
elif brand == "poco":
notes.append(
f"- If something goes wrong, you can reinstall MiUI here:\n<https://xiaomifirmwareupdater.com/miui/{self.state.config.device_code}/>\n"
)
......@@ -498,14 +503,15 @@ Make sure the file is for **your exact phone model!**""",
else:
self.selected_image.color = colors.RED
# if the image works and the sdk level is 33 or higher, show the additional image selection
if (
self.selected_image.color == colors.GREEN
and image_sdk_level(self.state.image_path) >= 33
):
self.toggle_additional_image_selection()
else:
self.additional_image_selection.controls = []
self.additional_image_selection.update()
if self.state.flash_recovery:
if (
self.selected_image.color == colors.GREEN
and image_sdk_level(self.state.image_path) >= 33
):
self.toggle_additional_image_selection()
else:
self.additional_image_selection.controls = []
self.additional_image_selection.update()
# update
self.selected_image.update()
......@@ -523,9 +529,9 @@ Make sure the file is for **your exact phone model!**""",
logger.info("No image selected.")
# check if the recovery works with the device and show the filename in different colors accordingly
if e.files:
device_code = self.state.config.device_code
if recovery_works_with_device(
device_code=device_code, recovery_path=self.state.recovery_path
supported_device_codes=self.state.config.supported_device_codes,
recovery_path=self.state.recovery_path,
):
self.selected_recovery.color = colors.GREEN
else:
......@@ -642,5 +648,31 @@ Make sure the file is for **your exact phone model!**""",
self.info_field.controls = []
self.confirm_button.disabled = False
self.right_view.update()
elif (".zip" in self.selected_image.value) and (not self.state.flash_recovery):
if not (
image_works_with_device(
supported_device_codes=self.state.config.supported_device_codes,
image_path=self.state.image_path,
)
):
# if image works for device allow to move on, otherwise display message
logger.error(
"Image doesn't work with the device. Please select a different one."
)
self.info_field.controls = [
Text(
"Image doesn't work with the device.",
color=colors.RED,
weight="bold",
)
]
self.confirm_button.disabled = True
self.right_view.update()
return
logger.info("Image works with the device. You can continue.")
self.info_field.controls = []
self.confirm_button.disabled = False
self.right_view.update()
else:
self.confirm_button.disabled = True
......@@ -13,7 +13,6 @@
# If not, see <https://www.gnu.org/licenses/>."""
# Author: Tobias Sterbak
import copy
import webbrowser
from loguru import logger
from typing import Callable
......@@ -99,15 +98,7 @@ Now you are ready to continue.
# toggleswitch to allow skipping unlocking the bootloader
def check_bootloader_unlocked(e):
"""Enable skipping unlocking the bootloader if selected."""
if self.bootloader_switch.value:
logger.info("Skipping bootloader unlocking.")
self.state.steps = []
else:
logger.info("Enabled unlocking the bootloader again.")
self.state.steps = copy.deepcopy(self.state.config.unlock_bootloader)
# if the recovery is already flashed, skip flashing it again
if self.recovery_switch.value == False:
self.state.steps += copy.deepcopy(self.state.config.boot_recovery)
self.state.toggle_flash_unlock_bootloader()
self.bootloader_switch = Switch(
label="Bootloader is already unlocked.",
......@@ -120,17 +111,7 @@ Now you are ready to continue.
# toggleswitch to allow skipping flashing recovery
def check_recovery_already_flashed(e):
"""Enable skipping flashing recovery if selected."""
# manage the bootloader unlocking switch
if self.bootloader_switch.value == False:
self.state.steps = copy.deepcopy(self.state.config.unlock_bootloader)
else:
self.state.steps = []
if self.recovery_switch.value:
logger.info("Skipping flashing recovery.")
else:
logger.info("Enabled flashing recovery again.")
self.state.steps += copy.deepcopy(self.state.config.boot_recovery)
self.state.toggle_flash_recovery()
self.recovery_switch = Switch(
label="Custom recovery is already flashed.",
......
......@@ -41,6 +41,7 @@ from tooling import (
adb_reboot,
adb_reboot_bootloader,
adb_reboot_download,
adb_reboot_recovery,
adb_sideload,
adb_twrp_copy_partitions,
fastboot_boot_recovery,
......@@ -216,6 +217,7 @@ class StepView(BaseView):
"adb_reboot": adb_reboot,
"adb_reboot_bootloader": adb_reboot_bootloader,
"adb_reboot_download": adb_reboot_download,
"adb_reboot_recovery": adb_reboot_recovery,
"adb_sideload": partial(adb_sideload, target=self.state.image_path),
"adb_twrp_copy_partitions": partial(
adb_twrp_copy_partitions, config_path=self.state.config_path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment