Skip to content

Commit 0afb39b

Browse files
committed
Change activating sideload since behaviour of adb with regards to return codes seems to have changed with versione 35.0.1
1 parent 7481137 commit 0afb39b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

openandroidinstaller/tooling.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def add_logging(step_desc: str, return_if_fail: bool = False) -> Callable:
7373
"""Logging decorator to wrap functions that yield lines.
7474
7575
Logs the `step_desc`.
76+
77+
Args:
78+
step_desc: Description of the step.
79+
return_if_fail: If True, return False if the function fails.
7680
"""
7781

7882
def logging_decorator(func) -> Callable:
@@ -94,14 +98,14 @@ def logging(*args, **kwargs) -> TerminalResponse:
9498
@add_logging("Rebooting device with adb.")
9599
def adb_reboot(bin_path: Path) -> TerminalResponse:
96100
"""Run adb reboot on the device and return success."""
97-
for line in run_command("adb reboot", bin_path):
101+
for line in run_command("adb -d reboot", bin_path):
98102
yield line
99103

100104

101105
@add_logging("Rebooting device into bootloader with adb.", return_if_fail=True)
102106
def adb_reboot_bootloader(bin_path: Path) -> TerminalResponse:
103107
"""Reboot the device into bootloader and return success."""
104-
for line in run_command("adb reboot bootloader", bin_path):
108+
for line in run_command("adb -d reboot bootloader", bin_path):
105109
yield line
106110
# wait for the bootloader to become available
107111
for line in fastboot_wait_for_bootloader(bin_path=bin_path):
@@ -111,22 +115,22 @@ def adb_reboot_bootloader(bin_path: Path) -> TerminalResponse:
111115
@add_logging("Rebooting device into download mode with adb.")
112116
def adb_reboot_download(bin_path: Path) -> TerminalResponse:
113117
"""Reboot the device into download mode of samsung devices and return success."""
114-
for line in run_command("adb reboot download", bin_path):
118+
for line in run_command("adb -d reboot download", bin_path):
115119
yield line
116120
yield heimdall_wait_for_download_available(bin_path=bin_path)
117121

118122

119123
@add_logging("Sideload the target to device with adb.")
120124
def adb_sideload(bin_path: Path, target: str) -> TerminalResponse:
121125
"""Sideload the target to device and return success."""
122-
for line in run_command("adb sideload", target=target, bin_path=bin_path):
126+
for line in run_command("adb -d sideload", target=target, bin_path=bin_path):
123127
yield line
124128

125129

126-
@add_logging("Activate sideloading in TWRP.", return_if_fail=True)
130+
@add_logging("Activate sideloading in TWRP.", return_if_fail=False)
127131
def activate_sideload(bin_path: Path) -> TerminalResponse:
128132
"""Activate sideload with adb shell in twrp."""
129-
for line in run_command("adb shell twrp sideload", bin_path):
133+
for line in run_command("adb -d shell twrp sideload", bin_path):
130134
yield line
131135
for line in adb_wait_for_sideload(bin_path=bin_path):
132136
yield line
@@ -135,28 +139,28 @@ def activate_sideload(bin_path: Path) -> TerminalResponse:
135139
@add_logging("Wait for device")
136140
def adb_wait_for_device(bin_path: Path) -> TerminalResponse:
137141
"""Use adb to wait for the device to become available."""
138-
for line in run_command("adb wait-for-device", bin_path):
142+
for line in run_command("adb -d wait-for-device", bin_path):
139143
yield line
140144

141145

142146
@add_logging("Wait for recovery")
143147
def adb_wait_for_recovery(bin_path: Path) -> TerminalResponse:
144148
"""Use adb to wait for the recovery to become available."""
145-
for line in run_command("adb wait-for-recovery", bin_path):
149+
for line in run_command("adb -d wait-for-recovery", bin_path):
146150
yield line
147151

148152

149153
@add_logging("Wait for sideload")
150154
def adb_wait_for_sideload(bin_path: Path) -> TerminalResponse:
151155
"""Use adb to wait for the sideload to become available."""
152-
for line in run_command("adb wait-for-sideload", bin_path):
156+
for line in run_command("adb -d wait-for-sideload", bin_path):
153157
yield line
154158

155159

156160
@add_logging("Reboot to recovery with adb")
157161
def adb_reboot_recovery(bin_path: Path) -> TerminalResponse:
158162
"""Reboot to recovery with adb."""
159-
for line in run_command("adb reboot recovery", bin_path):
163+
for line in run_command("adb -d reboot recovery", bin_path):
160164
yield line
161165
for line in adb_wait_for_recovery(bin_path=bin_path):
162166
yield line
@@ -190,7 +194,7 @@ def adb_twrp_format_data(bin_path: Path) -> TerminalResponse:
190194
If `format data` fails (for example because of old TWRP versions) we fall back to `wipe data`.
191195
"""
192196
unknown_command = False
193-
for line in run_command("adb shell twrp format data", bin_path):
197+
for line in run_command("adb -d shell twrp format data", bin_path):
194198
if isinstance(line, str) and ("Unrecognized script command" in line):
195199
unknown_command = True
196200
yield line
@@ -208,7 +212,7 @@ def adb_twrp_format_data(bin_path: Path) -> TerminalResponse:
208212
@add_logging("Wipe the selected partition with adb and twrp.", return_if_fail=True)
209213
def adb_twrp_wipe_partition(bin_path: Path, partition: str) -> TerminalResponse:
210214
"""Perform a factory reset with twrp and adb."""
211-
for line in run_command(f"adb shell twrp wipe {partition}", bin_path):
215+
for line in run_command(f"adb -d shell twrp wipe {partition}", bin_path):
212216
yield line
213217

214218

@@ -633,8 +637,8 @@ def search_device(platform: str, bin_path: Path) -> SearchResult:
633637
device_code=device_code,
634638
msg=f"Found device with device code '{device_code}'.",
635639
)
636-
except CalledProcessError as e:
637-
logger.error(f"Failed to detect a device. {e}")
640+
except CalledProcessError:
641+
logger.error("Failed to detect a device")
638642
return SearchResult(
639643
msg="Failed to detect a device. Connect to USB and try again."
640644
)

0 commit comments

Comments
 (0)