@@ -20,6 +20,7 @@ def get_product_props(value: str):
2020DEVICE_MODEL = get_product_props ("model" )
2121
2222DEVICE_ARCH = ["ro.bionic.arch" ]
23+ DEVICE_CPU_ABILIST = get_partition_props ("ro.{}product.cpu.abilist" , add_empty = True )
2324DEVICE_CPU_VARIANT = ["ro.bionic.cpu_variant" ]
2425DEVICE_SECOND_ARCH = ["ro.bionic.2nd_arch" ]
2526DEVICE_SECOND_CPU_VARIANT = ["ro.bionic.2nd_cpu_variant" ]
@@ -57,14 +58,16 @@ def __new__(cls, *args, **kwargs):
5758 def __init__ (self ,
5859 arch : str ,
5960 arch_variant : str ,
60- cpu_abi : str ,
61- cpu_abi2 : str = "" ,
62- kernel_name : str = "Image" ):
61+ bitness : int ,
62+ cpu_abilist : List [ str ] ,
63+ ):
6364 self .arch = arch
6465 self .arch_variant = arch_variant
65- self .cpu_abi = cpu_abi
66- self .cpu_abi2 = cpu_abi2
67- self .kernel_name = kernel_name
66+ self .bitness = bitness
67+ self .cpu_abilist = cpu_abilist
68+
69+ self .cpu_abi = self .cpu_abilist [0 ]
70+ self .cpu_abi2 = self .cpu_abilist [1 ] if len (self .cpu_abilist ) > 1 else ""
6871
6972 def __bool__ (self ):
7073 return self .arch != "unknown"
@@ -73,20 +76,29 @@ def __str__(self):
7376 return self .arch
7477
7578 @classmethod
76- def from_arch_string (cls , arch : str ):
79+ def from_arch (cls , arch : str ):
7780 for arch_enum in cls :
7881 if arch_enum .arch != arch :
7982 continue
8083
8184 return arch_enum
8285
83- return cls .UNKNOWN
86+ raise ValueError (f"Unknown arch: { arch } " )
87+
88+ @classmethod
89+ def from_abi (cls , abi : str ):
90+ for arch_enum in cls :
91+ if abi not in arch_enum .cpu_abilist :
92+ continue
8493
85- ARM = ("arm" , "armv7-a-neon" , "armeabi-v7a" , "armeabi" , "zImage" )
86- ARM64 = ("arm64" , "armv8-a" , "arm64-v8a" , "" , "Image.gz" )
87- X86 = ("x86" , "generic" , "x86" , "" , "bzImage" )
88- X86_64 = ("x86_64" , "generic" , "x86_64" , "" , "bzImage" )
89- UNKNOWN = ("unknown" , "generic" , "unknown" )
94+ return arch_enum
95+
96+ raise ValueError (f"Unknown ABI: { abi } " )
97+
98+ ARM = ("arm" , "armv7-a-neon" , 32 , ["armeabi-v7a" , "armeabi" ])
99+ ARM64 = ("arm64" , "armv8-a" , 64 , ["arm64-v8a" ])
100+ X86 = ("x86" , "generic" , 32 , ["x86" ])
101+ X86_64 = ("x86_64" , "generic" , 64 , ["x86_64" ])
90102
91103bool_cast = lambda x : bool (strtobool (x ))
92104
@@ -109,13 +121,30 @@ def __init__(self, build_prop: BuildProp):
109121 self .build_fingerprint = self .get_first_prop (BUILD_FINGERPRINT )
110122 self .build_description = self .get_first_prop (BUILD_DESCRIPTION , default = fingerprint_to_description (self .build_fingerprint ))
111123
112- self .arch = DeviceArch .from_arch_string (self .get_first_prop (DEVICE_ARCH ))
113- self .second_arch = DeviceArch .from_arch_string (self .get_first_prop (DEVICE_SECOND_ARCH ))
124+ # Parse arch
125+ self .arch = None
126+ self .second_arch = None
127+
128+ arch_prop = self .get_first_prop (DEVICE_ARCH , raise_exception = False )
129+ second_arch_prop = self .get_first_prop (DEVICE_SECOND_ARCH , raise_exception = False )
130+ if arch_prop :
131+ self .arch = DeviceArch .from_arch (arch_prop )
132+ if second_arch_prop :
133+ self .second_arch = DeviceArch .from_arch (second_arch_prop )
134+ else :
135+ # Fallback to ABI list
136+ abi_list = self .get_first_prop (DEVICE_CPU_ABILIST ).split ("," )
137+ assert abi_list , "No ABI list prop found"
138+ archs = list (set ([DeviceArch .from_abi (abi ) for abi in abi_list ]))
139+ assert 0 < len (archs ) <= 2 , "Invalid ABI list"
140+ # Higher bitness architectures has priority
141+ archs .sort (key = lambda x : x .bitness , reverse = True )
142+ self .arch = archs [0 ]
143+ if len (archs ) > 1 :
144+ self .second_arch = archs [1 ]
145+
114146 self .cpu_variant = self .get_first_prop (DEVICE_CPU_VARIANT , default = "generic" )
115147 self .second_cpu_variant = self .get_first_prop (DEVICE_SECOND_CPU_VARIANT , default = "generic" )
116- self .device_has_64bit_arch = self .arch in (DeviceArch .ARM64 , DeviceArch .X86_64 )
117- # TODO: Add 32binder64 detection (it only involves 8.0/8.1 devices so :shrug:)
118- self .device_has_64bit_binder = True
119148
120149 self .bootloader_board_name = self .get_first_prop (BOOTLOADER_BOARD_NAME )
121150 self .platform = self .get_first_prop (DEVICE_PLATFORM , default = "default" )
0 commit comments