From a4aa74d73022a41b7984bb9989a0cd5f91540746 Mon Sep 17 00:00:00 2001 From: Tobias Sterbak Date: Wed, 19 Apr 2023 19:30:43 +0200 Subject: [PATCH] If adb twrp format data fails, retry with adb twrp wipe data --- openandroidinstaller/tooling.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openandroidinstaller/tooling.py b/openandroidinstaller/tooling.py index c8b95dfd..69279217 100644 --- a/openandroidinstaller/tooling.py +++ b/openandroidinstaller/tooling.py @@ -184,9 +184,19 @@ def adb_twrp_format_data(bin_path: Path) -> TerminalResponse: @add_logging("Wipe the selected partition with adb and twrp.", return_if_fail=True) def adb_twrp_wipe_partition(bin_path: Path, partition: str) -> TerminalResponse: - """Perform a factory reset with twrp and adb.""" + """Perform a factory reset with twrp and adb. + + If `format data` fails (for example because of old TWRP versions) we fall back to `wipe data`. + """ for line in run_command(f"adb shell twrp wipe {partition}", bin_path): yield line + if (type(line) == bool) and not line: + logger.info( + "Factory reset with `adb twrp format data` failed. Trying `adb twrp wipe data` now." + ) + sleep(1) + for line in adb_twrp_wipe_partition(bin_path=bin_path, partition="data"): + yield line def adb_twrp_wipe_and_install(