summaryrefslogtreecommitdiffstats
path: root/packages/CaptivePortalLogin
diff options
context:
space:
mode:
authorPaul Jensen <pauljensen@google.com>2015-05-19 12:30:56 -0400
committerPaul Jensen <pauljensen@google.com>2015-06-03 15:15:12 +0000
commite836b6847af968460f36a4e6649b8cb6f6da18db (patch)
tree60e024c5860ad3428a5f0805fae0eb44a6b847f1 /packages/CaptivePortalLogin
parente247cdec6db549035b67bb21fa08a4c6c73897d3 (diff)
downloadframeworks_base-e836b6847af968460f36a4e6649b8cb6f6da18db.zip
frameworks_base-e836b6847af968460f36a4e6649b8cb6f6da18db.tar.gz
frameworks_base-e836b6847af968460f36a4e6649b8cb6f6da18db.tar.bz2
Disallow going back to initial empty page in captive portal app
This is a little tricky because WebView history can only be cleared after the next page load and we don't want to allow hitting back during the first page load. Bug:21147832 Change-Id: I639dfd27d4dc3af618282256ca02b9947e64a7b9
Diffstat (limited to 'packages/CaptivePortalLogin')
-rw-r--r--packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java37
1 files changed, 25 insertions, 12 deletions
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index 4c907a3..d876264 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -66,6 +66,7 @@ public class CaptivePortalLoginActivity extends Activity {
private NetworkCallback mNetworkCallback;
private ConnectivityManager mCm;
private boolean mLaunchBrowser = false;
+ private MyWebViewClient mWebViewClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -115,7 +116,8 @@ public class CaptivePortalLoginActivity extends Activity {
myWebView.clearCache(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
- myWebView.setWebViewClient(new MyWebViewClient());
+ mWebViewClient = new MyWebViewClient();
+ myWebView.setWebViewClient(mWebViewClient);
myWebView.setWebChromeClient(new MyWebChromeClient());
// Start initial page load so WebView finishes loading proxy settings.
// Actual load of mUrl is initiated by MyWebViewClient.
@@ -174,7 +176,7 @@ public class CaptivePortalLoginActivity extends Activity {
@Override
public void onBackPressed() {
WebView myWebView = (WebView) findViewById(R.id.webview);
- if (myWebView.canGoBack()) {
+ if (myWebView.canGoBack() && mWebViewClient.allowBack()) {
myWebView.goBack();
} else {
super.onBackPressed();
@@ -255,7 +257,12 @@ public class CaptivePortalLoginActivity extends Activity {
getResources().getDisplayMetrics()) /
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
getResources().getDisplayMetrics());
- private boolean mFirstPageLoad = true;
+ private int mPagesLoaded;
+
+ // If we haven't finished cleaning up the history, don't allow going back.
+ public boolean allowBack() {
+ return mPagesLoaded > 1;
+ }
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
@@ -264,26 +271,32 @@ public class CaptivePortalLoginActivity extends Activity {
done(Result.WANTED_AS_IS);
return;
}
- if (mFirstPageLoad) return;
+ // The first page load is used only to cause the WebView to
+ // fetch the proxy settings. Don't update the URL bar, and
+ // don't check if the captive portal is still there.
+ if (mPagesLoaded == 0) return;
+ // For internally generated pages, leave URL bar listing prior URL as this is the URL
+ // the page refers to.
+ if (!url.startsWith(INTERNAL_ASSETS)) {
+ final TextView myUrlBar = (TextView) findViewById(R.id.url_bar);
+ myUrlBar.setText(url);
+ }
testForCaptivePortal();
}
@Override
public void onPageFinished(WebView view, String url) {
- if (mFirstPageLoad) {
- mFirstPageLoad = false;
+ mPagesLoaded++;
+ if (mPagesLoaded == 1) {
// Now that WebView has loaded at least one page we know it has read in the proxy
// settings. Now prompt the WebView read the Network-specific proxy settings.
setWebViewProxy();
// Load the real page.
view.loadUrl(mURL.toString());
return;
- }
- // For internally generated pages, leave URL bar listing prior URL as this is the URL
- // the page refers to.
- if (!url.startsWith(INTERNAL_ASSETS)) {
- final TextView myUrlBar = (TextView) findViewById(R.id.url_bar);
- myUrlBar.setText(url);
+ } else if (mPagesLoaded == 2) {
+ // Prevent going back to empty first page.
+ view.clearHistory();
}
testForCaptivePortal();
}