From 86a1b1abf5cb7f45be0dab9a8be386cbcf67c787 Mon Sep 17 00:00:00 2001 From: Rohit Goyal Date: Mon, 11 Mar 2024 12:27:19 +0000 Subject: [PATCH] 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 --- src/com/android/launcher3/LauncherModel.java | 34 +++++++++++++------ .../launcher3/allapps/AppInfoComparator.java | 3 +- .../android/launcher3/icons/IconCache.java | 4 +-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 99fca62ac1..be01d633bc 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -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 archivedItemsToCacheRefresh = new HashSet<>(); - HashSet archivedPackagesToCacheRefresh = new HashSet<>(); + HashSet 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(); } } diff --git a/src/com/android/launcher3/allapps/AppInfoComparator.java b/src/com/android/launcher3/allapps/AppInfoComparator.java index a0867dbaf1..bbf8e5a5fb 100644 --- a/src/com/android/launcher3/allapps/AppInfoComparator.java +++ b/src/com/android/launcher3/allapps/AppInfoComparator.java @@ -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 { } private String getSortingTitle(AppInfo info) { - if (info.appTitle != null) { + if (!TextUtils.isEmpty(info.appTitle)) { return info.appTitle.toString(); } if (info.title != null) { diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java index 41e3ef026b..1633eba5e1 100644 --- a/src/com/android/launcher3/icons/IconCache.java +++ b/src/com/android/launcher3/icons/IconCache.java @@ -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);