mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 06:30:27 +03:00 
			
		
		
		
	parse targetSdkVersion from APKs
The default targetSdkVersion is minSdkVersion, according to the docs: https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#target https://gitlab.com/fdroid/fdroidclient/issues/682
This commit is contained in:
		
							parent
							
								
									032dbc3e8d
								
							
						
					
					
						commit
						1b7a8f85fc
					
				
					 4 changed files with 40 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -16,3 +16,4 @@ docs/html/
 | 
			
		|||
 | 
			
		||||
# files generated by tests
 | 
			
		||||
tmp/
 | 
			
		||||
tests/repo/icons*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -524,6 +524,16 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
 | 
			
		|||
                                      + ' 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(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)
 | 
			
		||||
                elif line.startswith("native-code:"):
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -937,6 +947,8 @@ def make_index(apps, sortedids, apks, repodir, archive, categories):
 | 
			
		|||
            addElement('sig', apk['sig'], doc, apkel)
 | 
			
		||||
            addElement('size', str(apk['size']), 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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										
											BIN
										
									
								
								tests/repo/urzip.apk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/repo/urzip.apk
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue