Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5cd8c0a authored by Kristian Monsen's avatar Kristian Monsen
Browse files

Fix for bug 8577776 Throw exception if app calls WebView used on wrong thread

Mostly copied and pasted from the bug report.

Change-Id: I57cd19961f51fce266025d76ad9273a24f629c5b
parent 77d94957
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.graphics.Picture;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.http.SslCertificate;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
@@ -241,6 +242,11 @@ public class WebView extends AbsoluteLayout

    private static final String LOGTAG = "webview_proxy";

    // Throwing an exception for incorrect thread usage if the
    // build target is JB MR2 or newer. Defaults to false, and is
    // set in the WebView constructor.
    private static Boolean sEnforceThreadChecking = false;

    /**
     *  Transportation object for returning WebView across thread boundaries.
     */
@@ -483,6 +489,8 @@ public class WebView extends AbsoluteLayout
        if (context == null) {
            throw new IllegalArgumentException("Invalid context argument");
        }
        sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
                Build.VERSION_CODES.JELLY_BEAN_MR2;
        checkThread();

        ensureProviderCreated();
@@ -1915,6 +1923,10 @@ public class WebView extends AbsoluteLayout
                    "Future versions of WebView may not support use on other threads.");
            Log.w(LOGTAG, Log.getStackTraceString(throwable));
            StrictMode.onWebViewMethodCalledOnWrongThread(throwable);

            if (sEnforceThreadChecking) {
                throw new RuntimeException(throwable);
            }
        }
    }