Skip to content

Commit

Permalink
Little fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anon1892 committed Jan 14, 2024
1 parent fe5644f commit 9b4b633
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions openandroidinstaller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,28 @@ def image_works_with_device(supported_device_codes: List[str], image_path: str)
True if the image works with the device, False otherwise.
"""
with zipfile.ZipFile(image_path) as image_zip:
with image_zip.open(
"META-INF/com/android/metadata", mode="r"
) as image_metadata:
metadata = image_metadata.readlines()
supported_devices = str(metadata[-1]).split("=")[-1][:-3].split(",")
logger.info(f"Image works with device: {supported_devices}")

if any(code in supported_devices for code in supported_device_codes):
logger.success("Device supported by the selected image.")
return True
else:
logger.error(
f"Image file {image_path.split('/')[-1]} is not supported."
)
return False
try:
with image_zip.open(
"META-INF/com/android/metadata", mode="r"
) as image_metadata:
metadata = image_metadata.readlines()
supported_devices = str(metadata[-1]).split("=")[-1][:-3].split(",")
logger.info(f"Image works with device: {supported_devices}")

if any(code in supported_devices for code in supported_device_codes):
logger.success("Device supported by the selected image.")
return True
else:
logger.error(
f"Image file {image_path.split('/')[-1]} is not supported."
)
return False
except KeyError:
logger.error("Selected image does not contains a metadata file. Can't check compatibility with the device")
return False
except zipfile.BadZipFile:
logger.error("Selected image is not a zip file.")
return False


def image_sdk_level(image_path: str) -> int:
Expand Down

0 comments on commit 9b4b633

Please sign in to comment.