Set SOURCE to app package name when starting QSB (if not set)

If QSB is started by SearchManager.startSearch(globalSearch=true)
from some app that doesn't set SOURCE, it will be set to the
package name of that app.

Bug: http://b/issue?id=2315234
Change-Id: Ic07a143b27b658dea8b081b973ac24349a18b9f1
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index 625b120..86224c5d 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -1654,10 +1654,17 @@
         Intent intent = new Intent(INTENT_ACTION_GLOBAL_SEARCH);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.setComponent(globalSearchActivity);
-        // TODO: Always pass name of calling package as an extra?
-        if (appSearchData != null) {
-            intent.putExtra(APP_DATA, appSearchData);
+        // Make sure that we have a Bundle to put source in
+        if (appSearchData == null) {
+            appSearchData = new Bundle();
+        } else {
+            appSearchData = new Bundle(appSearchData);
         }
+        // Set source to package name of app that starts global search, if not set already.
+        if (!appSearchData.containsKey("source")) {
+            appSearchData.putString("source", mContext.getPackageName());
+        }
+        intent.putExtra(APP_DATA, appSearchData);
         if (!TextUtils.isEmpty(initialQuery)) {
             intent.putExtra(QUERY, initialQuery);
         }