From f46439634d2e3ed36dd9391abfcad50076595b8c Mon Sep 17 00:00:00 2001 From: rudu <40572253+anon1892@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:58:29 +0200 Subject: [PATCH] Add function to know image sdk (mainly Android version+20) --- openandroidinstaller/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/openandroidinstaller/utils.py b/openandroidinstaller/utils.py index 0c17baf5..47aefcaa 100644 --- a/openandroidinstaller/utils.py +++ b/openandroidinstaller/utils.py @@ -59,6 +59,20 @@ def image_works_with_device(supported_device_codes: List[str], image_path: str) ) return False +def image_sdk_level(image_path: str) -> int: + """ + Determine Android version of the selected image. + Android 13 : 33 + """ + 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() + for line in metadata: + if b"sdk-level" in line: + return int(line[line.find(b'=')+1:-1].decode("utf-8")) + return 0 def recovery_works_with_device(device_code: str, recovery_path: str) -> bool: """Determine if a recovery works for the given device.