diff options
-rw-r--r-- | src/com/android/launcher3/AllAppsList.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher3/IconCache.java | 16 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 102 |
3 files changed, 89 insertions, 40 deletions
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java index dd646bb22..3b25dca34 100644 --- a/src/com/android/launcher3/AllAppsList.java +++ b/src/com/android/launcher3/AllAppsList.java @@ -24,6 +24,7 @@ import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.UserHandleCompat; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; @@ -117,6 +118,16 @@ class AllAppsList { } } + public void updateIconsAndLabels(HashSet<String> packages, UserHandleCompat user, + ArrayList<AppInfo> outUpdates) { + for (AppInfo info : data) { + if (info.user.equals(user) && packages.contains(info.componentName.getPackageName())) { + mIconCache.updateTitleAndIcon(info); + outUpdates.add(info); + } + } + } + /** * Add and remove icons for this package which has been updated. */ diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index fd4571482..6c2aa397d 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -407,6 +407,20 @@ public class IconCache { } /** + * Updates {@param application} only if a valid entry is found. + */ + public synchronized void updateTitleAndIcon(AppInfo application) { + CacheEntry entry = cacheLocked(application.componentName, null, application.user, + false, application.usingLowResIcon); + if (entry.icon != null && !isDefaultIcon(entry.icon, application.user)) { + application.title = entry.title; + application.iconBitmap = entry.icon; + application.contentDescription = entry.contentDescription; + application.usingLowResIcon = entry.isLowResIcon; + } + } + + /** * Returns a high res icon for the given intent and user */ public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) { @@ -655,7 +669,7 @@ public class IconCache { } private static final class IconDB extends SQLiteOpenHelper { - private final static int DB_VERSION = 3; + private final static int DB_VERSION = 4; private final static String TABLE_NAME = "icons"; private final static String COLUMN_ROWID = "rowid"; diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 0138a913a..ddbae3a18 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2767,6 +2767,7 @@ public class LauncherModel extends BroadcastReceiver } if (!mAllAppsLoaded) { loadAllApps(); + updateAllAppsIconsCache(); synchronized (LoaderTask.this) { if (mStopped) { return; @@ -2821,9 +2822,6 @@ public class LauncherModel extends BroadcastReceiver return; } - final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); - mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); - final List<UserHandleCompat> profiles = mUserManager.getUserProfiles(); // Clear the list of apps @@ -2843,42 +2841,6 @@ public class LauncherModel extends BroadcastReceiver return; } - // Update icon cache - HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps); - - // If any package icon has changed (app was updated while launcher was dead), - // update the corresponding shortcuts. - if (!updatedPackages.isEmpty()) { - final ArrayList<ShortcutInfo> updates = new ArrayList<ShortcutInfo>(); - synchronized (sBgLock) { - for (ItemInfo info : sBgItemsIdMap) { - if (info instanceof ShortcutInfo && user.equals(info.user) - && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { - ShortcutInfo si = (ShortcutInfo) info; - ComponentName cn = si.getTargetComponent(); - if (cn != null && updatedPackages.contains(cn.getPackageName())) { - si.updateIcon(mIconCache); - updates.add(si); - } - } - } - } - - if (!updates.isEmpty()) { - final UserHandleCompat userFinal = user; - mHandler.post(new Runnable() { - - public void run() { - Callbacks cb = getCallback(); - if (cb != null) { - cb.bindShortcutsChanged( - updates, new ArrayList<ShortcutInfo>(), userFinal); - } - } - }); - } - } - // Create the ApplicationInfos for (int i = 0; i < apps.size(); i++) { LauncherActivityInfoCompat app = apps.get(i); @@ -2929,6 +2891,68 @@ public class LauncherModel extends BroadcastReceiver } } + private void updateAllAppsIconsCache() { + final ArrayList<AppInfo> updatedApps = new ArrayList<>(); + + for (UserHandleCompat user : mUserManager.getUserProfiles()) { + // Query for the set of apps + final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); + // Fail if we don't have any apps + // TODO: Fix this. Only fail for the current user. + if (apps == null || apps.isEmpty()) { + return; + } + + // Update icon cache + HashSet<String> updatedPackages = mIconCache.updateDBIcons(user, apps); + + // If any package icon has changed (app was updated while launcher was dead), + // update the corresponding shortcuts. + if (!updatedPackages.isEmpty()) { + final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>(); + synchronized (sBgLock) { + for (ItemInfo info : sBgItemsIdMap) { + if (info instanceof ShortcutInfo && user.equals(info.user) + && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { + ShortcutInfo si = (ShortcutInfo) info; + ComponentName cn = si.getTargetComponent(); + if (cn != null && updatedPackages.contains(cn.getPackageName())) { + si.updateIcon(mIconCache); + updatedShortcuts.add(si); + } + } + } + mBgAllAppsList.updateIconsAndLabels(updatedPackages, user, updatedApps); + } + + if (!updatedShortcuts.isEmpty()) { + final UserHandleCompat userFinal = user; + mHandler.post(new Runnable() { + + public void run() { + Callbacks cb = getCallback(); + if (cb != null) { + cb.bindShortcutsChanged(updatedShortcuts, + new ArrayList<ShortcutInfo>(), userFinal); + } + } + }); + } + } + } + if (!updatedApps.isEmpty()) { + mHandler.post(new Runnable() { + + public void run() { + Callbacks cb = getCallback(); + if (cb != null) { + cb.bindAppsUpdated(updatedApps); + } + } + }); + } + } + public void dumpState() { synchronized (sBgLock) { Log.d(TAG, "mLoaderTask.mContext=" + mContext); |