From 4aade40455036958bd387d4d76f8b8675b27df00 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Mon, 7 Oct 2013 12:54:41 -0700 Subject: [PATCH] Bug 919645 - crash in android.os.NetworkOnMainThreadException. r=bnicholson --- .../android/base/favicons/LoadFaviconTask.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/favicons/LoadFaviconTask.java b/mobile/android/base/favicons/LoadFaviconTask.java index 3e6b98fd679..c5e43ec78ac 100644 --- a/mobile/android/base/favicons/LoadFaviconTask.java +++ b/mobile/android/base/favicons/LoadFaviconTask.java @@ -18,6 +18,7 @@ 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; @@ -212,8 +213,21 @@ public class LoadFaviconTask extends UiAsyncTask { } 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(); + } + }); } }