chiark / gitweb /
update: handle AndroidManifest XML namespace named other than 'android'
authorHans-Christoph Steiner <hans@eds.org>
Thu, 15 Mar 2018 14:56:30 +0000 (15:56 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Thu, 15 Mar 2018 14:56:30 +0000 (15:56 +0100)
https://stackoverflow.com/questions/5856719/why-do-we-specify-namespace-in-android-xml-file

https://f-droid.org/repo/org.moire.ultrasonic_60.apk has:
xmlns:a="http://schemas.android.com/apk/res/android"

fdroidserver/update.py

index 058cd5ea7bd11b7e567e0fb67389eab807898a7a..9c6c21f39f13d92528c23db57ea2271686f4be49 100644 (file)
@@ -1242,10 +1242,13 @@ def scan_apk_androguard(apk, apkfile):
         apk['nativecode'].extend(sorted(list(arch)))
 
     xml = apkobject.get_android_manifest_xml()
+    xmlns = xml.nsmap.get('android')
+    if not xmlns:
+        xmlns = 'http://schemas.android.com/apk/res/android'
 
     for item in xml.findall('uses-permission'):
-        name = str(item.attrib['{' + xml.nsmap['android'] + '}name'])
-        maxSdkVersion = item.attrib.get('{' + xml.nsmap['android'] + '}maxSdkVersion')
+        name = str(item.attrib['{' + xmlns + '}name'])
+        maxSdkVersion = item.attrib.get('{' + xmlns + '}maxSdkVersion')
         maxSdkVersion = int(maxSdkVersion) if maxSdkVersion else None
         permission = UsesPermission(
             name,
@@ -1260,8 +1263,8 @@ def scan_apk_androguard(apk, apkfile):
         apk['uses-permission'].append(permission)
 
     for item in xml.findall('uses-permission-sdk-23'):
-        name = str(item.attrib['{' + xml.nsmap['android'] + '}name'])
-        maxSdkVersion = item.attrib.get('{' + xml.nsmap['android'] + '}maxSdkVersion')
+        name = str(item.attrib['{' + xmlns + '}name'])
+        maxSdkVersion = item.attrib.get('{' + xmlns + '}maxSdkVersion')
         maxSdkVersion = int(maxSdkVersion) if maxSdkVersion else None
         permission_sdk_23 = UsesPermissionSdk23(
             name,
@@ -1270,7 +1273,7 @@ def scan_apk_androguard(apk, apkfile):
         apk['uses-permission-sdk-23'].append(permission_sdk_23)
 
     for item in xml.findall('uses-feature'):
-        key = '{' + xml.nsmap['android'] + '}name'
+        key = '{' + xmlns + '}name'
         if key not in item.attrib:
             continue
         feature = str(item.attrib[key])
@@ -1278,7 +1281,7 @@ def scan_apk_androguard(apk, apkfile):
                 and feature != "android.hardware.screen.landscape":
             if feature.startswith("android.feature."):
                 feature = feature[16:]
-        required = item.attrib.get('{' + xml.nsmap['android'] + '}required')
+        required = item.attrib.get('{' + xmlns + '}required')
         if required is None or required == 'true':
             apk['features'].append(feature)