For apps targeting JB MR2+, bind to the first thread using WebView
Bug 10937207
This reflects base change to bind to the first thread that instantiates
a WebView.
Change-Id: I2994db6e72b80ff24b93df3fbbd6c57ea9267657
(cherry picked from commit 916f857e0af25e8b179f60f532065386607567d7)
diff --git a/chromium/java/com/android/webview/chromium/WebViewChromium.java b/chromium/java/com/android/webview/chromium/WebViewChromium.java
index b399c6c..beae322 100644
--- a/chromium/java/com/android/webview/chromium/WebViewChromium.java
+++ b/chromium/java/com/android/webview/chromium/WebViewChromium.java
@@ -209,9 +209,14 @@
}
}
- if (!mFactory.hasStarted()) {
- // We will defer real initialization until we know which thread to do it on, unless we
- // are on the main thread already.
+ // We will defer real initialization until we know which thread to do it on, unless:
+ // - we are on the main thread already (common case),
+ // - the app is targeting >= JB MR2, in which case checkThread enforces that all usage
+ // comes from a single thread. (Note in JB MR2 this exception was in WebView.java).
+ if (mAppTargetSdkVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ mFactory.startYourEngines(false);
+ checkThread();
+ } else if (!mFactory.hasStarted()) {
if (Looper.myLooper() == Looper.getMainLooper()) {
mFactory.startYourEngines(true);
}