OSDN Git Service

Fix a race condition that caused the Launcher to be blank when triggered.
authorchrisrl <chris+android@zenthought.org>
Mon, 26 Oct 2009 18:30:03 +0000 (13:30 -0500)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sat, 17 Apr 2010 16:09:16 +0000 (00:09 +0800)
src/com/android/launcher/LauncherModel.java

index 25cbca3..935fae2 100644 (file)
@@ -541,10 +541,12 @@ public class LauncherModel {
                 launcher.runOnUiThread(action);
             }
 
-            if (!mStopped) {
-                mApplicationsLoaded = true;
-            } else {
-                if (DEBUG_LOADERS) d(LOG_TAG, "  ----> applications loader stopped (" + mId + ")");                                
+            synchronized(LauncherModel.this) {
+                if (!mStopped) {
+                    mApplicationsLoaded = true;
+                } else {
+                    if (DEBUG_LOADERS) d(LOG_TAG, "  ----> applications loader stopped (" + mId + ")");
+                }
             }
             mRunning = false;
         }
@@ -951,40 +953,42 @@ public class LauncherModel {
                 c.close();
             }
 
-            if (!mStopped) {
-                if (DEBUG_LOADERS)  {
-                    d(LOG_TAG, "  --> done loading workspace");
-                    d(LOG_TAG, "  ----> worskpace items=" + desktopItems.size());                
-                    d(LOG_TAG, "  ----> worskpace widgets=" + desktopAppWidgets.size());
-                }
+            synchronized(LauncherModel.this) {
+                if (!mStopped) {
+                    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);
+                    // 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 (!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) {
-                    if (DEBUG_LOADERS) {
-                        d(LOG_TAG, "  ----> loading applications from workspace loader");
+                        startApplicationsLoader(launcher, mIsLaunching);
                     }
-                    startApplicationsLoader(launcher, mIsLaunching);
-                }
 
-                mDesktopItemsLoaded = true;
-            } else {
-                if (DEBUG_LOADERS) d(LOG_TAG, "  ----> worskpace loader was stopped");
+                    mDesktopItemsLoaded = true;
+                } else {
+                    if (DEBUG_LOADERS) d(LOG_TAG, "  ----> worskpace loader was stopped");
+                }
             }
             mRunning = false;
         }