DO NOT MERGE - Backport RLZ code to GB:
- 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: I7ce0e7bead7954ed9ebfe10b66242553f14ed6f2
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 435560b..793a43c 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -188,6 +188,8 @@
// Keep a settings instance handy.
mSettings = BrowserSettings.getInstance();
+ mSettings.updateRlzValues(this);
+
// If this was a web search request, pass it on to the default web
// search provider and finish this activity.
if (handleWebSearchIntent(getIntent())) {
@@ -633,6 +635,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 (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)
@@ -4003,4 +4016,20 @@
};
/* package */ static final UrlData EMPTY_URL_DATA = new UrlData(null);
+
+ 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();
+ }
}