Skip to content

Commit 2df4a66

Browse files
committed
Replace detect_is_ab_device by field in the config
1 parent 916386e commit 2df4a66

File tree

9 files changed

+9
-90
lines changed

9 files changed

+9
-90
lines changed

openandroidinstaller/app_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def __init__(
4343
self.config = None
4444
self.image_path = None
4545
self.recovery_path = None
46-
self.is_ab = None
4746

4847
# store views
4948
self.default_views: List = []

openandroidinstaller/assets/configs/sargo.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
metadata:
22
maintainer: Tobias Sterbak (tsterbak)
33
device_name: Pixel 3a
4-
device_code: sargo
4+
is_ab_device: true
5+
device_code: sargo
56
supported_device_codes:
67
- sargo
78
requirements:

openandroidinstaller/installer_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
self.metadata = metadata
6262
self.requirements = requirements
6363
self.device_code = metadata.get("device_code")
64+
self.is_ab = metadata.get("is_ab_device", False)
6465
self.supported_device_codes = metadata.get("supported_device_codes")
6566
self.twrp_link = metadata.get("twrp-link")
6667

@@ -161,6 +162,7 @@ def validate_config(config: str) -> bool:
161162
"metadata": {
162163
"maintainer": str,
163164
"device_name": str,
165+
"is_ab_device": bool,
164166
"device_code": str,
165167
"supported_device_codes": [str],
166168
schema.Optional("twrp-link"): str,

openandroidinstaller/tooling.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -468,43 +468,3 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
468468
except CalledProcessError:
469469
logger.error("Failed to detect a device.")
470470
return None
471-
472-
473-
def check_ab_partition(platform: str, bin_path: Path) -> Optional[bool]:
474-
"""Figure out, if its an a/b-partitioned device."""
475-
logger.info(f"Run on {platform} with {bin_path}...")
476-
try:
477-
# check if ab device
478-
if platform in ("linux", "darwin"):
479-
output = check_output(
480-
[
481-
str(bin_path.joinpath(Path("adb"))),
482-
"shell",
483-
"getprop",
484-
"|",
485-
"grep",
486-
"ro.boot.slot_suffix",
487-
],
488-
stderr=STDOUT,
489-
).decode()
490-
elif platform in ("windows", "win32"):
491-
output = check_output(
492-
[
493-
str(bin_path.joinpath(Path("adb.exe"))),
494-
"shell",
495-
"getprop",
496-
"|",
497-
"findstr",
498-
"ro.boot.slot_suffix",
499-
],
500-
stderr=STDOUT,
501-
shell=True,
502-
).decode()
503-
else:
504-
raise Exception(f"Unknown platform {platform}.")
505-
logger.info(output)
506-
logger.info("This is an a/b-partitioned device.")
507-
return True
508-
except CalledProcessError:
509-
logger.info("This is not an a/b-partitioned device.")
510-
return False

openandroidinstaller/views/install_addons_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def run_install_addons(self, e):
158158
for line in adb_twrp_install_addons(
159159
addons=self.state.addon_paths,
160160
bin_path=self.state.bin_path,
161-
is_ab=self.state.is_ab,
161+
is_ab=self.state.config.is_ab,
162162
):
163163
# write the line to advanced output terminal
164164
self.terminal_box.write_line(line)

openandroidinstaller/views/install_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def run_install(self, e):
189189
config_path=self.state.config_path,
190190
bin_path=self.state.bin_path,
191191
install_addons=self.state.install_addons,
192-
is_ab=self.state.is_ab,
192+
is_ab=self.state.config.is_ab,
193193
recovery=self.state.recovery_path,
194194
):
195195
# write the line to advanced output terminal

openandroidinstaller/views/start_view.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def search_devices(self, e):
213213
# search the device
214214
if self.state.test:
215215
# this only happens for testing
216-
device_code, is_ab = self.state.test_config, True
216+
device_code = self.state.test_config
217217
logger.info(
218218
f"Running search in development mode and loading config {device_code}.yaml."
219219
)
@@ -239,8 +239,6 @@ def search_devices(self, e):
239239
self.device_name.value = device_code
240240
# load config from file
241241
self.state.load_config(device_code)
242-
# write ab-info to state
243-
self.state.is_ab = is_ab
244242
if self.state.config:
245243
device_name = self.state.config.metadata.get(
246244
"device_name", "No device name in config."

openandroidinstaller/views/step_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def call_to_phone(self, e, command: str):
220220
"fastboot_boot_recovery": partial(
221221
fastboot_boot_recovery,
222222
recovery=self.state.recovery_path,
223-
is_ab=self.state.is_ab,
223+
is_ab=self.state.config.is_ab,
224224
),
225225
"fastboot_flash_boot": partial(
226226
fastboot_flash_boot,

tests/test_tooling.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from openandroidinstaller.tooling import (
2020
adb_reboot,
2121
search_device,
22-
check_ab_partition,
2322
)
2423

2524

@@ -95,44 +94,4 @@ def patched_check_output(*args, **kwargs):
9594
platform="linux", bin_path=Path("openandroidinstaller/bin/")
9695
)
9796

98-
assert device_code == None
99-
100-
101-
def test_check_ab_device_is_ab(mocker):
102-
"""Test if checking for ab device works fine."""
103-
mocker.patch(
104-
"openandroidinstaller.tooling.check_output",
105-
return_value=b"[ro.boot.slot_suffix]: [_b]",
106-
)
107-
108-
# test linux
109-
is_ab = check_ab_partition(
110-
platform="linux", bin_path=Path("openandroidinstaller/bin/")
111-
)
112-
113-
assert is_ab
114-
115-
# test windows
116-
is_ab = check_ab_partition(
117-
platform="windows", bin_path=Path("openandroidinstaller/bin/")
118-
)
119-
120-
assert is_ab
121-
122-
123-
def test_check_ab_device_not_ab(mocker):
124-
"""Test if checking for ab device returns False if it fails."""
125-
126-
def patched_check_output(*args, **kwargs):
127-
raise CalledProcessError(returncode=1, cmd="output is None")
128-
129-
mocker.patch(
130-
"openandroidinstaller.tooling.check_output",
131-
patched_check_output,
132-
)
133-
134-
is_ab = check_ab_partition(
135-
platform="linux", bin_path=Path("openandroidinstaller/bin/")
136-
)
137-
138-
assert not is_ab
97+
assert device_code == None

0 commit comments

Comments
 (0)