diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-05-21 20:31:36 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-21 20:31:37 +0000 |
commit | 324d78358c88d30eac587f4e1d679f9b5bf8d2f3 (patch) | |
tree | 1106f11c30905749e97cf28cae2fa0cb1748c12b /src/com/android/launcher3/LauncherModel.java | |
parent | edc9c0564454ed38dd3006c9ae4b82a449f447a4 (diff) | |
parent | 75b0f552ae653a4afc64c5fb6782a481fdb89b4d (diff) | |
download | packages_apps_Trebuchet-324d78358c88d30eac587f4e1d679f9b5bf8d2f3.tar.gz packages_apps_Trebuchet-324d78358c88d30eac587f4e1d679f9b5bf8d2f3.tar.bz2 packages_apps_Trebuchet-324d78358c88d30eac587f4e1d679f9b5bf8d2f3.zip |
Merge "Breaking icon update task so that it doesn't block worker thread" into ub-launcher3-burnaby
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 112 |
1 files changed, 51 insertions, 61 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index a04d92ecc..d994dc77c 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2757,7 +2757,7 @@ public class LauncherModel extends BroadcastReceiver return; } } - updateAllAppsIconsCache(); + mIconCache.updateDbIcons(); synchronized (LoaderTask.this) { if (mStopped) { return; @@ -2883,75 +2883,65 @@ 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); - } + public void dumpState() { + synchronized (sBgLock) { + Log.d(TAG, "mLoaderTask.mContext=" + mContext); + Log.d(TAG, "mLoaderTask.mStopped=" + mStopped); + Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished); + Log.d(TAG, "mItems size=" + sBgWorkspaceItems.size()); + } + } + } - if (!updatedShortcuts.isEmpty()) { - final UserHandleCompat userFinal = user; - mHandler.post(new Runnable() { + /** + * Called when the icons for packages have been updated in the icon cache. + */ + public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandleCompat user) { + final Callbacks callbacks = getCallback(); + final ArrayList<AppInfo> updatedApps = new ArrayList<>(); + final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>(); - public void run() { - Callbacks cb = getCallback(); - if (cb != null) { - cb.bindShortcutsChanged(updatedShortcuts, - new ArrayList<ShortcutInfo>(), userFinal); - } - } - }); + // If any package icon has changed (app was updated while launcher was dead), + // update the corresponding shortcuts. + 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); } } } - if (!updatedApps.isEmpty()) { - mHandler.post(new Runnable() { + mBgAllAppsList.updateIconsAndLabels(updatedPackages, user, updatedApps); + } - public void run() { - Callbacks cb = getCallback(); - if (cb != null) { - cb.bindAppsUpdated(updatedApps); - } + if (!updatedShortcuts.isEmpty()) { + final UserHandleCompat userFinal = user; + mHandler.post(new Runnable() { + + public void run() { + Callbacks cb = getCallback(); + if (cb != null && callbacks == cb) { + cb.bindShortcutsChanged(updatedShortcuts, + new ArrayList<ShortcutInfo>(), userFinal); } - }); - } + } + }); } - public void dumpState() { - synchronized (sBgLock) { - Log.d(TAG, "mLoaderTask.mContext=" + mContext); - Log.d(TAG, "mLoaderTask.mStopped=" + mStopped); - Log.d(TAG, "mLoaderTask.mLoadAndBindStepFinished=" + mLoadAndBindStepFinished); - Log.d(TAG, "mItems size=" + sBgWorkspaceItems.size()); - } + if (!updatedApps.isEmpty()) { + mHandler.post(new Runnable() { + + public void run() { + Callbacks cb = getCallback(); + if (cb != null && callbacks == cb) { + cb.bindAppsUpdated(updatedApps); + } + } + }); } } |