Specify workspace resource in preload broadcast

Bug 7203884

Allow specifying the workspace XML layout in the PRELOAD_WORKSPACE
broadcast.

Change-Id: Iec01c6fa2dde4635f624f040b0772ee11fcd88dc
diff --git a/src/com/android/launcher2/PreloadReceiver.java b/src/com/android/launcher2/PreloadReceiver.java
index 7bec721..08350b6 100644
--- a/src/com/android/launcher2/PreloadReceiver.java
+++ b/src/com/android/launcher2/PreloadReceiver.java
@@ -19,16 +19,31 @@
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.text.TextUtils;
+import android.util.Log;
 
 public class PreloadReceiver extends BroadcastReceiver {
+    private static final String TAG = "Launcher.PreloadReceiver";
+    private static final boolean LOGD = false;
+
+    public static final String EXTRA_WORKSPACE_NAME =
+            "com.android.launcher.action.EXTRA_WORKSPACE_NAME";
+
     @Override
     public void onReceive(Context context, Intent intent) {
         final LauncherApplication app = (LauncherApplication) context.getApplicationContext();
         final LauncherProvider provider = app.getLauncherProvider();
         if (provider != null) {
+            String name = intent.getStringExtra(EXTRA_WORKSPACE_NAME);
+            final int workspaceResId = !TextUtils.isEmpty(name)
+                    ? context.getResources().getIdentifier(name, "xml", "com.android.launcher") : 0;
+            if (LOGD) {
+                Log.d(TAG, "workspace name: " + name + " id: " + workspaceResId);
+            }
             new Thread(new Runnable() {
+                @Override
                 public void run() {
-                    provider.loadDefaultFavoritesIfNecessary();
+                    provider.loadDefaultFavoritesIfNecessary(workspaceResId);
                 }
             }).start();
         }