import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
// other locks, this one can generally be held long-term because we never expect any of these
// static data structures to be referenced outside of the worker thread except on the first
// load after configuration change.
- static final Object mBgLock = new Object();
+ static final Object sBgLock = new Object();
// sBgItemsIdMap maps *all* the ItemInfos (shortcuts, folders, and widgets) created by
// LauncherModel to their ids
// by making a copy of workspace items first.
final ArrayList<ItemInfo> tmpWorkspaceItems = new ArrayList<ItemInfo>();
final ArrayList<ItemInfo> tmpAppWidgets = new ArrayList<ItemInfo>();
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
tmpWorkspaceItems.addAll(sBgWorkspaceItems);
tmpAppWidgets.addAll(sBgAppWidgets);
}
final long itemId = item.id;
Runnable r = new Runnable() {
public void run() {
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
ItemInfo modelItem = sBgItemsIdMap.get(itemId);
if (modelItem != null && item != modelItem) {
// the modelItem needs to match up perfectly with item if our model is
cr.update(uri, values, null, null);
// Lock on mBgLock *after* the db operation
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
ItemInfo modelItem = sBgItemsIdMap.get(itemId);
if (item != modelItem) {
// the modelItem needs to match up perfectly with item if our model is to be
LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
// Lock on mBgLock *after* the db operation
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
if (sBgItemsIdMap.containsKey(item.id)) {
// we should not be adding new items in the db with the same id
throw new RuntimeException("Error: ItemInfo id (" + item.id + ") passed to " +
cr.delete(uriToDelete, null, null);
// Lock on mBgLock *after* the db operation
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
sBgFolders.remove(item.id);
public void run() {
cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
// Lock on mBgLock *after* the db operation
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
sBgItemsIdMap.remove(info.id);
sBgFolders.remove(info.id);
sBgDbIconCache.remove(info);
cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
// Lock on mBgLock *after* the db operation
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
for (ItemInfo childInfo : info.contents) {
sBgItemsIdMap.remove(childInfo.id);
sBgDbIconCache.remove(childInfo);
// Update the saved icons if necessary
if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons");
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
for (Object key : sBgDbIconCache.keySet()) {
updateSavedIcon(mContext, (ShortcutInfo) key, sBgDbIconCache.get(key));
}
// Make sure the default workspace is loaded, if needed
mApp.getLauncherProvider().loadDefaultFavoritesIfNecessary();
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
sBgWorkspaceItems.clear();
sBgAppWidgets.clear();
sBgFolders.clear();
ArrayList<ItemInfo> allWorkspaceItems,
ArrayList<ItemInfo> currentScreenItems,
ArrayList<ItemInfo> otherScreenItems) {
+ // Purge any null ItemInfos
+ Iterator<ItemInfo> iter = allWorkspaceItems.iterator();
+ while (iter.hasNext()) {
+ ItemInfo i = iter.next();
+ if (i == null) {
+ iter.remove();
+ }
+ }
+
// If we aren't filtering on a screen, then the set of items to load is the full set of
// items given.
if (currentScreen < 0) {
}
for (LauncherAppWidgetInfo widget : appWidgets) {
+ if (widget == null) continue;
if (widget.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
widget.screen == currentScreen) {
currentScreenWidgets.add(widget);
for (long id : folders.keySet()) {
ItemInfo info = itemsIdMap.get(id);
FolderInfo folder = folders.get(id);
+ if (info == null || folder == null) continue;
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
info.screen == currentScreen) {
currentScreenFolders.put(id, folder);
new ArrayList<LauncherAppWidgetInfo>();
HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>();
HashMap<Long, ItemInfo> itemsIdMap = new HashMap<Long, ItemInfo>();
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
workspaceItems.addAll(sBgWorkspaceItems);
appWidgets.addAll(sBgAppWidgets);
folders.putAll(sBgFolders);
}
public void dumpState() {
- synchronized (mBgLock) {
+ synchronized (sBgLock) {
Log.d(TAG, "mLoaderTask.mContext=" + mContext);
Log.d(TAG, "mLoaderTask.mIsLaunching=" + mIsLaunching);
Log.d(TAG, "mLoaderTask.mStopped=" + mStopped);