Updating the icon cache after all apps has been bound.

> Updating the cache DB version to reset existing cache.

Bug: 20834835
Change-Id: I298ca9ddcc4dd270b25b767447ecde01ef41a916
This commit is contained in:
Sunny Goyal
2015-05-06 16:53:21 -07:00
parent 1d08f70441
commit 77919b93b9
3 changed files with 89 additions and 40 deletions
@@ -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.
*/
+15 -1
View File
@@ -406,6 +406,20 @@ public class IconCache {
application.usingLowResIcon = entry.isLowResIcon;
}
/**
* 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
*/
@@ -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";
+63 -39
View File
@@ -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);