Tagging where ItemInfos are created for debug purposes

Change-Id: Iad3ed8ef4f81f4990c027ab46fd25b03b089babb
diff --git a/src/com/android/launcher2/AllAppsList.java b/src/com/android/launcher2/AllAppsList.java
index 051b0bd..7c107a7 100644
--- a/src/com/android/launcher2/AllAppsList.java
+++ b/src/com/android/launcher2/AllAppsList.java
@@ -91,7 +91,7 @@
 
         if (matches.size() > 0) {
             for (ResolveInfo info : matches) {
-                add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null));
+                add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null, "15"));
             }
         }
     }
@@ -142,7 +142,7 @@
                         info.activityInfo.applicationInfo.packageName,
                         info.activityInfo.name);
                 if (applicationInfo == null) {
-                    add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null));
+                    add(new ApplicationInfo(context.getPackageManager(), info, mIconCache, null, "16"));
                 } else {
                     mIconCache.remove(applicationInfo.componentName);
                     mIconCache.getTitleAndIcon(applicationInfo, info, null);
diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java
index 1fc1d1f..bbca664 100644
--- a/src/com/android/launcher2/ApplicationInfo.java
+++ b/src/com/android/launcher2/ApplicationInfo.java
@@ -60,7 +60,8 @@
 
     int flags = 0;
 
-    ApplicationInfo() {
+    ApplicationInfo(String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
     }
 
@@ -68,7 +69,8 @@
      * Must not hold the Context.
      */
     public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache,
-            HashMap<Object, CharSequence> labelCache) {
+            HashMap<Object, CharSequence> labelCache, String whereCreated) {
+        super(whereCreated);
         final String packageName = info.activityInfo.applicationInfo.packageName;
 
         this.componentName = new ComponentName(packageName, info.activityInfo.name);
@@ -93,8 +95,8 @@
         iconCache.getTitleAndIcon(this, info, labelCache);
     }
 
-    public ApplicationInfo(ApplicationInfo info) {
-        super(info);
+    public ApplicationInfo(ApplicationInfo info, String whereCreated) {
+        super(info, whereCreated);
         componentName = info.componentName;
         title = info.title.toString();
         intent = new Intent(info.intent);
@@ -133,6 +135,6 @@
     }
 
     public ShortcutInfo makeShortcut() {
-        return new ShortcutInfo(this);
+        return new ShortcutInfo(this, "18");
     }
 }
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 0e442ea..3adf404 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -1016,7 +1016,7 @@
             if (rawInfo instanceof AppWidgetProviderInfo) {
                 // Fill in the widget information
                 AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
-                createItemInfo = new PendingAddWidgetInfo(info, null, null);
+                createItemInfo = new PendingAddWidgetInfo(info, null, null, "13");
                 int[] cellSpans = CellLayout.rectToCell(getResources(),
                         info.minWidth, info.minHeight, null);
                 FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
@@ -1026,7 +1026,7 @@
             } else if (rawInfo instanceof ResolveInfo) {
                 // Fill in the shortcuts information
                 ResolveInfo info = (ResolveInfo) rawInfo;
-                createItemInfo = new PendingAddItemInfo();
+                createItemInfo = new PendingAddItemInfo("14");
                 createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
                 createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
                         info.activityInfo.name);
diff --git a/src/com/android/launcher2/FolderInfo.java b/src/com/android/launcher2/FolderInfo.java
index 3ae31d2..0f8b9e0 100644
--- a/src/com/android/launcher2/FolderInfo.java
+++ b/src/com/android/launcher2/FolderInfo.java
@@ -42,7 +42,8 @@
 
     ArrayList<FolderListener> listeners = new ArrayList<FolderListener>();
 
-    FolderInfo() {
+    FolderInfo(String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
     }
 
diff --git a/src/com/android/launcher2/InstallWidgetReceiver.java b/src/com/android/launcher2/InstallWidgetReceiver.java
index 6b3763c..1b54e90 100644
--- a/src/com/android/launcher2/InstallWidgetReceiver.java
+++ b/src/com/android/launcher2/InstallWidgetReceiver.java
@@ -187,7 +187,7 @@
             final AppWidgetProviderInfo widgetInfo = mActivities.get(which).widgetInfo;
 
             final PendingAddWidgetInfo createInfo = new PendingAddWidgetInfo(widgetInfo, mMimeType,
-                    mClipData);
+                    mClipData, "4");
             mLauncher.addAppWidgetFromDrop(createInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP,
                     mTargetLayoutScreen, null, mTargetLayoutPos);
         }
diff --git a/src/com/android/launcher2/ItemInfo.java b/src/com/android/launcher2/ItemInfo.java
index 8d46624..5c05f16 100644
--- a/src/com/android/launcher2/ItemInfo.java
+++ b/src/com/android/launcher2/ItemInfo.java
@@ -86,10 +86,16 @@
      */
     int[] dropPos = null;
 
