diff --git a/packages/CaptivePortalLogin/assets/locked_page.png b/packages/CaptivePortalLogin/assets/locked_page.png
deleted file mode 100644
index 91e1291df0dfb..0000000000000
Binary files a/packages/CaptivePortalLogin/assets/locked_page.png and /dev/null differ
diff --git a/packages/CaptivePortalLogin/assets/quantum_ic_warning_amber_96.png b/packages/CaptivePortalLogin/assets/quantum_ic_warning_amber_96.png
new file mode 100644
index 0000000000000..08294cee45875
Binary files /dev/null and b/packages/CaptivePortalLogin/assets/quantum_ic_warning_amber_96.png differ
diff --git a/packages/CaptivePortalLogin/res/values/strings.xml b/packages/CaptivePortalLogin/res/values/strings.xml
index 8348be9f1c5bd..b1a3852a7a8d7 100644
--- a/packages/CaptivePortalLogin/res/values/strings.xml
+++ b/packages/CaptivePortalLogin/res/values/strings.xml
@@ -5,5 +5,8 @@
Use this network as is
Do not use this network
Sign in to network
+ The network you’re trying to join has security issues.
+ For example, the login page may not belong to the organization shown.
+ Continue anyway via browser
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index c7b7e6a0cf558..4c907a31dd601 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -33,6 +33,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.Log;
+import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.SslErrorHandler;
@@ -50,6 +51,7 @@ import java.net.URL;
import java.lang.InterruptedException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Random;
public class CaptivePortalLoginActivity extends Activity {
private static final String TAG = "CaptivePortalLogin";
@@ -63,6 +65,7 @@ public class CaptivePortalLoginActivity extends Activity {
private String mResponseToken;
private NetworkCallback mNetworkCallback;
private ConnectivityManager mCm;
+ private boolean mLaunchBrowser = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -200,6 +203,18 @@ public class CaptivePortalLoginActivity extends Activity {
mCm.unregisterNetworkCallback(mNetworkCallback);
mNetworkCallback = null;
}
+ if (mLaunchBrowser) {
+ // Give time for this network to become default. After 500ms just proceed.
+ for (int i = 0; i < 5; i++) {
+ // TODO: This misses when mNetwork underlies a VPN.
+ if (mNetwork.equals(mCm.getActiveNetwork())) break;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mURL.toString())));
+ }
}
private void testForCaptivePortal() {
@@ -233,18 +248,30 @@ public class CaptivePortalLoginActivity extends Activity {
private class MyWebViewClient extends WebViewClient {
private static final String INTERNAL_ASSETS = "file:///android_asset/";
- private boolean firstPageLoad = true;
+ private final String mBrowserBailOutToken = Long.toString(new Random().nextLong());
+ // How many Android device-independent-pixels per scaled-pixel
+ // dp/sp = (px/sp) / (px/dp) = (1/sp) / (1/dp)
+ private final float mDpPerSp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 1,
+ getResources().getDisplayMetrics()) /
+ TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
+ getResources().getDisplayMetrics());
+ private boolean mFirstPageLoad = true;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
- if (firstPageLoad) return;
+ if (url.contains(mBrowserBailOutToken)) {
+ mLaunchBrowser = true;
+ done(Result.WANTED_AS_IS);
+ return;
+ }
+ if (mFirstPageLoad) return;
testForCaptivePortal();
}
@Override
public void onPageFinished(WebView view, String url) {
- if (firstPageLoad) {
- firstPageLoad = false;
+ if (mFirstPageLoad) {
+ mFirstPageLoad = false;
// 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();
@@ -261,16 +288,46 @@ public class CaptivePortalLoginActivity extends Activity {
testForCaptivePortal();
}
+ // Convert Android device-independent-pixels (dp) to HTML size.
+ private String dp(int dp) {
+ // HTML px's are scaled just like dp's, so just add "px" suffix.
+ return Integer.toString(dp) + "px";
+ }
+
+ // Convert Android scaled-pixels (sp) to HTML size.
+ private String sp(int sp) {
+ // Convert sp to dp's.
+ float dp = sp * mDpPerSp;
+ // Apply a scale factor to make things look right.
+ dp *= 1.3;
+ // Convert dp's to HTML size.
+ return dp((int)dp);
+ }
+
// A web page consisting of a large broken lock icon to indicate SSL failure.
- final static String SSL_ERROR_HTML = "
";
+ private final String SSL_ERROR_HTML = "
" +
+ "
%s
" +
+ "%s
" +
+ "%s";
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
- Log.w(TAG, "SSL error; displaying broken lock icon.");
- view.loadDataWithBaseURL(INTERNAL_ASSETS, SSL_ERROR_HTML, "text/HTML", "UTF-8", null);
+ Log.w(TAG, "SSL error; displaying SSL warning.");
+ final String html = String.format(SSL_ERROR_HTML, getString(R.string.ssl_error_warning),
+ getString(R.string.ssl_error_example), mBrowserBailOutToken,
+ getString(R.string.ssl_error_continue));
+ view.loadDataWithBaseURL(INTERNAL_ASSETS, html, "text/HTML", "UTF-8", null);
}
}