Bug 919645 - crash in android.os.NetworkOnMainThreadException. r=bnicholson
authorRichard Newman <rnewman@mozilla.com>
Mon, 07 Oct 2013 12:54:41 -0700
changeset 163860 54d196d5fdfb1a6dbdd0a8f169544a6c18cbd074
parent 163833 5f0569c3cb8fd3d4377d9db2c943ad604f1fd2cc
child 163861 62296252e2f0464acb516743e986a3375f1e4090
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs919645
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 919645 - crash in android.os.NetworkOnMainThreadException. r=bnicholson
mobile/android/base/favicons/LoadFaviconTask.java
--- a/mobile/android/base/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/favicons/LoadFaviconTask.java
@@ -13,16 +13,17 @@ import android.util.Log;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.entity.BufferedHttpEntity;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.util.GeckoJarReader;
+import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UiAsyncTask;
 import static org.mozilla.gecko.favicons.Favicons.sContext;
 
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -207,13 +208,26 @@ public class LoadFaviconTask extends UiA
         // favicon load is cancelled.
     }
 
     int getId() {
         return mId;
     }
 
     static void closeHTTPClient() {
-        if (sHttpClient != null) {
-            sHttpClient.close();
+        // This work must be done on a background thread because it shuts down
+        // the connection pool, which typically involves closing a connection --
+        // which counts as network activity.
+        if (ThreadUtils.isOnBackgroundThread()) {
+            if (sHttpClient != null) {
+                sHttpClient.close();
+            }
+            return;
         }
+
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                LoadFaviconTask.closeHTTPClient();
+            }
+        });
     }
 }