-    ItemInfo() {
+    /*
+     *  A tag to know where this item was created
+     */
+    String whereCreated;
+
+    ItemInfo(String whereCreated) {
+        this.whereCreated = whereCreated;
     }
 
-    ItemInfo(ItemInfo info) {
+    ItemInfo(ItemInfo info, String whereCreated) {
         id = info.id;
         cellX = info.cellX;
         cellY = info.cellY;
@@ -98,6 +104,7 @@
         screen = info.screen;
         itemType = info.itemType;
         container = info.container;
+        this.whereCreated = whereCreated;
     }
 
     /**
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 6c446a2..f05850b 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -176,7 +176,7 @@
     private AppWidgetManager mAppWidgetManager;
     private LauncherAppWidgetHost mAppWidgetHost;
 
-    private ItemInfo mPendingAddInfo = new ItemInfo();
+    private ItemInfo mPendingAddInfo = new ItemInfo("1");
     private int[] mTmpAddItemCellCoordinates = new int[2];
 
     private FolderInfo mFolderInfo;
@@ -930,7 +930,7 @@
         }
 
         // Build Launcher-specific widget info and save to database
-        LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
+        LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, "2");
         launcherInfo.spanX = spanXY[0];
         launcherInfo.spanY = spanXY[1];
 
@@ -1474,7 +1474,7 @@
 
     FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
             int cellY) {
-        final FolderInfo folderInfo = new FolderInfo();
+        final FolderInfo folderInfo = new FolderInfo("3");
         folderInfo.title = getText(R.string.folder_name);
 
         // Update the model
diff --git a/src/com/android/launcher2/LauncherAppWidgetInfo.java b/src/com/android/launcher2/LauncherAppWidgetInfo.java
index 844abb5..69eae17 100644
--- a/src/com/android/launcher2/LauncherAppWidgetInfo.java
+++ b/src/com/android/launcher2/LauncherAppWidgetInfo.java
@@ -51,7 +51,8 @@
     /**
      * Constructor for use with AppWidgets that haven't been instantiated yet.
      */
-    LauncherAppWidgetInfo(ComponentName providerName) {
+    LauncherAppWidgetInfo(ComponentName providerName, String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
         this.providerName = providerName;
 
@@ -61,7 +62,8 @@
         spanY = -1;
     }
 
-    LauncherAppWidgetInfo(int appWidgetId) {
+    LauncherAppWidgetInfo(int appWidgetId, String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
         this.appWidgetId = appWidgetId;
     }
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 4ad8922..ea51d01 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -210,8 +210,10 @@
                         // the modelItem needs to match up perfectly with item if our model is to be
                         // consistent with the database-- for now, just require modelItem == item
                         String msg = "item: " + ((item != null) ? item.toString() : "null") +
-                            "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
-                            "Error: ItemInfo passed to moveItemInDatabase doesn't match original";
+                            " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
+                            " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
+                            " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
+                            " Error: ItemInfo passed to moveItemInDatabase doesn't match original";
                         throw new RuntimeException(msg);
                     }
 
@@ -258,8 +260,10 @@
                         // the modelItem needs to match up perfectly with item if our model is to be
                         // consistent with the database-- for now, just require modelItem == item
                         String msg = "item: " + ((item != null) ? item.toString() : "null") +
-                            "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
-                            "Error: ItemInfo passed to resizeItemInDatabase doesn't match original";
+                            " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
+                            " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
+                            " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
+                            " Error: ItemInfo passed to resizeItemInDatabase doesn't match original";
                         throw new RuntimeException(msg);
                     }
                 }
@@ -306,7 +310,7 @@
 
         try {
             while (c.moveToNext()) {
-                ItemInfo item = new ItemInfo();
+                ItemInfo item = new ItemInfo("17");
                 item.cellX = c.getInt(cellXIndex);
                 item.cellY = c.getInt(cellYIndex);
                 item.spanX = c.getInt(spanXIndex);
@@ -470,8 +474,10 @@
                     // the modelItem needs to match up perfectly with item if our model is to be
                     // consistent with the database-- for now, just require modelItem == item
                     String msg = "item: " + ((item != null) ? item.toString() : "null") +
-                        "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
-                        "Error: ItemInfo passed to updateItemInDatabase doesn't match original";
+                        " modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
+                        " creation tag of item: " + ((item != null) ? item.whereCreated : "null") +
+                        " creation tag of modelItem: " + ((modelItem != null) ? modelItem.whereCreated : "null") +
+                        " Error: ItemInfo passed to updateItemInDatabase doesn't match original";
                     throw new RuntimeException(msg);
                 }
             }
@@ -1059,7 +1065,7 @@
                                         + id + " appWidgetId=" + appWidgetId);
                                 itemsToRemove.add(id);
                             } else {
-                                appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
+                                appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, "5");
                                 appWidgetInfo.id = id;
                                 appWidgetInfo.screen = c.getInt(screenIndex);
                                 appWidgetInfo.cellX = c.getInt(cellXIndex);
