Skip to content

Commit 357002c

Browse files
committed
Add fastboot_flash_recovery and fastboot_reboot_recovery from anon1892
1 parent 661f9b4 commit 357002c

4 files changed

Lines changed: 85 additions & 20 deletions

File tree

openandroidinstaller/tooling.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,40 @@ def fastboot_flash_boot(bin_path: Path, recovery: str) -> TerminalResponse:
440440
yield True
441441

442442

443+
@add_logging("Flash custom recovery with fastboot.")
444+
def fastboot_flash_recovery(
445+
bin_path: Path, recovery: str, is_ab: bool = True
446+
) -> TerminalResponse:
447+
"""Flash custom recovery with fastboot."""
448+
for line in run_command(
449+
"fastboot flash recovery ", target=f"{recovery}", bin_path=bin_path
450+
):
451+
yield line
452+
if not is_ab:
453+
if (type(line) == bool) and not line:
454+
logger.error("Flashing recovery failed.")
455+
yield False
456+
else:
457+
yield True
458+
459+
460+
@add_logging("Rebooting device to recovery.")
461+
def fastboot_reboot_recovery(bin_path: Path) -> TerminalResponse:
462+
"""Reboot to recovery with fastboot.
463+
464+
WARNING: On some devices, users need to press a specific key combo to make it work.
465+
"""
466+
for line in run_command("fastboot reboot recovery", bin_path):
467+
yield line
468+
469+
443470
@add_logging("Flash additional partitions with fastboot")
444471
def fastboot_flash_additional_partitions(
445-
bin_path: Path, dtbo: Optional[str], vbmeta: Optional[str], super_empty: Optional[str], is_ab: bool = True
472+
bin_path: Path,
473+
dtbo: Optional[str],
474+
vbmeta: Optional[str],
475+
super_empty: Optional[str],
476+
is_ab: bool = True,
446477
) -> TerminalResponse:
447478
"""Flash additional partitions (dtbo, vbmeta, super_empty) with fastboot."""
448479
logger.info("Flash additional partitions with fastboot.")
@@ -544,4 +575,4 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
544575
return device_code
545576
except CalledProcessError:
546577
logger.error("Failed to detect a device.")
547-
return None
578+
return None

openandroidinstaller/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def image_works_with_device(supported_device_codes: List[str], image_path: str)
6363
def image_sdk_level(image_path: str) -> int:
6464
"""Determine Android version of the selected image.
6565
66-
Example:
66+
Example:
6767
Android 13: 33
6868
"""
6969
with zipfile.ZipFile(image_path) as image_zip:

openandroidinstaller/views/select_view.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
from views import BaseView
4242
from app_state import AppState
4343
from widgets import get_title, confirm_button
44-
from utils import get_download_link, image_works_with_device, recovery_works_with_device, image_sdk_level
44+
from utils import (
45+
get_download_link,
46+
image_works_with_device,
47+
recovery_works_with_device,
48+
image_sdk_level,
49+
)
4550

4651

4752
class SelectFilesView(BaseView):
@@ -104,9 +109,15 @@ def init_visuals(
104109

105110
self.selected_image = Text("Selected image: ")
106111
self.selected_recovery = Text("Selected recovery: ")
107-
self.selected_dtbo = Checkbox(fill_color=colors.RED, value=None, disabled=True, tristate=True)
108-
self.selected_vbmeta = Checkbox(fill_color=colors.RED, value=None, disabled=True, tristate=True)
109-
self.selected_super_empty = Checkbox(fill_color=colors.RED, value=None, disabled=True, tristate=True)
112+
self.selected_dtbo = Checkbox(
113+
fill_color=colors.RED, value=None, disabled=True, tristate=True
114+
)
115+
self.selected_vbmeta = Checkbox(
116+
fill_color=colors.RED, value=None, disabled=True, tristate=True
117+
)
118+
self.selected_super_empty = Checkbox(
119+
fill_color=colors.RED, value=None, disabled=True, tristate=True
120+
)
110121

111122
# initialize and manage button state.
112123
self.confirm_button = confirm_button(self.on_confirm)
@@ -133,13 +144,15 @@ def build(self):
133144
)
134145

