Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I get dozens of crash log caused by this exception from my app (which depends on webview heavily), involved ROM version are 4.0.4 and 4.0.3.</p> <p>It seems that there is no normal way to fix it, so i tried following hacking approach.</p> <p>code snipet on 4.0.4:</p> <pre><code>private static Handler sWebCoreHandler; // Class for providing Handler creation inside the WebCore thread. private static class WebCoreThread implements Runnable { // Message id for initializing a new WebViewCore. private static final int INITIALIZE = 0; private static final int REDUCE_PRIORITY = 1; private static final int RESUME_PRIORITY = 2; public void run() { Looper.prepare(); Assert.assertNull(sWebCoreHandler); synchronized (WebViewCore.class) { sWebCoreHandler = new Handler() { @Override public void handleMessage(Message msg) { // ... // Process.setPriority(...) } }; // ... } // ... } } </code></pre> <p>I think this exception is thrown from sWebCoreHandler.handleMessage(), if we can wrap try/catch on handleMessage(), the problem could be fixed.</p> <p>Handler class has four members:</p> <pre><code>final MessageQueue mQueue; final Looper mLooper; final Callback mCallback; IMessenger mMessenger; </code></pre> <p>mQueue is set as mLooper.mQueue, mCallback is null in sWebCoreHandler, so we just need to set mLooper and mMessenger with values in sWebCoreHandler.</p> <pre><code>static Handler sProxyHandler = null; static void tryTweakWebCoreHandler() { // 4.0.3/4.0.4 rom if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { tweakWebCoreHandle(); } } static private void tweakWebCoreHandle() { if (sProxyHandler != null) return; try { Field f = Class.forName("android.webkit.WebViewCore").getDeclaredField("sWebCoreHandler"); f.setAccessible(true); Object h = f.get(null); Object mMessenger = null; Method m = Handler.class.getDeclaredMethod("getIMessenger", (Class&lt;?&gt;[])null); m.setAccessible(true); mMessenger = m.invoke(h, (Object[])null); sProxyHandler = new WebCoreProxyHandler((Handler)h); if (mMessenger != null) { Field f1 = Handler.class.getDeclaredField("mMessenger"); f1.setAccessible(true); f1.set(sProxyHandler, mMessenger); } f.set(null, sProxyHandler); // Log.w(TAG, "sWebCoreHandler: " + h); } catch (Throwable e) { Log.w(TAG, "exception: " + e); } if (sProxyHandler == null) sProxyHandler = new Handler(); } static class WebCoreProxyHandler extends Handler { final Handler handler; public WebCoreProxyHandler(Handler handler) { super(handler.getLooper()); this.handler = handler; } public void handleMessage(Message msg) { // Log.w("WebCoreProxyHandler", "handle msg: " + msg.what); try { handler.handleMessage(msg); } catch (Throwable tr) { Log.w("WebCoreProxyHandler", "exception: " + tr); } } } </code></pre> <p>Remain problem is when to invoke tryTweakWebCoreHandler(). I tried to invoke it after a WebView instance is created and tested on some devices, WebCoreProxyHandler.handleMessage() can be called.</p> <p>Note: i just made some simple test, i'm not sure this problem is resolved as the origin exception can not be reproduced reliably.</p> <p>If you decide to try this approach, please do enough test.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload