Make network usage on the main thread fatal (Honeycomb+)
For apps targetting Honeycomb SDK or above, make network usage on the
main thread (aka event thread, Looper thread, UI thread) be fatal.
If an app is targetting a previous SDK version, they're grandfathered
into the older (lack of) rules.
Bug: 786847
Change-Id: Ia4ae77b8369567ee526c96b930d523bc722b0bc9
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 754295a..7315f01 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3188,6 +3188,17 @@
}
/**
+ * For apps targetting SDK Honeycomb or later, we don't allow
+ * network usage on the main event loop / UI thread.
+ *
+ * Note to those grepping: this is what ultimately throws
+ * NetworkOnMainThreadException ...
+ */
+ if (data.appInfo.targetSdkVersion > 9) {
+ StrictMode.enableDeathOnNetwork();
+ }
+
+ /**
* Switch this process to density compatibility mode if needed.
*/
if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES)