AutofillManager WebView Input crash on Android 8.1

1.3k Views Asked by At

I have a bug with autofill manager, when I focus any input - it throws an exception:

W/System.err: java.lang.NullPointerException: activityToken
W/System.err: at android.os.Parcel.readException(Parcel.java:2011)
W/System.err: at android.os.Parcel.readException(Parcel.java:1951)
 at android.view.autofill.IAutoFillManager$Stub$Proxy.startSession(IAutoFillManager.java:397)
 at android.view.autofill.AutofillManager.startSessionLocked(AutofillManager.java:1012) W/System.err: at android.view.autofill.AutofillManager.notifyViewEntered(AutofillManager.java:734) android.view.autofill.AutofillManager.notifyViewEntered(AutofillManager.java:706)

I was able to fix it via adding a next code in the bases activity onCreate():

public static void preventViewAutoFill(@NonNull Window window) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
        final Method method;
        try {
            method = View.class.getMethod(AUTO_FILL_MANAGER_METHOD, Integer.TYPE);
        } catch (Exception ignore) {
            return;
        }
        if (method != null) {
            try {
                method.invoke(window.getDecorView(), IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
            } catch (Exception ignore) {
            }
        }
    }
}

This fixed problem in all views except input inside the WebView. I have a WebView with input fields when user focus on any input inside a WebView application crash.

In there any way to fix this on the application layer or on the WebView side?

Application targeting 25 API, min 16.

0

There are 0 best solutions below