diff --git a/fdroidserver/update.py b/fdroidserver/update.py index b108f38a..ebd29a2c 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1181,6 +1181,27 @@ def scan_apk_aapt(apk, apkfile): apk['icons_src'] = _get_apk_icons_src(apkfile, icon_name) +def _ensure_final_value(packageName, arsc, value): + """Ensure incoming value is always the value, not the resid + + androguard will sometimes return the Android "resId" aka + Resource ID instead of the actual value. This checks whether + the value is actually a resId, then performs the Android + Resource lookup as needed. + + """ + if value: + returnValue = value + if value[0] == '@': + try: # can be a literal value or a resId + res_id = int(value.replace("@", "0x"), 16) + res_id = arsc.get_id(packageName, res_id)[1] + returnValue = arsc.get_string(packageName, res_id)[1] + except ValueError: + pass + return returnValue + + def _sanitize_sdk_version(value): """Sanitize the raw values from androguard to handle bad values @@ -1229,16 +1250,8 @@ def scan_apk_androguard(apk, apkfile): apk['versionCode'] = int(apkobject.get_androidversion_code()) apk['name'] = apkobject.get_app_name() - versionName = apkobject.get_androidversion_name() - if versionName: - apk['versionName'] = versionName - if versionName[0] == '@': - try: # can be a literal value or a resId - res_id = int(versionName.replace("@", "0x"), 16) - res_id = arsc.get_id(apk['packageName'], res_id)[1] - apk['versionName'] = arsc.get_string(apk['packageName'], res_id)[1] - except ValueError: - pass + apk['versionName'] = _ensure_final_value(apk['packageName'], arsc, + apkobject.get_androidversion_name()) minSdkVersion = _sanitize_sdk_version(apkobject.get_min_sdk_version()) if minSdkVersion is not None: diff --git a/tests/update.TestCase b/tests/update.TestCase index 6616669f..f4e02e47 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -303,6 +303,7 @@ class UpdateTest(unittest.TestCase): self.assertEqual(apk_info.get('versionName'), '0.9') apk_info = fdroidserver.update.scan_apk('repo/duplicate.permisssions_9999999.apk') + self.assertIsNone(apk_info.get('versionName')) self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_launcher.png', '-1': 'res/drawable/ic_launcher.png'}) @@ -328,14 +329,17 @@ class UpdateTest(unittest.TestCase): self.assertEqual(apk_info['targetSdkVersion'], '8') apk_info = fdroidserver.update.scan_apk('org.bitbucket.tickytacky.mirrormirror_4.apk') + self.assertEqual(apk_info.get('versionName'), '1.0.3') self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable-mdpi/mirror.png', '-1': 'res/drawable-mdpi/mirror.png'}) apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk') + self.assertEqual(apk_info.get('versionName'), '1.3') self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_coffee_on.xml', '-1': 'res/drawable/ic_coffee_on.xml'}) apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk') + self.assertEqual(apk_info.get('versionName'), '1.5') self.assertEqual(apk_info['icons_src'], {'120': 'res/drawable-ldpi-v4/icon.png', '160': 'res/drawable-mdpi-v4/icon.png', '240': 'res/drawable-hdpi-v4/icon.png', @@ -343,6 +347,7 @@ class UpdateTest(unittest.TestCase): '-1': 'res/drawable-mdpi-v4/icon.png'}) apk_info = fdroidserver.update.scan_apk('SpeedoMeterApp.main_1.apk') + self.assertEqual(apk_info.get('versionName'), '1.0') self.assertEqual(apk_info['icons_src'], {}) def test_scan_apk_no_sig(self):