@@ -1345,7 +1351,7 @@
                 for (int j=0; i<N && j<batchSize; j++) {
                     // This builds the icon bitmaps.
                     mAllAppsList.add(new ApplicationInfo(packageManager, apps.get(i),
-                            mIconCache, mLabelCache));
+                            mIconCache, mLabelCache, "6"));
                     i++;
                 }
 
@@ -1541,7 +1547,7 @@
     public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context,
             Cursor c, int iconIndex, int titleIndex, HashMap<Object, CharSequence> labelCache) {
         Bitmap icon = null;
-        final ShortcutInfo info = new ShortcutInfo();
+        final ShortcutInfo info = new ShortcutInfo("7");
 
         ComponentName componentName = intent.getComponent();
         if (componentName == null) {
@@ -1606,7 +1612,7 @@
             int titleIndex) {
 
         Bitmap icon = null;
-        final ShortcutInfo info = new ShortcutInfo();
+        final ShortcutInfo info = new ShortcutInfo("8");
         info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
 
         // TODO: If there's an explicit component and we can't install that, delete it.
@@ -1765,7 +1771,7 @@
             }
         }
 
-        final ShortcutInfo info = new ShortcutInfo();
+        final ShortcutInfo info = new ShortcutInfo("9");
 
         if (icon == null) {
             if (fallbackIcon != null) {
@@ -1833,7 +1839,7 @@
         FolderInfo folderInfo = folders.get(id);
         if (folderInfo == null) {
             // No placeholder -- create a new instance
-            folderInfo = new FolderInfo();
+            folderInfo = new FolderInfo("10");
             folders.put(id, folderInfo);
         }
         return folderInfo;
diff --git a/src/com/android/launcher2/PendingAddItemInfo.java b/src/com/android/launcher2/PendingAddItemInfo.java
index 7b564e0..6ee300b 100644
--- a/src/com/android/launcher2/PendingAddItemInfo.java
+++ b/src/com/android/launcher2/PendingAddItemInfo.java
@@ -28,6 +28,10 @@
      * The component that will be created.
      */
     ComponentName componentName;
+
+    public PendingAddItemInfo(String whereCreated) {
+        super(whereCreated);
+    }
 }
 
 class PendingAddWidgetInfo extends PendingAddItemInfo {
@@ -39,7 +43,9 @@
     String mimeType;
     Parcelable configurationData;
 
-    public PendingAddWidgetInfo(AppWidgetProviderInfo i, String dataMimeType, Parcelable data) {
+    public PendingAddWidgetInfo(
+            AppWidgetProviderInfo i, String dataMimeType, Parcelable data, String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
         componentName = i.provider;
         minWidth = i.minWidth;
diff --git a/src/com/android/launcher2/ShortcutInfo.java b/src/com/android/launcher2/ShortcutInfo.java
index c0f80ae..6d4853f 100644
--- a/src/com/android/launcher2/ShortcutInfo.java
+++ b/src/com/android/launcher2/ShortcutInfo.java
@@ -62,12 +62,14 @@
      */
     private Bitmap mIcon;
 
-    ShortcutInfo() {
+    ShortcutInfo(String whereCreated) {
+        super(whereCreated);
         itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
+        this.whereCreated = whereCreated;
     }
     
-    public ShortcutInfo(ShortcutInfo info) {
-        super(info);
+    public ShortcutInfo(ShortcutInfo info, String whereCreated) {
+        super(info, whereCreated);
         title = info.title.toString();
         intent = new Intent(info.intent);
         if (info.iconResource != null) {
@@ -80,8 +82,8 @@
     }
 
     /** TODO: Remove this.  It's only called by ApplicationInfo.makeShortcut. */
-    public ShortcutInfo(ApplicationInfo info) {
-        super(info);
+    public ShortcutInfo(ApplicationInfo info, String whereCreated) {
+        super(info, whereCreated);
         title = info.title.toString();
         intent = new Intent(info.intent);
         customIcon = false;
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 1c13f14..3e0b466 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -2575,7 +2575,7 @@
                         // that widget
                         final AppWidgetProviderInfo widgetInfo = widgets.get(0).widgetInfo;
                         final PendingAddWidgetInfo createInfo =
-                                new PendingAddWidgetInfo(widgetInfo, mimeType, data);
+                                new PendingAddWidgetInfo(widgetInfo, mimeType, data, "11");
                         mLauncher.addAppWidgetFromDrop(createInfo,
                             LauncherSettings.Favorites.CONTAINER_DESKTOP, mCurrentPage, null, pos);
                     } else {
@@ -3091,7 +3091,7 @@
             case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                 if (info.container == NO_ID && info instanceof ApplicationInfo) {
                     // Came from all apps -- make a copy
-                    info = new ShortcutInfo((ApplicationInfo) info);
+                    info = new ShortcutInfo((ApplicationInfo) info, "12");
                 }
                 view = mLauncher.createShortcut(R.layout.application, cellLayout,
                         (ShortcutInfo) info);