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(); + } + }); } }