135146
# attach hidden dialogues
136-
self.right_view.controls.extend([
137-
self.pick_image_dialog,
138-
self.pick_recovery_dialog,
139-
self.pick_dtbo_dialog,
140-
self.pick_vbmeta_dialog,
141-
self.pick_super_empty_dialog
142-
])
147+
self.right_view.controls.extend(
148+
[
149+
self.pick_image_dialog,
150+
self.pick_recovery_dialog,
151+
self.pick_dtbo_dialog,
152+
self.pick_vbmeta_dialog,
153+
self.pick_super_empty_dialog,
154+
]
155+
)
143156

144157
# create help/info button to show the help dialog
145158
info_button = OutlinedButton(
@@ -264,14 +277,17 @@ def toggle_additional_image_selection(self):
264277
# attach the controls for uploading others partitions, like dtbo, vbmeta & super_empty
265278
additional_image_selection = []
266279
if self.state.config.metadata["additional_steps"]:
267-
additional_image_selection.extend([
280+
additional_image_selection.extend(
281+
[
268282
Text("Select required additional images:", style="titleSmall"),
269-
Markdown("""
283+
Markdown(
284+
"""
270285
Your selected device and ROM requires flashing of additional partitions. Please select the required images below.
271286
272287
Make sure the file is for **your exact phone model!**""",
273-
)
274-
])
288+
),
289+
]
290+
)
275291
if "dtbo" in self.state.config.metadata["additional_steps"]:
276292
self.selected_dtbo.value = False
277293
additional_image_selection.extend(
@@ -372,7 +388,10 @@ def pick_image_result(self, e: FilePickerResultEvent):
372388
else:
373389
self.selected_image.color = colors.RED
374390
# if the image works and the sdk level is 33 or higher, show the additional image selection
375-
if self.selected_image.color == colors.GREEN and image_sdk_level(self.state.image_path) >= 33:
391+
if (
392+
self.selected_image.color == colors.GREEN
393+
and image_sdk_level(self.state.image_path) >= 33
394+
):
376395
self.toggle_additional_image_selection()
377396
else:
378397
self.additional_image_selection.controls = []
@@ -485,7 +504,14 @@ def enable_button_if_ready(self, e):
485504
return
486505

487506
# check if the additional images work with the device
488-
if any(v == False for v in [self.selected_dtbo.value, self.selected_vbmeta.value, self.selected_super_empty.value]):
507+
if any(
508+
v == False
509+
for v in [
510+
self.selected_dtbo.value,
511+
self.selected_vbmeta.value,
512+
self.selected_super_empty.value,
513+
]
514+
):
489515
logger.error(
490516
"Some additional images don't match. Please select different ones."
491517
)

openandroidinstaller/views/step_view.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
adb_twrp_copy_partitions,
4646
fastboot_boot_recovery,
4747
fastboot_flash_boot,
48+
fastboot_flash_recovery,
49+
fastboot_reboot_recovery,
4850
fastboot_flash_additional_partitions,
4951
fastboot_oem_unlock,
5052
fastboot_reboot,
@@ -234,6 +236,12 @@ def call_to_phone(self, e, command: str):
234236
fastboot_flash_boot,
235237
recovery=self.state.recovery_path,
236238
),
239+
"fastboot_flash_recovery": partial(
240+
fastboot_flash_recovery,
241+
recovery=self.state.recovery_path,
242+
is_ab=self.state.config.is_ab,
243+
),
244+
"fastboot_reboot_recovery": fastboot_reboot_recovery,
237245
"fastboot_flash_additional_partitions": partial(
238246
fastboot_flash_additional_partitions,
239247
dtbo=self.state.dtbo_path,

0 commit comments

Comments
 (0)