chiark / gitweb /
Merge branch 'targetSdkVersion' into 'master'
authorHans-Christoph Steiner <hans@guardianproject.info>
Tue, 14 Jun 2016 10:39:50 +0000 (10:39 +0000)
committerHans-Christoph Steiner <hans@guardianproject.info>
Tue, 14 Jun 2016 10:39:50 +0000 (10:39 +0000)
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

.gitignore
fdroidserver/update.py
tests/import.TestCase
tests/metadata.TestCase
tests/repo/urzip.apk [new file with mode: 0644]
tests/update.TestCase

index 9a46bd2de5e1c2c8351507a4f79d9f29a016fa22..1c57aac4c89329ef613eeda72604d7e0f2b04b50 100644 (file)
@@ -16,3 +16,4 @@ docs/html/
 
 # files generated by tests
 tmp/
+tests/repo/icons*
index ba7a3998c2fb763143970d0a3477b9ae9f8c0c93..cd75449d34f5aab06f619dab1645543bde8476d0 100644 (file)
@@ -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)
index c53b53d46446739e7376629e1059bb39f1d7d317..4d5acc56520a8a95f7010d61571cec574f64c67d 100755 (executable)
@@ -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__":
index c287a212723db8723326ceb51490f0072d64d844..0cdf3164861576067019e8815b7662a8ecd1190a 100755 (executable)
@@ -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)
diff --git a/tests/repo/urzip.apk b/tests/repo/urzip.apk
new file mode 100644 (file)
index 0000000..ee5e5cb
Binary files /dev/null and b/tests/repo/urzip.apk differ
index 0cc93e5c8b8880dd0c2200587b98b3310944f488..1005a1582608c138dd76078350890bc152a784bd 100755 (executable)
@@ -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()