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

Commit 86a1b1ab authored by Rohit Goyal's avatar Rohit Goyal
Browse files

Bugfixes: Handle session failure unarchival cases so that icon and title are accurate.

* Remove old package icon entry from IconCache in case of a session failure.
* Allow package entry to fallback to fallback state where missing icon & titles are filled using PackageManager.
* Re-bind archived application in all apps if an unarchival fails.

Test: verified bugfixes locally.
Bug: 326494527
Bug: 328314141
Flag: ACONFIG com.android.launcher3.enable_support_for_archiving DEVELOPMENT
Merged-In: Ib132bece397001e9a14933c2f6d733a04a089ef9
Change-Id: Ib132bece397001e9a14933c2f6d733a04a089ef9
parent f774a101
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_RESOURC

import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
import static com.android.launcher3.config.FeatureFlags.IS_STUDIO_BUILD;
import static com.android.launcher3.icons.cache.BaseIconCache.EMPTY_CLASS_NAME;
import static com.android.launcher3.model.PackageUpdatedTask.OP_UPDATE;
import static com.android.launcher3.pm.UserCache.ACTION_PROFILE_AVAILABLE;
import static com.android.launcher3.pm.UserCache.ACTION_PROFILE_UNAVAILABLE;
@@ -27,6 +28,7 @@ import static com.android.launcher3.testing.shared.TestProtocol.sDebugTracing;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInstaller;
@@ -70,6 +72,7 @@ import com.android.launcher3.pm.UserCache;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Preconditions;

@@ -443,9 +446,18 @@ public class LauncherModel implements InstallSessionTracker.Callback {
                    @NonNull final BgDataModel dataModel, @NonNull final AllAppsList apps) {
                IconCache iconCache = app.getIconCache();
                final IntSet removedIds = new IntSet();
                HashSet<WorkspaceItemInfo> archivedItemsToCacheRefresh = new HashSet<>();
                HashSet<String> archivedPackagesToCacheRefresh = new HashSet<>();
                HashSet<WorkspaceItemInfo> archivedWorkspaceItemsToCacheRefresh = new HashSet<>();
                boolean isAppArchived = new PackageManagerHelper(
                        mApp.getContext()).isAppArchivedForUser(packageName, user);
                synchronized (dataModel) {
                    if (isAppArchived) {
                        // Remove package icon cache entry for archived app in case of a session
                        // failure.
                        mApp.getIconCache().remove(
                                new ComponentName(packageName, packageName + EMPTY_CLASS_NAME),
                                user);
                    }

                    for (ItemInfo info : dataModel.itemsIdMap) {
                        if (info instanceof WorkspaceItemInfo
                                && ((WorkspaceItemInfo) info).hasPromiseIconUi()
@@ -456,19 +468,16 @@ public class LauncherModel implements InstallSessionTracker.Callback {
                            }
                            if (((WorkspaceItemInfo) info).isArchived()) {
                                WorkspaceItemInfo workspaceItem = (WorkspaceItemInfo) info;
                                // Remove package cache icon for archived app in case of a session
                                // failure.
                                mApp.getIconCache().removeIconsForPkg(packageName, user);
                                // Refresh icons on the workspace for archived apps.
                                iconCache.getTitleAndIcon(workspaceItem,
                                        workspaceItem.usingLowResIcon());
                                archivedPackagesToCacheRefresh.add(packageName);
                                archivedItemsToCacheRefresh.add(workspaceItem);
                                archivedWorkspaceItemsToCacheRefresh.add(workspaceItem);
                            }
                        }
                    }
                    if (!archivedPackagesToCacheRefresh.isEmpty()) {
                        apps.updateIconsAndLabels(archivedPackagesToCacheRefresh, user);

                    if (isAppArchived) {
                        apps.updateIconsAndLabels(new HashSet<>(List.of(packageName)), user);
                    }
                }

@@ -477,8 +486,11 @@ public class LauncherModel implements InstallSessionTracker.Callback {
                            ItemInfoMatcher.ofItemIds(removedIds),
                            "removed because install session failed");
                }
                if (!archivedItemsToCacheRefresh.isEmpty()) {
                    bindUpdatedWorkspaceItems(archivedItemsToCacheRefresh.stream().toList());
                if (!archivedWorkspaceItemsToCacheRefresh.isEmpty()) {
                    bindUpdatedWorkspaceItems(
                            archivedWorkspaceItemsToCacheRefresh.stream().toList());
                }
                if (isAppArchived) {
                    bindApplicationsIfNeeded();
                }
            }
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.allapps;
import android.content.Context;
import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;

import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.pm.UserCache;
@@ -64,7 +65,7 @@ public class AppInfoComparator implements Comparator<AppInfo> {
    }

    private String getSortingTitle(AppInfo info) {
        if (info.appTitle != null) {
        if (!TextUtils.isEmpty(info.appTitle)) {
            return info.appTitle.toString();
        }
        if (info.title != null) {
+2 −2
Original line number Diff line number Diff line
@@ -222,6 +222,7 @@ public class IconCache extends BaseIconCache {
     * Updates {@param application} only if a valid entry is found.
     */
    public synchronized void updateTitleAndIcon(AppInfo application) {
        boolean preferPackageIcon = application.isArchived();
        CacheEntry entry = cacheLocked(application.componentName,
                application.user, () -> null, mLauncherActivityInfoCachingLogic,
                false, application.usingLowResIcon());
@@ -229,13 +230,12 @@ public class IconCache extends BaseIconCache {
            return;
        }

        boolean preferPackageIcon = application.isArchived();
        if (preferPackageIcon) {
            String packageName = application.getTargetPackage();
            CacheEntry packageEntry =
                    cacheLocked(new ComponentName(packageName, packageName + EMPTY_CLASS_NAME),
                            application.user, () -> null, mLauncherActivityInfoCachingLogic,
                            false, application.usingLowResIcon());
                            true, application.usingLowResIcon());
            applyPackageEntry(packageEntry, application, entry);
        } else {
            applyCacheEntry(entry, application);