Skip to content

Commit

Permalink
If adb twrp format data fails, retry with adb twrp wipe data (#142)
Browse files Browse the repository at this point in the history
If `adb twrp format data` fails, retry with `adb twrp wipe data`. This
should address issues with old versions of TWRP as found in #140.
  • Loading branch information
tsterbak committed May 13, 2023
2 parents 74377ab + 3f7a878 commit ad81cca
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,25 @@ def adb_twrp_copy_partitions(bin_path: Path, config_path: Path) -> TerminalRespo

@add_logging("Perform a factory reset with adb and twrp.", return_if_fail=True)
def adb_twrp_format_data(bin_path: Path) -> 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`.
"""
unknown_command = False
for line in run_command("adb shell twrp format data", bin_path):
if (type(line) == str) and ("Unrecognized script command" in line):
unknown_command = True
yield line

# if it fails because the command is unknown, retry with wipe data.
if unknown_command:
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


@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:
Expand Down

0 comments on commit ad81cca

Please sign in to comment.