summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-08-25 16:51:24 -0700
committerRomain Guy <romainguy@android.com>2009-08-25 16:51:24 -0700
commit4e8fc32dd59a45dda46c322904895336d0e79a3a (patch)
tree963e2fc1459eacea942f109b28c5870126b1bf7a
parentd1057c6cc26767030281f57a19c0433bc551d658 (diff)
downloadLauncher-4e8fc32dd59a45dda46c322904895336d0e79a3a.tar.gz
This change also adds new logs to help track down the issue if it happens again.
-rw-r--r--src/com/android/launcher/Launcher.java30
-rw-r--r--src/com/android/launcher/LauncherModel.java48
2 files changed, 63 insertions, 15 deletions
diff --git a/src/com/android/launcher/Launcher.java b/src/com/android/launcher/Launcher.java
index 3fd141d..710578f 100644
--- a/src/com/android/launcher/Launcher.java
+++ b/src/com/android/launcher/Launcher.java
@@ -1367,19 +1367,26 @@ public final class Launcher extends Activity implements View.OnClickListener, On
sModel.loadUserItems(false, this, false, false);
}
- void onDesktopItemsLoaded() {
- if (mDestroyed) return;
- bindDesktopItems();
+ void onDesktopItemsLoaded(ArrayList<ItemInfo> shortcuts,
+ ArrayList<LauncherAppWidgetInfo> appWidgets) {
+ if (mDestroyed) {
+ if (LauncherModel.DEBUG_LOADERS) {
+ d(LauncherModel.LOG_TAG, " ------> destroyed, ignoring desktop items");
+ }
+ return;
+ }
+ bindDesktopItems(shortcuts, appWidgets);
}
/**
* Refreshes the shortcuts shown on the workspace.
*/
- private void bindDesktopItems() {
- final ArrayList<ItemInfo> shortcuts = sModel.getDesktopItems();
- final ArrayList<LauncherAppWidgetInfo> appWidgets = sModel.getDesktopAppWidgets();
+ private void bindDesktopItems(ArrayList<ItemInfo> shortcuts,
+ ArrayList<LauncherAppWidgetInfo> appWidgets) {
+
final ApplicationsAdapter drawerAdapter = sModel.getApplicationsAdapter();
if (shortcuts == null || appWidgets == null || drawerAdapter == null) {
+ if (LauncherModel.DEBUG_LOADERS) d(LauncherModel.LOG_TAG, " ------> a source is null");
return;
}
@@ -1529,7 +1536,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
- if (LOGD) d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo));
+ if (LOGD) {
+ d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s",
+ appWidgetId, appWidgetInfo));
+ }
item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
item.hostView.setTag(item);
@@ -2171,9 +2181,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mAppWidgets.addLast(appWidgetInfo);
}
}
+
+ if (LauncherModel.DEBUG_LOADERS) {
+ d(Launcher.LOG_TAG, "------> binding " + shortcuts.size() + " items");
+ d(Launcher.LOG_TAG, "------> binding " + appWidgets.size() + " widgets");
+ }
}
public void startBindingItems() {
+ if (LauncherModel.DEBUG_LOADERS) d(Launcher.LOG_TAG, "------> start binding items");
obtainMessage(MESSAGE_BIND_ITEMS, 0, mShortcuts.size()).sendToTarget();
}
diff --git a/src/com/android/launcher/LauncherModel.java b/src/com/android/launcher/LauncherModel.java
index 15cd942..d69bd13 100644
--- a/src/com/android/launcher/LauncherModel.java
+++ b/src/com/android/launcher/LauncherModel.java
@@ -76,12 +76,16 @@ public class LauncherModel {
new HashMap<ComponentName, ApplicationInfo>(INITIAL_ICON_CACHE_CAPACITY);
synchronized void abortLoaders() {
+ if (DEBUG_LOADERS) d(LOG_TAG, "aborting loaders");
+
if (mApplicationsLoader != null && mApplicationsLoader.isRunning()) {
+ if (DEBUG_LOADERS) d(LOG_TAG, " --> aborting applications loader");
mApplicationsLoader.stop();
mApplicationsLoaded = false;
}
if (mDesktopItemsLoader != null && mDesktopItemsLoader.isRunning()) {
+ if (DEBUG_LOADERS) d(LOG_TAG, " --> aborting workspace loader");
mDesktopItemsLoader.stop();
mDesktopItemsLoaded = false;
}
@@ -474,6 +478,7 @@ public class LauncherModel {
}
private static final AtomicInteger sAppsLoaderCount = new AtomicInteger(1);
+ private static final AtomicInteger sWorkspaceLoaderCount = new AtomicInteger(1);
private class ApplicationsLoader implements Runnable {
private final WeakReference<Launcher> mLauncher;
@@ -612,7 +617,7 @@ public class LauncherModel {
if (DEBUG_LOADERS) d(LOG_TAG, " --> items loaded, return");
if (loadApplications) startApplicationsLoader(launcher, true);
// We have already loaded our data from the DB
- launcher.onDesktopItemsLoaded();
+ launcher.onDesktopItemsLoaded(mDesktopItems, mDesktopAppWidgets);
return;
}
@@ -720,6 +725,7 @@ public class LauncherModel {
private final boolean mLocaleChanged;
private final boolean mLoadApplications;
private final boolean mIsLaunching;
+ private final int mId;
DesktopItemsLoader(Launcher launcher, boolean localeChanged, boolean loadApplications,
boolean isLaunching) {
@@ -727,6 +733,7 @@ public class LauncherModel {
mIsLaunching = isLaunching;
mLauncher = new WeakReference<Launcher>(launcher);
mLocaleChanged = localeChanged;
+ mId = sWorkspaceLoaderCount.getAndIncrement();
}
void stop() {
@@ -738,6 +745,8 @@ public class LauncherModel {
}
public void run() {
+ if (DEBUG_LOADERS) d(LOG_TAG, " ----> running workspace loader (" + mId + ")");
+
mRunning = true;
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
@@ -943,16 +952,39 @@ public class LauncherModel {
}
if (!mStopped) {
- launcher.runOnUiThread(new Runnable() {
- public void run() {
- launcher.onDesktopItemsLoaded();
+ if (DEBUG_LOADERS) {
+ d(LOG_TAG, " --> done loading workspace");
+ d(LOG_TAG, " ----> worskpace items=" + desktopItems.size());
+ d(LOG_TAG, " ----> worskpace widgets=" + desktopAppWidgets.size());
+ }
+
+ // Create a copy of the lists in case the workspace loader is restarted
+ // and the list are cleared before the UI can go through them
+ final ArrayList<ItemInfo> uiDesktopItems =
+ new ArrayList<ItemInfo>(desktopItems);
+ final ArrayList<LauncherAppWidgetInfo> uiDesktopWidgets =
+ new ArrayList<LauncherAppWidgetInfo>(desktopAppWidgets);
+
+ if (!mStopped) {
+ d(LOG_TAG, " ----> items cloned, ready to refresh UI");
+ launcher.runOnUiThread(new Runnable() {
+ public void run() {
+ if (DEBUG_LOADERS) d(LOG_TAG, " ----> onDesktopItemsLoaded()");
+ launcher.onDesktopItemsLoaded(uiDesktopItems, uiDesktopWidgets);
+ }
+ });
+ }
+
+ if (mLoadApplications) {
+ if (DEBUG_LOADERS) {
+ d(LOG_TAG, " ----> loading applications from workspace loader");
}
- });
- if (mLoadApplications) startApplicationsLoader(launcher, mIsLaunching);
- }
+ startApplicationsLoader(launcher, mIsLaunching);
+ }
- if (!mStopped) {
mDesktopItemsLoaded = true;
+ } else {
+ if (DEBUG_LOADERS) d(LOG_TAG, " ----> worskpace loader was stopped");
}
mRunning = false;
}