Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4ed3ab8 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias
Browse files

Fix blank workspce icons on Launcher data refresh.

Clearing the launcher data with bulk workspace icon loading caused blank app icons to appear. Added fallback title and icon loading flows to the bulk icon loading flow.

Test: manually cleared launcher data
Fixes: 216590478
Bug: 195674813
Change-Id: I8e24a166be9f591155d538dfec865d047131b756
parent 470f4591
Loading
Loading
Loading
Loading
+90 −30
Original line number Diff line number Diff line
@@ -350,10 +350,22 @@ public class IconCache extends BaseIconCache {
                                    iconRequest.itemInfo.getTargetComponent()));

            Trace.beginSection("loadIconSubsectionInBulk");
            loadIconSubsection(sectionKey, filteredList, duplicateIconRequestsMap);
            Trace.endSection();
        });
        Trace.endSection();
    }

    private <T extends ItemInfoWithIcon> void loadIconSubsection(
            Pair<UserHandle, Boolean> sectionKey,
            List<IconRequestInfo<T>> filteredList,
            Map<ComponentName, List<IconRequestInfo<T>>> duplicateIconRequestsMap) {
        Trace.beginSection("loadIconSubsectionWithDatabase");
        try (Cursor c = createBulkQueryCursor(
                filteredList,
                /* user = */ sectionKey.first,
                /* useLowResIcons = */ sectionKey.second)) {
            // Database title and icon loading
            int componentNameColumnIndex = c.getColumnIndexOrThrow(IconDB.COLUMN_COMPONENT);
            while (c.moveToNext()) {
                ComponentName cn = ComponentName.unflattenFromString(
@@ -381,10 +393,58 @@ public class IconCache extends BaseIconCache {
        } finally {
            Trace.endSection();
        }
        });
        Trace.endSection();

        Trace.beginSection("loadIconSubsectionWithFallback");
        // Fallback title and icon loading
        for (ComponentName cn : duplicateIconRequestsMap.keySet()) {
            IconRequestInfo<T> iconRequestInfo = duplicateIconRequestsMap.get(cn).get(0);
            ItemInfoWithIcon itemInfo = iconRequestInfo.itemInfo;
            BitmapInfo icon = itemInfo.bitmap;
            boolean loadFallbackTitle = TextUtils.isEmpty(itemInfo.title);
            boolean loadFallbackIcon = icon == null
                    || isDefaultIcon(icon, itemInfo.user)
                    || icon == BitmapInfo.LOW_RES_INFO;

            if (loadFallbackTitle || loadFallbackIcon) {
                Log.i(TAG,
                        "Database bulk icon loading failed, using fallback bulk icon loading "
                                + "for: " + cn);
                CacheEntry entry = new CacheEntry();
                LauncherActivityInfo lai = iconRequestInfo.launcherActivityInfo;

                // Fill fields that are not updated below so they are not subsequently
                // deleted.
                entry.title = itemInfo.title;
                if (icon != null) {
                    entry.bitmap = icon;
                }
                entry.contentDescription = itemInfo.contentDescription;

                if (loadFallbackIcon) {
                    loadFallbackIcon(
                            lai,
                            entry,
                            mLauncherActivityInfoCachingLogic,
                            /* usePackageIcon= */ false,
                            /* usePackageTitle= */ loadFallbackTitle,
                            cn,
                            sectionKey.first);
                }
                if (loadFallbackTitle && TextUtils.isEmpty(entry.title)) {
                    loadFallbackTitle(
                            lai,
                            entry,
                            mLauncherActivityInfoCachingLogic,
                            sectionKey.first);
                }

                for (IconRequestInfo<T> iconRequest : duplicateIconRequestsMap.get(cn)) {
                    applyCacheEntry(entry, iconRequest.itemInfo);
                }
            }
        }
        Trace.endSection();
    }

    /**
     * Fill in {@param infoInOut} with the corresponding icon and label.