summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-23 14:34:00 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-23 14:34:00 -0700
commit560e97f8e0cb63a0fa6e88db6badc142a99517d2 (patch)
treee08fd821c1fa45b4ae5d83ff490fe752626228a1
parentf4232e0097ffb672f5d1559b20c7230081efe34f (diff)
parent08d584cd1cba05284ccd2d0ea128c297624f0c47 (diff)
downloadframeworks_base-560e97f8e0cb63a0fa6e88db6badc142a99517d2.zip
frameworks_base-560e97f8e0cb63a0fa6e88db6badc142a99517d2.tar.gz
frameworks_base-560e97f8e0cb63a0fa6e88db6badc142a99517d2.tar.bz2
Merge "Log a StrictMode violation when WebView methods are called on the wrong thread"
-rw-r--r--core/java/android/os/StrictMode.java7
-rw-r--r--core/java/android/webkit/WebView.java19
2 files changed, 17 insertions, 9 deletions
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 1375a29..01c640a 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -1481,6 +1481,13 @@ public final class StrictMode {
onVmPolicyViolation(message, originStack);
}
+ /**
+ * @hide
+ */
+ public static void onWebViewMethodCalledOnWrongThread(Throwable originStack) {
+ onVmPolicyViolation(null, originStack);
+ }
+
// Map from VM violation fingerprint to uptime millis.
private static final HashMap<Integer, Long> sLastVmViolationTime = new HashMap<Integer, Long>();
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index f774803..61a69ca 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -54,7 +54,9 @@ import android.net.http.SslCertificate;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Looper;
import android.os.Message;
+import android.os.StrictMode;
import android.provider.Settings;
import android.speech.tts.TextToSpeech;
import android.text.Selection;
@@ -8933,15 +8935,14 @@ public class WebView extends AbsoluteLayout
}
private static void checkThread() {
- if (!"main".equals(Thread.currentThread().getName())) {
- try {
- throw new RuntimeException("A WebView method was called on thread '" +
- Thread.currentThread().getName() + "'. " +
- "All WebView methods must be called on the UI thread. " +
- "Future versions of WebView may not support use on other threads.");
- } catch (RuntimeException e) {
- Log.e(LOGTAG, Log.getStackTraceString(e));
- }
+ if (Looper.myLooper() != Looper.getMainLooper()) {
+ RuntimeException exception = new RuntimeException(
+ "A WebView method was called on thread '" +
+ Thread.currentThread().getName() + "'. " +
+ "All WebView methods must be called on the UI thread. " +
+ "Future versions of WebView may not support use on other threads.");
+ Log.e(LOGTAG, Log.getStackTraceString(exception));
+ StrictMode.onWebViewMethodCalledOnWrongThread(exception);
}
}