Skip to content

Commit f2ae4a6

Browse files
committed
Implemement a fix with alternative device code resolution
1 parent b179bf9 commit f2ae4a6

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

openandroidinstaller/installer_config.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ def __init__(
4949

5050

5151
class InstallerConfig:
52+
53+
# map some detected device codes to their real code.
54+
device_code_mapping = {
55+
# Sony issues
56+
"C6603": "yuga",
57+
# OnePlus issues
58+
"OnePlus6": "enchilada",
59+
"OnePlus6T": "fajita",
60+
"OnePlus7": "guacamoleb",
61+
"OnePlus7Pro": "guacamole",
62+
"OnePlus7T": "hotdogb",
63+
"OnePlus7TPro": "hotdog",
64+
"Nord": "avicii",
65+
"NordN200": "dre",
66+
}
67+
5268
def __init__(
5369
self,
5470
unlock_bootloader: List[Step],
@@ -62,6 +78,10 @@ def __init__(
6278
self.install_os = install_os
6379
self.metadata = metadata
6480
self.requirements = requirements
81+
self.device_code = metadata.get("devicecode")
82+
self.alternative_device_code = self.device_code_mapping.get(
83+
self.device_code, self.device_code
84+
)
6585

6686
@classmethod
6787
def from_file(cls, path):
@@ -107,15 +127,18 @@ def _load_config(device_code: str, config_path: Path) -> Optional[InstallerConfi
107127
Try to load local file in the same directory as the executable first, then load from assets.
108128
"""
109129
# try loading a custom local file first
110-
custom_path = Path.cwd().joinpath(Path(f"{device_code}.yaml"))
130+
mapped_device_code = InstallerConfig.device_code_mapping.get(
131+
device_code, device_code
132+
)
133+
custom_path = Path.cwd().joinpath(Path(f"{mapped_device_code}.yaml"))
111134
try:
112135
config = InstallerConfig.from_file(custom_path)
113136
logger.info(f"Loaded custom device config from {custom_path}.")
114137
logger.info(f"Config metadata: {config.metadata}.")
115138
return config
116139
except FileNotFoundError:
117140
# if no localfile, then try to load a config file from assets
118-
path = config_path.joinpath(Path(f"{device_code}.yaml"))
141+
path = config_path.joinpath(Path(f"{mapped_device_code}.yaml"))
119142
try:
120143
config = InstallerConfig.from_file(path)
121144
logger.info(f"Loaded device config from {path}.")

openandroidinstaller/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def get_download_link(devicecode: str) -> Optional[str]:
3939
return
4040

4141

42-
def image_works_with_device(device_code: str, image_path: str) -> bool:
42+
def image_works_with_device(
43+
device_code: str, alternative_device_code: str, image_path: str
44+
) -> bool:
4345
"""Determine if an image works for the given device."""
4446
with zipfile.ZipFile(image_path) as image_zip:
4547
with image_zip.open(
@@ -49,7 +51,9 @@ def image_works_with_device(device_code: str, image_path: str) -> bool:
4951
supported_devices = str(metadata[-1]).split("=")[-1][:-3].split(",")
5052
logger.info(f"Image works with device: {supported_devices}")
5153

52-
if device_code in supported_devices:
54+
if (device_code in supported_devices) or (
55+
alternative_device_code in supported_devices
56+
):
5357
logger.success("Device supported by the selected image.")
5458
return True
5559
else:

openandroidinstaller/views/select_view.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,11 @@ def pick_image_result(self, e: FilePickerResultEvent):
237237
logger.info("No image selected.")
238238
# check if the image works with the device and show the filename in different colors accordingly
239239
if e.files:
240-
device_code = self.state.config.metadata.get("devicecode")
240+
device_code = self.state.config.device_code
241241
if image_works_with_device(
242-
device_code=device_code, image_path=self.state.image_path
242+
device_code=device_code,
243+
alternative_device_code=self.state.config.alternative_device_code,
244+
image_path=self.state.image_path,
243245
):
244246
self.selected_image.color = colors.GREEN
245247
else:
@@ -261,7 +263,7 @@ def pick_recovery_result(self, e: FilePickerResultEvent):
261263
logger.info("No image selected.")
262264
# check if the recovery works with the device and show the filename in different colors accordingly
263265
if e.files:
264-
device_code = self.state.config.metadata.get("devicecode")
266+
device_code = self.state.config.device_code
265267
if recovery_works_with_device(
266268
device_code=device_code, recovery_path=self.state.recovery_path
267269
):
@@ -276,10 +278,12 @@ def enable_button_if_ready(self, e):
276278
if (".zip" in self.selected_image.value) and (
277279
".img" in self.selected_recovery.value
278280
):
279-
device_code = self.state.config.metadata.get("devicecode")
281+
device_code = self.state.config.device_code
280282
if not (
281283
image_works_with_device(
282-
device_code=device_code, image_path=self.state.image_path
284+
device_code=device_code,
285+
alternative_device_code=self.state.config.alternative_device_code,
286+
image_path=self.state.image_path,
283287
)
284288
and recovery_works_with_device(
285289
device_code=device_code, recovery_path=self.state.recovery_path

0 commit comments

Comments
 (0)