Skip to content

Commit f464396

Browse files
author
rudu
committed
Add function to know image sdk (mainly Android version+20)
1 parent 0604ff1 commit f464396

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

openandroidinstaller/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ def image_works_with_device(supported_device_codes: List[str], image_path: str)
5959
)
6060
return False
6161

62+
def image_sdk_level(image_path: str) -> int:
63+
"""
64+
Determine Android version of the selected image.
65+
Android 13 : 33
66+
"""
67+
with zipfile.ZipFile(image_path) as image_zip:
68+
with image_zip.open(
69+
"META-INF/com/android/metadata", mode="r"
70+
) as image_metadata:
71+
metadata = image_metadata.readlines()
72+
for line in metadata:
73+
if b"sdk-level" in line:
74+
return int(line[line.find(b'=')+1:-1].decode("utf-8"))
75+
return 0
6276

6377
def recovery_works_with_device(device_code: str, recovery_path: str) -> bool:
6478
"""Determine if a recovery works for the given device.

0 commit comments

Comments
 (0)