Android custom InputConnection newly failing

557 Views Asked by At

I've got a custom webview that I use (via contenteditable) as a rich text editor. To accommodate a few things, I also have a custom InputConnection.

This has worked fine until just recently — I'm suspecting a recent Android/WebView update.

I construct the InputConnection by overriding my WebView-derived class's onCreateInputConnection:

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection ic = super.onCreateInputConnection(outAttrs);
    if (ic != null) {
        InputConnection mic = new MyInputConnection(ic);
        return mic;
    }
    return ic;
}

MyInputConnection looks like:

private class MyInputConnection implements InputConnection {
    private InputConnection IC;

    // Must be implemented (at least pre-Android-N)
    @Override
    public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
        return IC.getExtractedText(request, flags);
    }
    ...
}

This used to work great. But now I get:

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.AssertionError
    at org.chromium.content.browser.input.ImeUtils.checkCondition(ImeUtils.java:1)
    at org.chromium.content.browser.input.ThreadedInputConnection.assertOnImeThread(ThreadedInputConnection.java:64)
    at org.chromium.content.browser.input.ThreadedInputConnection.getExtractedText(ThreadedInputConnection.java:105)
    at com.myapp.MyWebView$MyInputConnection.getExtractedText(MyWebView.java:106)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:326)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

So it seems like somehow it doesn't like the thread that my InputConnection is running on? Even though it should be calling the WebView's original InputConnection?

Like I said, the puzzling part is this was working a couple of days ago. (It fails now with Gboard and SwiftKey, at least, but strangely seems to still work as it did originally with Hacker's Keyboard.)

0

There are 0 best solutions below