mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-14 02:50:12 +01:00
Merge branch 'targetSdkVersion' into 'master'
support targetSdkVersion In order to provide the proper Android-6 permissions experience, the client needs to know which `targetSdkVersion` any APK has before it downloads it. So this adds it to the metadata. https://gitlab.com/fdroid/fdroidclient/issues/682 See merge request !128
This commit is contained in:
commit
2fab013393
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@ docs/html/
|
||||
|
||||
# files generated by tests
|
||||
tmp/
|
||||
tests/repo/icons*
|
||||
|
@ -523,9 +523,19 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
|
||||
logging.error(line.replace('sdkVersion:', '')
|
||||
+ ' is not a valid minSdkVersion!')
|
||||
else:
|
||||
apk['sdkversion'] = m.group(1)
|
||||
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(sdkversion_pat, line)
|
||||
if m is None:
|
||||
logging.error(line.replace('targetSdkVersion:', '')
|
||||
+ ' is not a valid targetSdkVersion!')
|
||||
else:
|
||||
apk['targetSdkVersion'] = m.group(1)
|
||||
elif line.startswith("maxSdkVersion:"):
|
||||
apk['maxsdkversion'] = re.match(sdkversion_pat, line).group(1)
|
||||
apk['maxSdkVersion'] = re.match(sdkversion_pat, line).group(1)
|
||||
elif line.startswith("native-code:"):
|
||||
apk['nativecode'] = []
|
||||
for arch in line[13:].split(' '):
|
||||
@ -545,9 +555,9 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
|
||||
perm = perm[16:]
|
||||
apk['features'].add(perm)
|
||||
|
||||
if 'sdkversion' not in apk:
|
||||
if 'minSdkVersion' not in apk:
|
||||
logging.warn("No SDK version information found in {0}".format(apkfile))
|
||||
apk['sdkversion'] = 0
|
||||
apk['minSdkVersion'] = 1
|
||||
|
||||
# Check for debuggable apks...
|
||||
if common.isApkDebuggable(apkfile, config):
|
||||
@ -801,7 +811,7 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
||||
for mirror in config.get('mirrors', []):
|
||||
addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel)
|
||||
|
||||
repoel.setAttribute("version", "15")
|
||||
repoel.setAttribute("version", "16")
|
||||
repoel.setAttribute("timestamp", str(int(time.time())))
|
||||
|
||||
nosigningkey = False
|
||||
@ -936,9 +946,11 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
|
||||
apkel.appendChild(hashel)
|
||||
addElement('sig', apk['sig'], doc, apkel)
|
||||
addElement('size', str(apk['size']), doc, apkel)
|
||||
addElement('sdkver', str(apk['sdkversion']), doc, apkel)
|
||||
if 'maxsdkversion' in apk:
|
||||
addElement('maxsdkver', str(apk['maxsdkversion']), doc, apkel)
|
||||
addElement('sdkver', str(apk['minSdkVersion']), doc, apkel)
|
||||
if 'targetSdkVersion' in apk:
|
||||
addElement('targetSdkVersion', str(apk['targetSdkVersion']), doc, apkel)
|
||||
if 'maxSdkVersion' in apk:
|
||||
addElement('maxsdkver', str(apk['maxSdkVersion']), doc, apkel)
|
||||
if 'added' in apk:
|
||||
addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel)
|
||||
addElementNonEmpty('permissions', ','.join(apk['permissions']), doc, apkel)
|
||||
|
@ -33,9 +33,9 @@ class ImportTest(unittest.TestCase):
|
||||
app = fdroidserver.metadata.get_default_app_info()
|
||||
app.UpdateCheckMode = "Tags"
|
||||
root_dir, src_dir = import_proxy.get_metadata_from_url(app, url)
|
||||
self.assertEquals(app.RepoType, 'git')
|
||||
self.assertEquals(app.WebSite, 'https://gitlab.com/fdroid/fdroidclient')
|
||||
self.assertEquals(app.Repo, 'https://gitlab.com/fdroid/fdroidclient.git')
|
||||
self.assertEqual(app.RepoType, 'git')
|
||||
self.assertEqual(app.WebSite, 'https://gitlab.com/fdroid/fdroidclient')
|
||||
self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/fdroidclient.git')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -44,7 +44,7 @@ class MetadataTest(unittest.TestCase):
|
||||
self.assertTrue(appid in apps)
|
||||
with open(savepath, 'rb') as f:
|
||||
frompickle = pickle.load(f)
|
||||
self.assertEquals(frommeta, frompickle)
|
||||
self.assertEqual(frommeta, frompickle)
|
||||
# Uncomment to overwrite
|
||||
# with open(savepath, 'wb') as f:
|
||||
# pickle.dump(frommeta, f)
|
||||
|
BIN
tests/repo/urzip.apk
Normal file
BIN
tests/repo/urzip.apk
Normal file
Binary file not shown.
@ -55,13 +55,13 @@ class UpdateTest(unittest.TestCase):
|
||||
self.assertIsNotNone(sig, "sig is None")
|
||||
pysig = fdroidserver.update.getsig(apkfile)
|
||||
self.assertIsNotNone(pysig, "pysig is None")
|
||||
self.assertEquals(sig, fdroidserver.update.getsig(apkfile),
|
||||
"python sig not equal to java sig!")
|
||||
self.assertEquals(len(sig), len(pysig),
|
||||
"the length of the two sigs are different!")
|
||||
self.assertEqual(sig, fdroidserver.update.getsig(apkfile),
|
||||
"python sig not equal to java sig!")
|
||||
self.assertEqual(len(sig), len(pysig),
|
||||
"the length of the two sigs are different!")
|
||||
try:
|
||||
self.assertEquals(unhexlify(sig), unhexlify(pysig),
|
||||
"the length of the two sigs are different!")
|
||||
self.assertEqual(unhexlify(sig), unhexlify(pysig),
|
||||
"the length of the two sigs are different!")
|
||||
except TypeError as e:
|
||||
print(e)
|
||||
self.assertTrue(False, 'TypeError!')
|
||||
@ -83,6 +83,32 @@ class UpdateTest(unittest.TestCase):
|
||||
pysig = fdroidserver.update.getsig(apkfile)
|
||||
self.assertIsNone(pysig, "python sig should be None: " + str(sig))
|
||||
|
||||
def testScanApks(self):
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
if os.path.basename(os.getcwd()) != 'tests':
|
||||
raise Exception('This test must be run in the "tests/" subdir')
|
||||
|
||||
config = dict()
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
config['ndk_paths'] = dict()
|
||||
config['accepted_formats'] = ['json', 'txt', 'xml', 'yml']
|
||||
fdroidserver.common.config = config
|
||||
fdroidserver.update.config = config
|
||||
|
||||
fdroidserver.update.options = type('', (), {})()
|
||||
fdroidserver.update.options.clean = True
|
||||
|
||||
alltestapps = fdroidserver.metadata.read_metadata(xref=True)
|
||||
apps = dict()
|
||||
apps['info.guardianproject.urzip'] = alltestapps['info.guardianproject.urzip']
|
||||
knownapks = fdroidserver.common.KnownApks()
|
||||
apks, cachechanged = fdroidserver.update.scan_apks(apps, {}, 'repo', knownapks, False)
|
||||
self.assertEqual(len(apks), 1)
|
||||
apk = apks[0]
|
||||
self.assertEqual(apk['minSdkVersion'], '4')
|
||||
self.assertEqual(apk['targetSdkVersion'], '18')
|
||||
self.assertFalse('maxSdkVersion' in apk)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = optparse.OptionParser()
|
||||
|
Loading…
Reference in New Issue
Block a user