Also store icons of launchable system apps

This commit is contained in:
Torsten Grote 2024-05-22 16:44:14 -03:00
parent a0a3e871e0
commit 1ac613f588
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -42,12 +42,24 @@ internal class IconManager(
val packageManager = context.packageManager val packageManager = context.packageManager
ZipOutputStream(outputStream).use { zip -> ZipOutputStream(outputStream).use { zip ->
zip.setLevel(BEST_SPEED) zip.setLevel(BEST_SPEED)
val entries = mutableSetOf<String>()
packageService.allUserPackages.forEach { packageService.allUserPackages.forEach {
val drawable = packageManager.getApplicationIcon(it.applicationInfo) val drawable = packageManager.getApplicationIcon(it.applicationInfo)
if (packageManager.isDefaultApplicationIcon(drawable)) return@forEach if (packageManager.isDefaultApplicationIcon(drawable)) return@forEach
val entry = ZipEntry(it.packageName) val entry = ZipEntry(it.packageName)
zip.putNextEntry(entry) zip.putNextEntry(entry)
drawable.toBitmap(ICON_SIZE, ICON_SIZE).compress(WEBP_LOSSY, ICON_QUALITY, zip) drawable.toBitmap(ICON_SIZE, ICON_SIZE).compress(WEBP_LOSSY, ICON_QUALITY, zip)
entries.add(it.packageName)
zip.closeEntry()
}
packageService.launchableSystemApps.forEach {
val drawable = it.loadIcon(packageManager)
if (packageManager.isDefaultApplicationIcon(drawable)) return@forEach
// check for duplicates (e.g. updated launchable system app)
if (it.activityInfo.packageName in entries) return@forEach
val entry = ZipEntry(it.activityInfo.packageName)
zip.putNextEntry(entry)
drawable.toBitmap(ICON_SIZE, ICON_SIZE).compress(WEBP_LOSSY, ICON_QUALITY, zip)
zip.closeEntry() zip.closeEntry()
} }
} }