fix 2315821 and 2315729 - problems caused because the apps list could become
unsynchronized with the list of icons.
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
index 0c45075..88f074c 100644
--- a/src/com/android/launcher2/AllAppsView.java
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -277,7 +277,7 @@
                 mShouldGainFocus = true;
             }
         } else {
-            if (mRollo != null && mRollo.mHasSurface) {
+            if (mRollo != null) {
                 if (mArrowNavigation) {
                     // Clear selection when we lose focus
                     mRollo.clearSelectedIcon();
@@ -674,7 +674,7 @@
         }
 
         final int N = list.size();
-        if (mRollo != null && mRollo.mHasSurface) {
+        if (mRollo != null) {
             mRollo.reallocAppsList(mRollo.mState.iconCount + N);
         }
 
@@ -686,13 +686,12 @@
                 index = -(index+1);
             }
             mAllAppsList.add(index, item);
-            if (mRollo != null && mRollo.mHasSurface) {
+            if (mRollo != null) {
                 mRollo.addApp(index, item);
-                mRollo.mState.iconCount++;
             }
         }
 
-        if (mRollo != null && mRollo.mHasSurface) {
+        if (mRollo != null) {
             mRollo.saveAppsList();
         }
     }
@@ -710,7 +709,7 @@
             if (index >= 0) {
                 int ic = mRollo != null ? mRollo.mState.iconCount : 666;
                 mAllAppsList.remove(index);
-                if (mRollo != null && mRollo.mHasSurface) {
+                if (mRollo != null) {
                     mRollo.removeApp(index);
                 }
             } else {
@@ -719,7 +718,7 @@
             }
         }
 
-        if (mRollo != null && mRollo.mHasSurface) {
+        if (mRollo != null) {
             mRollo.saveAppsList();
         }
     }
@@ -1050,16 +1049,12 @@
             mRS.contextBindRootScript(mScript);
         }
 
-        private void uploadApps(ArrayList<ApplicationInfo> list) {
-            for (int i=0; i < mState.iconCount; i++) {
-                uploadAppIcon(i, list.get(i));
-            }
-        }
-
         void dirtyCheck() {
             if (mHasSurface) {
                 if (mAppsDirty) {
-                    uploadApps(mAllAppsList);
+                    for (int i=0; i < mState.iconCount; i++) {
+                        uploadAppIcon(i, mAllAppsList.get(i));
+                    }
                     saveAppsList();
                     mAppsDirty = false;
                 }
@@ -1086,10 +1081,11 @@
 
             Element ie8888 = Element.RGBA_8888(mRS);
 
-            Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
-
             mState.iconCount = count;
-            uploadApps(list);
+            for (int i=0; i < mState.iconCount; i++) {
+                createAppIconAllocations(i, list.get(i));
+                uploadAppIcon(i, list.get(i));
+            }
             saveAppsList();
         }
 
@@ -1124,22 +1120,32 @@
             a.subData(0, 0, 1, 1, black);
         }
 
-        private void uploadAppIcon(int index, ApplicationInfo item) {
+        private void createAppIconAllocations(int index, ApplicationInfo item) {
             mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap,
                     Element.RGBA_8888(mRS), true);
-            frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), item.iconBitmap.getHeight());
+            frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(),
+                    item.iconBitmap.getHeight());
 
             mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap,
                     Element.RGBA_8888(mRS), true);
-            frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(), item.titleBitmap.getHeight());
-
-            mIcons[index].uploadToTexture(0);
-            mLabels[index].uploadToTexture(0);
+            frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(),
+                    item.titleBitmap.getHeight());
 
             mIconIds[index] = mIcons[index].getID();
             mLabelIds[index] = mLabels[index].getID();
         }
 
+        private void uploadAppIcon(int index, ApplicationInfo item) {
+            if (mIconIds[index] != mIcons[index].getID()) {
+                throw new IllegalStateException("uploadAppIcon index=" + index
+                    + " mIcons[index].getID=" + mIcons[index].getID()
+                    + " mIconsIds[index]=" + mIconIds[index]
+                    + " item=" + item);
+            }
+            mIcons[index].uploadToTexture(0);
+            mLabels[index].uploadToTexture(0);
+        }
+
         /**
          * Puts the empty spaces at the end.  Updates mState.iconCount.  You must
          * fill in the values and call saveAppsList().
@@ -1178,11 +1184,15 @@
             System.arraycopy(mLabels, index, mLabels, dest, count);
             System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
 
+            createAppIconAllocations(index, item);
+
             if (mHasSurface) {
                 uploadAppIcon(index, item);
             } else {
                 mAppsDirty = true;
             }
+
+            mRollo.mState.iconCount++;
         }
 
         /**
@@ -1198,7 +1208,7 @@
             System.arraycopy(mLabelIds, src, mLabelIds, index, count);
 
             mRollo.mState.iconCount--;
-            final int last = mState.iconCount - 1;
+            final int last = mState.iconCount;
 
             mIcons[last] = null;
             mIconIds[last] = 0;