Skip to content

Commit ad81cca

Browse files
authored
If adb twrp format data fails, retry with adb twrp wipe data (#142)
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.
2 parents 74377ab + 3f7a878 commit ad81cca

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

openandroidinstaller/tooling.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,25 @@ def adb_twrp_copy_partitions(bin_path: Path, config_path: Path) -> TerminalRespo
184184

185185
@add_logging("Perform a factory reset with adb and twrp.", return_if_fail=True)
186186
def adb_twrp_format_data(bin_path: Path) -> TerminalResponse:
187-
"""Perform a factory reset with twrp and adb."""
187+
"""Perform a factory reset with twrp and adb.
188+
189+
If `format data` fails (for example because of old TWRP versions) we fall back to `wipe data`.
190+
"""
191+
unknown_command = False
188192
for line in run_command("adb shell twrp format data", bin_path):
193+
if (type(line) == str) and ("Unrecognized script command" in line):
194+
unknown_command = True
189195
yield line
190196

197+
# if it fails because the command is unknown, retry with wipe data.
198+
if unknown_command:
199+
logger.info(
200+
"Factory reset with `adb twrp format data` failed. Trying `adb twrp wipe data` now."
201+
)
202+
sleep(1)
203+
for line in adb_twrp_wipe_partition(bin_path=bin_path, partition="data"):
204+
yield line
205+
191206

192207
@add_logging("Wipe the selected partition with adb and twrp.", return_if_fail=True)
193208
def adb_twrp_wipe_partition(bin_path: Path, partition: str) -> TerminalResponse:

0 commit comments

Comments
 (0)