mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-19 21:30:10 +01:00
Merge branch 'androguard_minsdk' into 'master'
common: use androguard to figure out minSDK version Closes #816 See merge request fdroid/fdroidserver!785
This commit is contained in:
commit
29eea3f739
@ -2502,20 +2502,19 @@ def get_native_code(apkfile):
|
|||||||
return sorted(list(archset))
|
return sorted(list(archset))
|
||||||
|
|
||||||
|
|
||||||
def get_minSdkVersion_aapt(apkfile):
|
def get_minSdkVersion(apkfile):
|
||||||
"""Extract the minimum supported Android SDK from an APK using aapt
|
"""Extract the minimum supported Android SDK from an APK using androguard
|
||||||
|
|
||||||
:param apkfile: path to an APK file.
|
:param apkfile: path to an APK file.
|
||||||
:returns: the integer representing the SDK version
|
:returns: the integer representing the SDK version
|
||||||
"""
|
"""
|
||||||
r = re.compile(r"^sdkVersion:'([0-9]+)'")
|
|
||||||
p = SdkToolsPopen(['aapt', 'dump', 'badging', apkfile], output=False)
|
try:
|
||||||
for line in p.output.splitlines():
|
apk = _get_androguard_APK(apkfile)
|
||||||
m = r.match(line)
|
except FileNotFoundError:
|
||||||
if m:
|
|
||||||
return int(m.group(1))
|
|
||||||
raise FDroidException(_('Reading minSdkVersion failed: "{apkfilename}"')
|
raise FDroidException(_('Reading minSdkVersion failed: "{apkfilename}"')
|
||||||
.format(apkfilename=apkfile))
|
.format(apkfilename=apkfile))
|
||||||
|
return int(apk.get_min_sdk_version())
|
||||||
|
|
||||||
|
|
||||||
class PopenResult:
|
class PopenResult:
|
||||||
@ -3040,7 +3039,7 @@ def sign_apk(unsigned_path, signed_path, keyalias):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if get_minSdkVersion_aapt(unsigned_path) < 18:
|
if get_minSdkVersion(unsigned_path) < 18:
|
||||||
signature_algorithm = ['-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1']
|
signature_algorithm = ['-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1']
|
||||||
else:
|
else:
|
||||||
signature_algorithm = ['-sigalg', 'SHA256withRSA', '-digestalg', 'SHA-256']
|
signature_algorithm = ['-sigalg', 'SHA256withRSA', '-digestalg', 'SHA-256']
|
||||||
|
@ -674,7 +674,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
||||||
try:
|
try:
|
||||||
fdroidserver.common.find_sdk_tools_cmd('aapt')
|
fdroidserver.common.find_sdk_tools_cmd('aapt')
|
||||||
self.assertEqual(18, fdroidserver.common.get_minSdkVersion_aapt(signed))
|
self.assertEqual(18, fdroidserver.common.get_minSdkVersion(signed))
|
||||||
except fdroidserver.exception.FDroidException:
|
except fdroidserver.exception.FDroidException:
|
||||||
print('\n\nSKIPPING test_sign_apk min SDK check, aapt is not installed!\n')
|
print('\n\nSKIPPING test_sign_apk min SDK check, aapt is not installed!\n')
|
||||||
return
|
return
|
||||||
@ -775,63 +775,54 @@ class CommonTest(unittest.TestCase):
|
|||||||
nc = fdroidserver.common.get_native_code(apkfilename)
|
nc = fdroidserver.common.get_native_code(apkfilename)
|
||||||
self.assertEqual(native_code, nc)
|
self.assertEqual(native_code, nc)
|
||||||
|
|
||||||
def test_get_minSdkVersion_aapt(self):
|
def test_get_minSdkVersion_androguard(self):
|
||||||
config = dict()
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('bad-unicode-πÇÇ现代通用字-български-عربي1.apk')
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
|
||||||
fdroidserver.common.config = config
|
|
||||||
self._set_build_tools()
|
|
||||||
try: # get_minSdkVersion_aapt requires aapt
|
|
||||||
config['aapt'] = fdroidserver.common.find_sdk_tools_cmd('aapt')
|
|
||||||
except fdroidserver.exception.FDroidException:
|
|
||||||
print('\n\nSKIPPING test_sign_apk, aapt is not installed!\n')
|
|
||||||
return
|
|
||||||
|
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('bad-unicode-πÇÇ现代通用字-български-عربي1.apk')
|
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('org.bitbucket.tickytacky.mirrormirror_1.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('org.bitbucket.tickytacky.mirrormirror_1.apk')
|
||||||
self.assertEqual(14, minSdkVersion)
|
self.assertEqual(14, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('org.bitbucket.tickytacky.mirrormirror_2.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('org.bitbucket.tickytacky.mirrormirror_2.apk')
|
||||||
self.assertEqual(14, minSdkVersion)
|
self.assertEqual(14, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('org.bitbucket.tickytacky.mirrormirror_3.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('org.bitbucket.tickytacky.mirrormirror_3.apk')
|
||||||
self.assertEqual(14, minSdkVersion)
|
self.assertEqual(14, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('org.bitbucket.tickytacky.mirrormirror_4.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('org.bitbucket.tickytacky.mirrormirror_4.apk')
|
||||||
self.assertEqual(14, minSdkVersion)
|
self.assertEqual(14, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('org.dyndns.fules.ck_20.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('org.dyndns.fules.ck_20.apk')
|
||||||
self.assertEqual(7, minSdkVersion)
|
self.assertEqual(7, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('urzip.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('urzip.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('urzip-badcert.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('urzip-badcert.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('urzip-badsig.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('urzip-badsig.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('urzip-release.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('urzip-release.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('urzip-release-unsigned.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('urzip-release-unsigned.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/com.politedroid_3.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/com.politedroid_3.apk')
|
||||||
self.assertEqual(3, minSdkVersion)
|
self.assertEqual(3, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/com.politedroid_4.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/com.politedroid_4.apk')
|
||||||
self.assertEqual(3, minSdkVersion)
|
self.assertEqual(3, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/com.politedroid_5.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/com.politedroid_5.apk')
|
||||||
self.assertEqual(3, minSdkVersion)
|
self.assertEqual(3, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/com.politedroid_6.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/com.politedroid_6.apk')
|
||||||
self.assertEqual(14, minSdkVersion)
|
self.assertEqual(14, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.main.oldversion_1444412523.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.main.oldversion_1444412523.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.mainpatch.current_1619_another-release-key.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.mainpatch.current_1619_another-release-key.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.mainpatch.current_1619.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.mainpatch.current_1619.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.main.twoversions_1101613.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.main.twoversions_1101613.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.main.twoversions_1101615.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.main.twoversions_1101615.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/obb.main.twoversions_1101617.apk')
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/obb.main.twoversions_1101617.apk')
|
||||||
|
self.assertEqual(4, minSdkVersion)
|
||||||
|
minSdkVersion = fdroidserver.common.get_minSdkVersion('repo/urzip-; Рахма́, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢·.apk')
|
||||||
self.assertEqual(4, minSdkVersion)
|
self.assertEqual(4, minSdkVersion)
|
||||||
minSdkVersion = fdroidserver.common.get_minSdkVersion_aapt('repo/urzip-; Рахма́, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢·.apk')
|
|
||||||
|
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
fdroidserver.common.get_minSdkVersion_aapt('nope')
|
fdroidserver.common.get_minSdkVersion('nope')
|
||||||
|
|
||||||
def test_apk_release_name(self):
|
def test_apk_release_name(self):
|
||||||
appid, vercode, sigfp = fdroidserver.common.apk_parse_release_filename('com.serwylo.lexica_905.apk')
|
appid, vercode, sigfp = fdroidserver.common.apk_parse_release_filename('com.serwylo.lexica_905.apk')
|
||||||
|
Loading…
Reference in New Issue
Block a user