re.compile(".*(name='(?P<name>.*?)')(.*maxSdkVersion='(?P<maxSdkVersion>.*?)')?.*")
APK_FEATURE_PAT = re.compile(".*name='([^']*)'.*")
-screen_densities = ['640', '480', '320', '240', '160', '120']
+screen_densities = ['65534', '640', '480', '320', '240', '160', '120']
screen_resolutions = {
"xxxhdpi": '640',
"xxhdpi": '480',
def get_icon_dir(repodir, density):
- if density == '0':
+ if density == '0' or density == '65534':
return os.path.join(repodir, "icons")
- return os.path.join(repodir, "icons-%s" % density)
+ else:
+ return os.path.join(repodir, "icons-%s" % density)
def get_icon_dirs(repodir):
logging.error("...FAILED to create page '{0}': {1}".format(pagename, e))
# Purge server cache to ensure counts are up to date
- site.pages['Repository Maintenance'].purge()
+ site.Pages['Repository Maintenance'].purge()
+
+ # Write a page with the last build log for this version code
+ wiki_page_path = 'update_' + time.strftime('%s', start_timestamp)
+ newpage = site.Pages[wiki_page_path]
+ txt = ''
+ txt += "* command line: <code>" + ' '.join(sys.argv) + "</code>\n"
+ txt += "* started at " + common.get_wiki_timestamp(start_timestamp) + '\n'
+ txt += "* completed at " + common.get_wiki_timestamp() + '\n'
+ txt += "\n\n"
+ txt += common.get_android_tools_version_log()
+ newpage.save(txt, summary='Run log')
+ newpage = site.Pages['update']
+ newpage.save('#REDIRECT [[' + wiki_page_path + ']]', summary='Update redirect')
def delete_disabled_builds(apps, apkcache, repodirs):
if 'minSdkVersion' not in apk:
logging.warning("No SDK version information found in {0}".format(apk_file))
- apk['minSdkVersion'] = 1
+ apk['minSdkVersion'] = 3 # aapt defaults to 3 as the min
+ if 'targetSdkVersion' not in apk:
+ apk['targetSdkVersion'] = apk['minSdkVersion']
# Check for known vulnerabilities
if has_known_vulnerability(apk_file):
+ ' 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(APK_SDK_VERSION_PAT, line)
if m is None:
if apkobject.get_max_sdk_version() is not None:
apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
- apk['minSdkVersion'] = apkobject.get_min_sdk_version()
- apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
+ if apkobject.get_min_sdk_version() is not None:
+ apk['minSdkVersion'] = apkobject.get_min_sdk_version()
+ if apkobject.get_target_sdk_version() is not None:
+ apk['targetSdkVersion'] = apkobject.get_target_sdk_version()
icon_id = int(apkobject.get_element("application", "icon").replace("@", "0x"), 16)
icon_name = arsc.get_id(apk['packageName'], icon_id)[1]
.format(apkfilename=apkfile) + str(e))
# extract icons from APK zip file
- iconfilename = "%s.%s.png" % (apk['packageName'], apk['versionCode'])
+ iconfilename = "%s.%s" % (apk['packageName'], apk['versionCode'])
try:
empty_densities = extract_apk_icons(iconfilename, apk, apkzip, repodir)
finally:
def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
- """
- Extracts icons from the given APK zip in various densities,
- saves them into given repo directory
- and stores their names in the APK metadata dictionary.
+ """Extracts PNG icons from an APK with the supported pixel densities
+
+ Extracts icons from the given APK zip in various densities, saves
+ them into given repo directory and stores their names in the APK
+ metadata dictionary. If the icon is an XML icon, then this tries
+ to find PNG icon that can replace it.
:param icon_filename: A string representing the icon's file name
:param apk: A populated dictionary containing APK metadata.
:param apkzip: An opened zipfile.ZipFile of the APK file
:param repo_dir: The directory of the APK's repository
:return: A list of icon densities that are missing
+
"""
+ res_name_re = re.compile(r'res/(drawable|mipmap)-(x*[hlm]dpi|anydpi).*/(.*)_[0-9]+dp.(png|xml)')
+ pngs = dict()
+ for f in apkzip.namelist():
+ m = res_name_re.match(f)
+ if m and m.group(4) == 'png':
+ density = screen_resolutions[m.group(2)]
+ pngs[m.group(3) + '/' + density] = m.group(0)
+
+ icon_type = None
empty_densities = []
for density in screen_densities:
if density not in apk['icons_src']:
continue
icon_src = apk['icons_src'][density]
icon_dir = get_icon_dir(repo_dir, density)
- icon_dest = os.path.join(icon_dir, icon_filename)
+ icon_type = '.png'
# Extract the icon files per density
if icon_src.endswith('.xml'):
- png = os.path.basename(icon_src)[:-4] + '.png'
- for f in apkzip.namelist():
- if f.endswith(png):
- m = re.match(r'res/(drawable|mipmap)-(x*[hlm]dpi).*/', f)
- if m and screen_resolutions[m.group(2)] == density:
- icon_src = f
+ m = res_name_re.match(icon_src)
+ if m:
+ name = pngs.get(m.group(3) + '/' + str(density))
+ if name:
+ icon_src = name
if icon_src.endswith('.xml'):
empty_densities.append(density)
- continue
+ icon_type = '.xml'
+ icon_dest = os.path.join(icon_dir, icon_filename + icon_type)
+
try:
with open(icon_dest, 'wb') as f:
f.write(get_icon_bytes(apkzip, icon_src))
- apk['icons'][density] = icon_filename
+ apk['icons'][density] = icon_filename + icon_type
except (zipfile.BadZipFile, ValueError, KeyError) as e:
logging.warning("Error retrieving icon file: %s %s", icon_dest, e)
del apk['icons_src'][density]
empty_densities.append(density)
- if '-1' in apk['icons_src'] and not apk['icons_src']['-1'].endswith('.xml'):
+ # '-1' here is a remnant of the parsing of aapt output, meaning "no DPI specified"
+ if '-1' in apk['icons_src']:
icon_src = apk['icons_src']['-1']
- icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename)
+ icon_type = icon_src[-4:]
+ icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename + icon_type)
with open(icon_path, 'wb') as f:
f.write(get_icon_bytes(apkzip, icon_src))
- im = None
- try:
- im = Image.open(icon_path)
- dpi = px_to_dpi(im.size[0])
- for density in screen_densities:
- if density in apk['icons']:
- break
- if density == screen_densities[-1] or dpi >= int(density):
- apk['icons'][density] = icon_filename
- shutil.move(icon_path,
- os.path.join(get_icon_dir(repo_dir, density), icon_filename))
- empty_densities.remove(density)
- break
- except Exception as e:
- logging.warning(_("Failed reading {path}: {error}")
- .format(path=icon_path, error=e))
- finally:
- if im and hasattr(im, 'close'):
- im.close()
+ if icon_type == '.png':
+ im = None
+ try:
+ im = Image.open(icon_path)
+ dpi = px_to_dpi(im.size[0])
+ for density in screen_densities:
+ if density in apk['icons']:
+ break
+ if density == screen_densities[-1] or dpi >= int(density):
+ apk['icons'][density] = icon_filename
+ shutil.move(icon_path,
+ os.path.join(get_icon_dir(repo_dir, density), icon_filename))
+ empty_densities.remove(density)
+ break
+ except Exception as e:
+ logging.warning(_("Failed reading {path}: {error}")
+ .format(path=icon_path, error=e))
+ finally:
+ if im and hasattr(im, 'close'):
+ im.close()
if apk['icons']:
- apk['icon'] = icon_filename
+ apk['icon'] = icon_filename + icon_type
return empty_densities
def fill_missing_icon_densities(empty_densities, icon_filename, apk, repo_dir):
"""
- Resize existing icons for densities missing in the APK to ensure all densities are available
+ Resize existing PNG icons for densities missing in the APK to ensure all densities are available
:param empty_densities: A list of icon densities that are missing
:param icon_filename: A string representing the icon's file name
:param apk: A populated dictionary containing APK metadata. Needs to have 'icons' key
:param repo_dir: The directory of the APK's repository
+
"""
+ icon_filename += '.png'
# First try resizing down to not lose quality
last_density = None
for density in screen_densities:
+ if density == '65534': # not possible to generate 'anydpi' from other densities
+ continue
if density not in empty_densities:
last_density = density
continue
config = None
options = None
+start_timestamp = time.gmtime()
def main():