DO NOT MERGE - Update and fix RLZ code:
  - Cache RLZ parameter
  - Set RLZ parameter for address bar searches
  - Add broadcast receiver to handle RLZ updates
  - Update RLZ parameters in home page and bookmarks
Bug: 4436761

Change-Id: I505932656c68dca458283598c2f647e035f120d3
diff --git a/src/com/android/browser/IntentHandler.java b/src/com/android/browser/IntentHandler.java
index fa8bfbc..b556638 100644
--- a/src/com/android/browser/IntentHandler.java
+++ b/src/com/android/browser/IntentHandler.java
@@ -221,6 +221,17 @@
                             headers.put(key, pairs.getString(key));
                         }
                     }
+
+                    // AppId will be set to the Browser for Search Bar initiated searches
+                    final String appId = intent.getStringExtra(Browser.EXTRA_APPLICATION_ID);
+                    if (mActivity.getPackageName().equals(appId)) {
+                        String rlz = mSettings.getRlzValue();
+                        Uri uri = Uri.parse(url);
+                        if (!rlz.isEmpty() && needsRlz(uri)) {
+                            Uri rlzUri = addRlzParameter(uri, rlz);
+                            url = rlzUri.toString();
+                        }
+                    }
                 }
             } else if (Intent.ACTION_SEARCH.equals(action)
                     || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)
@@ -364,4 +375,19 @@
         }
     }
 
+    private static boolean needsRlz(Uri uri) {
+        if ((uri.getQueryParameter("rlz") == null) &&
+            (uri.getQueryParameter("q") != null) &&
+            UrlUtils.isGoogleUri(uri)) {
+            return true;
+        }
+        return false;
+    }
+
+    private static Uri addRlzParameter(Uri uri, String rlz) {
+        if (rlz.isEmpty()) {
+            return uri;
+        }
+        return uri.buildUpon().appendQueryParameter("rlz", rlz).build();
+    }
 }