Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue where Home was not loading the workspace items.

This change also adds new logs to help track down the issue if it
happens again.
  • Loading branch information...
commit 4e8fc32dd59a45dda46c322904895336d0e79a3a 1 parent d1057c6
@romainguy romainguy authored
View
30 src/com/android/launcher/Launcher.java
@@ -1367,19 +1367,26 @@ private void onFavoritesChanged() {
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 @@ private void bindAppWidgets(Launcher.DesktopBinder binder,
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 void onScrollEnded() {
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();
}
View
48 src/com/android/launcher/LauncherModel.java
@@ -76,12 +76,16 @@
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 @@ private static void updateApplicationInfoTitleAndIcon(PackageManager manager, Re
}
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 @@ void loadUserItems(boolean isLaunching, Launcher launcher, boolean localeChanged
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 @@ private static String getLabel(PackageManager manager, ActivityInfo activityInfo
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 @@ private static String getLabel(PackageManager manager, ActivityInfo activityInfo
mIsLaunching = isLaunching;
mLauncher = new WeakReference<Launcher>(launcher);
mLocaleChanged = localeChanged;
+ mId = sWorkspaceLoaderCount.getAndIncrement();
}
void stop() {
@@ -738,6 +745,8 @@ boolean isRunning() {
}
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 void run() {
}
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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.