From: Hans-Christoph Steiner Date: Thu, 15 Mar 2018 14:56:30 +0000 (+0100) Subject: update: handle AndroidManifest XML namespace named other than 'android' X-Git-Tag: 1.0.3~4^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=54242dee32218955f69297b344d81d4d2042eaf8;p=fdroidserver.git update: handle AndroidManifest XML namespace named other than 'android' 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" --- diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 058cd5ea..9c6c21f3 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -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)