Add support for <include> in workspace XML.

Note that this doesn't honor folder nesting (that is, you
can't include an XML file full of shortcuts inside a
<folder> node and expect them all to appear in that folder).
It's really just a way to concatenate/overlay multiple XML
files, making it easier to make a few tweaks/additions for
certain screen sizes or locales.

Bug: 10932771
Change-Id: I1fc29477d0717a8a7bc116f16729a955e6c625d5
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 471d2d2..5a8f630 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -296,6 +296,7 @@
         private static final String TAG_SHORTCUT = "shortcut";
         private static final String TAG_FOLDER = "folder";
         private static final String TAG_EXTRA = "extra";
+        private static final String TAG_INCLUDE = "include";
 
         private final Context mContext;
         private final AppWidgetHost mAppWidgetHost;
@@ -1011,6 +1012,8 @@
             intent.addCategory(Intent.CATEGORY_LAUNCHER);
             ContentValues values = new ContentValues();
 
+            if (LOGD) Log.v(TAG, String.format("Loading favorites from resid=0x%08x", workspaceResourceId));
+
             PackageManager packageManager = mContext.getPackageManager();
             int i = 0;
             try {
@@ -1031,6 +1034,30 @@
                     boolean added = false;
                     final String name = parser.getName();
 
+                    if (TAG_INCLUDE.equals(name)) {
+                        final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Include);
+
+                        final int resId = a.getResourceId(R.styleable.Include_workspace, 0);
+
+                        if (LOGD) Log.v(TAG, String.format(("%" + (2*(depth+1)) + "s<include workspace=%08x>"),
+                                "", resId));
+
+                        if (resId != 0 && resId != workspaceResourceId) {
+                            // recursively load some more favorites, why not?
+                            i += loadFavorites(db, resId);
+                            added = false;
+                            mMaxItemId = -1;
+                        } else {
+                            Log.w(TAG, String.format("Skipping <include workspace=0x%08x>", resId));
+                        }
+
+                        a.recycle();
+
+                        if (LOGD) Log.v(TAG, String.format(("%" + (2*(depth+1)) + "s</include>"), ""));
+                        continue;
+                    }
+
+                    // Assuming it's a <favorite> at this point
                     TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Favorite);
 
                     long container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
@@ -1048,6 +1075,17 @@
                     values.put(LauncherSettings.Favorites.CELLX, x);
                     values.put(LauncherSettings.Favorites.CELLY, y);
 
+                    if (LOGD) {
+                        final String title = a.getString(R.styleable.Favorite_title);
+                        final String pkg = a.getString(R.styleable.Favorite_packageName);
+                        final String something = title != null ? title : pkg;
+                        Log.v(TAG, String.format(
+                                ("%" + (2*(depth+1)) + "s<%s%s c=%d s=%s x=%s y=%s>"),
+                                "", name,
+                                (something == null ? "" : (" \"" + something + "\"")),
+                                container, screen, x, y));
+                    }
+
                     if (TAG_FAVORITE.equals(name)) {
                         long id = addAppShortcut(db, values, a, packageManager, intent);
                         added = id >= 0;
@@ -1087,6 +1125,13 @@
                             values.clear();
                             values.put(LauncherSettings.Favorites.CONTAINER, folderId);
 
+                            if (LOGD) {
+                                final String pkg = ar.getString(R.styleable.Favorite_packageName);
+                                final String uri = ar.getString(R.styleable.Favorite_uri);
+                                Log.v(TAG, String.format(("%" + (2*(folderDepth+1)) + "s<%s \"%s\">"), "",
+                                        folder_item_name, uri != null ? uri : pkg));
+                            }
+
                             if (TAG_FAVORITE.equals(folder_item_name) && folderId >= 0) {
                                 long id =
                                     addAppShortcut(db, values, ar, packageManager, intent);