summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-12-07 16:09:16 +0000
committerBen Murdoch <benm@google.com>2010-12-08 14:25:20 +0000
commita941f6e87e73c15219042714745d1897cbd13582 (patch)
tree611d7150527faf6fba6af02f2da6ec89a3f512a9
parentb9e0d5c08145e53f2dabd62dee86fd9eb83a0079 (diff)
downloadpackages_apps_browser-a941f6e87e73c15219042714745d1897cbd13582.zip
packages_apps_browser-a941f6e87e73c15219042714745d1897cbd13582.tar.gz
packages_apps_browser-a941f6e87e73c15219042714745d1897cbd13582.tar.bz2
Fix StrictMode violation in shouldOverrideUrlLoading
Move the RLZ string database lookup into a background thread to clear up a fairly regular Strict Mode violation. Change-Id: I2a7bcc6649b6e3ae433226d838673ea8aef02db7
-rw-r--r--src/com/android/browser/UrlHandler.java55
1 files changed, 39 insertions, 16 deletions
diff --git a/src/com/android/browser/UrlHandler.java b/src/com/android/browser/UrlHandler.java
index 72704e0..52945b3 100644
--- a/src/com/android/browser/UrlHandler.java
+++ b/src/com/android/browser/UrlHandler.java
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
+import android.os.AsyncTask;
import android.util.Log;
import android.webkit.WebView;
@@ -98,22 +99,11 @@ public class UrlHandler {
if (rlzProviderPresent()) {
Uri siteUri = Uri.parse(url);
if (needsRlzString(siteUri)) {
- String rlz = null;
- Cursor cur = null;
- try {
- cur = mActivity.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();
- }
- }
- mController.loadUrl(view, url);
+ // Need to look up the RLZ info from a database, so do it in an
+ // AsyncTask. Although we are not overriding the URL load synchronously,
+ // we guarantee that we will handle this URL load after the task executes,
+ // so it's safe to just return true to WebCore now to stop its own loading.
+ new RLZTask(siteUri, view).execute();
return true;
}
}
@@ -173,6 +163,39 @@ public class UrlHandler {
return false;
}
+ private class RLZTask extends AsyncTask<Void, Void, String> {
+ private Uri mSiteUri;
+ private WebView mWebView;
+
+ public RLZTask(Uri uri, WebView webView) {
+ mSiteUri = uri;
+ mWebView = webView;
+ }
+
+ protected String doInBackground(Void... unused) {
+ String result = mSiteUri.toString();
+ Cursor cur = null;
+ try {
+ cur = mActivity.getContentResolver()
+ .query(getRlzUri(), null, null, null, null);
+ if (cur != null && cur.moveToFirst() && !cur.isNull(0)) {
+ result = mSiteUri.buildUpon()
+ .appendQueryParameter("rlz", cur.getString(0))
+ .build().toString();
+ }
+ } finally {
+ if (cur != null) {
+ cur.close();
+ }
+ }
+ return result;
+ }
+
+ protected void onPostExecute(String result) {
+ mController.loadUrl(mWebView, result);
+ }
+ }
+
// Determine whether the RLZ provider is present on the system.
private boolean rlzProviderPresent() {
if (mIsProviderPresent == null) {