From 081caaa34ab5af0694087c3203e39be25797455a Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Tue, 18 Jan 2011 08:50:20 -0500 Subject: Protect access to mWebView by checking mRunnable. If the user cancels the login event, mRunnable will be reset and the WebView destroyed. Check for a null mRunnable before accessing mWebView. Bug: 3361009 Bug: 3349815 Change-Id: Idd9a2b788673d9ec95bfa083a4af7df705c22fcd --- src/com/android/browser/GoogleAccountLogin.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/com/android/browser/GoogleAccountLogin.java') diff --git a/src/com/android/browser/GoogleAccountLogin.java b/src/com/android/browser/GoogleAccountLogin.java index 04b395751..855c407b7 100644 --- a/src/com/android/browser/GoogleAccountLogin.java +++ b/src/com/android/browser/GoogleAccountLogin.java @@ -86,9 +86,17 @@ public class GoogleAccountLogin extends Thread implements .appendQueryParameter("SID", mSid) .appendQueryParameter("LSID", mLsid) .build().toString(); + // Check mRunnable to see if the request has been canceled. Otherwise + // we might access a destroyed WebView. + String ua = null; + synchronized (this) { + if (mRunnable == null) { + return; + } + ua = mWebView.getSettings().getUserAgentString(); + } // Intentionally not using Proxy. - AndroidHttpClient client = AndroidHttpClient.newInstance( - mWebView.getSettings().getUserAgentString()); + AndroidHttpClient client = AndroidHttpClient.newInstance(ua); HttpPost request = new HttpPost(url); String result = null; @@ -119,7 +127,15 @@ public class GoogleAccountLogin extends Thread implements .build().toString(); mActivity.runOnUiThread(new Runnable() { @Override public void run() { - mWebView.loadUrl(newUrl); + // Check mRunnable in case the request has been canceled. This + // is most likely not necessary as run() is the only non-UI + // thread that calls done() but I am paranoid. + synchronized (GoogleAccountLogin.this) { + if (mRunnable == null) { + return; + } + mWebView.loadUrl(newUrl); + } } }); } -- cgit v1.2.3