From 699b3e4c698c370bb69de8308de5299705a813a2 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 14 Feb 2018 22:00:42 +0100 Subject: [PATCH] update: fix min/target/max edge case parsing with androguard In order to test that aapt defaults minSdkVersion to 3, I ran this script then compared the output with meld: cd $ANDROID_HOME/build-tools for d in *.*; do echo $d; $ANDROID_HOME/build-tools/$d/aapt dump badging /home/hans/code/fdroid/server/tests/repo/com.politedroid_3.apk > /tmp/${d}.txt; done meld /tmp/17.0.0.txt /tmp/26.0.2.txt /tmp/27.0.3.txt --- fdroidserver/update.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 10705a8f..a2f1a04c 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1069,7 +1069,9 @@ def scan_apk(apk_file): if 'minSdkVersion' not in apk: logging.warning("No SDK version information found in {0}".format(apk_file)) - apk['minSdkVersion'] = 1 + apk['minSdkVersion'] = 3 # aapt defaults to 3 as the min + if 'targetSdkVersion' not in apk: + apk['targetSdkVersion'] = apk['minSdkVersion'] # Check for known vulnerabilities if has_known_vulnerability(apk_file): @@ -1125,9 +1127,6 @@ def scan_apk_aapt(apk, apkfile): + ' is not a valid minSdkVersion!') else: apk['minSdkVersion'] = m.group(1) - # if target not set, default to min - if 'targetSdkVersion' not in apk: - apk['targetSdkVersion'] = m.group(1) elif line.startswith("targetSdkVersion:"): m = re.match(APK_SDK_VERSION_PAT, line) if m is None: @@ -1209,8 +1208,10 @@ def scan_apk_androguard(apk, apkfile): if apkobject.get_max_sdk_version() is not None: apk['maxSdkVersion'] = apkobject.get_max_sdk_version() - apk['minSdkVersion'] = apkobject.get_min_sdk_version() - apk['targetSdkVersion'] = apkobject.get_target_sdk_version() + if apkobject.get_min_sdk_version() is not None: + apk['minSdkVersion'] = apkobject.get_min_sdk_version() + if apkobject.get_target_sdk_version() is not None: + apk['targetSdkVersion'] = apkobject.get_target_sdk_version() icon_id = int(apkobject.get_element("application", "icon").replace("@", "0x"), 16) icon_name = arsc.get_id(apk['packageName'], icon_id)[1] -- 2.30.2