summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-05-20 21:57:06 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-05-21 09:18:27 -0700
commit75b0f552ae653a4afc64c5fb6782a481fdb89b4d (patch)
treec662b33a1f3c9825bc8f209dc257db9d1222bc6d /src/com/android/launcher3/LauncherModel.java
parentc393b0765df8d2d34b3b996b71700a705b7d0106 (diff)
downloadandroid_packages_apps_Trebuchet-75b0f552ae653a4afc64c5fb6782a481fdb89b4d.tar.gz
android_packages_apps_Trebuchet-75b0f552ae653a4afc64c5fb6782a481fdb89b4d.tar.bz2
android_packages_apps_Trebuchet-75b0f552ae653a4afc64c5fb6782a481fdb89b4d.zip
Breaking icon update task so that it doesn't block worker thread
Bug: 20945600 Change-Id: Iaf516577898b51ad6e8a813d7f018ecad969c100
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java112
1 files changed, 51 insertions, 61 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 3e05f57b9..9deee43d4 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -2754,7 +2754,7 @@ public class LauncherModel extends BroadcastReceiver
return;
}
}
- updateAllAppsIconsCache();
+ mIconCache.updateDbIcons();
synchronized (LoaderTask.this) {
if (mStopped) {
return;
@@ -2880,75 +2880,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);
+ }
+ }
+ });
}
}