diff options
-rw-r--r-- | AndroidManifest.xml | 8 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 80 | ||||
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 5 |
4 files changed, 97 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f50c9f0..14e8aeb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -233,6 +233,14 @@ <!-- Makes .BrowserActivity the search target for any activity in Browser --> <meta-data android:name="android.app.default_searchable" android:value=".BrowserActivity" /> + <!-- Application code for RLZ tracking. RLZ assigns non-unique, non-personally identifiable + tracking labels to client products; these labels sometimes appear in Google search + queries. See http://code.google.com/p/rlz for more info. + + This value signifies to the RLZ client that this application uses RLZ tracking. --> + <meta-data android:name="com.google.android.partnersetup.RLZ_ACCESS_POINT" + android:value="@string/rlz_access_point" /> + <receiver android:name=".OpenDownloadReceiver"> <intent-filter> <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/> diff --git a/res/values/strings.xml b/res/values/strings.xml index 238cf5c..e825b85 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -754,4 +754,8 @@ <!-- The default state to the "up to parent folder" button in the bookmarks UI. This is displayed when the user is at the highest level and cannot go up --> <string name="defaultBookmarksUpButton">Bookmarks</string> + + <!-- Access point for RLZ tracking. --> + <string name="rlz_access_point">Y1</string> + </resources> diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 54fb96f..548eba6 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -167,6 +167,9 @@ public class BrowserActivity extends Activity private boolean mXLargeScreenSize; + private Boolean mIsProviderPresent = null; + private Uri mRlzUri = null; + @Override public void onCreate(Bundle icicle) { if (LOGV_ENABLED) { @@ -2784,6 +2787,29 @@ public class BrowserActivity extends Activity return false; } + // If this is a Google search, attempt to add an RLZ string (if one isn't already present). + if (rlzProviderPresent()) { + Uri siteUri = Uri.parse(url); + if (needsRlzString(siteUri)) { + String rlz = null; + Cursor cur = null; + try { + cur = getContentResolver().query(getRlzUri(), null, null, null, null); + if (cur != null && cur.moveToFirst() && !cur.isNull(0)) { + url = siteUri.buildUpon() + .appendQueryParameter("rlz", cur.getString(0)) + .build().toString(); + } + } finally { + if (cur != null) { + cur.close(); + } + } + loadUrl(view, url); + return true; + } + } + Intent intent; // perform generic parsing of the URI to turn it into an Intent. try { @@ -2839,6 +2865,60 @@ public class BrowserActivity extends Activity return false; } + // Determine whether the RLZ provider is present on the system. + private boolean rlzProviderPresent() { + if (mIsProviderPresent == null) { + PackageManager pm = getPackageManager(); + mIsProviderPresent = pm.resolveContentProvider(BrowserSettings.RLZ_PROVIDER, 0) != null; + } + return mIsProviderPresent; + } + + // Retrieve the RLZ access point string and cache the URI used to retrieve RLZ values. + private Uri getRlzUri() { + if (mRlzUri == null) { + String ap = getResources().getString(R.string.rlz_access_point); + mRlzUri = Uri.withAppendedPath(BrowserSettings.RLZ_PROVIDER_URI, ap); + } + return mRlzUri; + } + + // Determine if this URI appears to be for a Google search and does not have an RLZ parameter. + // Taken largely from Chrome source, src/chrome/browser/google_url_tracker.cc + private static boolean needsRlzString(Uri uri) { + if ((uri.getQueryParameter("q") != null) && (uri.getQueryParameter("rlz") == null)) { + String host = uri.getHost(); + if (host == null) { + return false; + } + String[] hostComponents = host.split("\\."); + + if (hostComponents.length < 2) { + return false; + } + int googleComponent = hostComponents.length - 2; + String component = hostComponents[googleComponent]; + if (!"google".equals(component)) { + if (hostComponents.length < 3 || + (!"co".equals(component) && !"com".equals(component))) { + return false; + } + googleComponent = hostComponents.length - 3; + if (!"google".equals(hostComponents[googleComponent])) { + return false; + } + } + + // Google corp network handling. + if (googleComponent > 0 && "corp".equals(hostComponents[googleComponent - 1])) { + return false; + } + + return true; + } + return false; + } + // ------------------------------------------------------------------------- // Helper function for WebChromeClient // ------------------------------------------------------------------------- diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 94bed2d..2f739fa 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.pm.ActivityInfo; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.net.Uri; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; import android.webkit.CookieManager; @@ -156,6 +157,10 @@ class BrowserSettings extends Observable { // a ListView public final static int MAX_TEXTVIEW_LEN = 80; + public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider"; + + public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/"); + private TabControl mTabControl; // Single instance of the BrowserSettings for use in the Browser app. |