OSDN Git Service

Update captive portal sign-in app SSL error page UI.
authorPaul Jensen <pauljensen@google.com>
Wed, 6 May 2015 18:40:59 +0000 (14:40 -0400)
committerPaul Jensen <pauljensen@google.com>
Wed, 3 Jun 2015 13:12:25 +0000 (09:12 -0400)
Add text and update image as per UX team recommendations.
Add "Use as is and open browser" link.

Bug:18791346
Bug:20038019
Bug:20486308
Change-Id: Ibf6d1493f5332e7905154cc7306645ac4c1a6283

packages/CaptivePortalLogin/assets/locked_page.png [deleted file]
packages/CaptivePortalLogin/assets/quantum_ic_warning_amber_96.png [new file with mode: 0644]
packages/CaptivePortalLogin/res/values/strings.xml
packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java

diff --git a/packages/CaptivePortalLogin/assets/locked_page.png b/packages/CaptivePortalLogin/assets/locked_page.png
deleted file mode 100644 (file)
index 91e1291..0000000
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 (file)
index 0000000..08294ce
Binary files /dev/null and b/packages/CaptivePortalLogin/assets/quantum_ic_warning_amber_96.png differ
index 8348be9..b1a3852 100644 (file)
@@ -5,5 +5,8 @@
     <string name="action_use_network">Use this network as is</string>
     <string name="action_do_not_use_network">Do not use this network</string>
     <string name="action_bar_label">Sign in to network</string>
+    <string name="ssl_error_warning">The network you&#8217;re trying to join has security issues.</string>
+    <string name="ssl_error_example">For example, the login page may not belong to the organization shown.</string>
+    <string name="ssl_error_continue">Continue anyway via browser</string>
 
 </resources>
index c7b7e6a..4c907a3 100644 (file)
@@ -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 = "<!DOCTYPE html><html><head><style>" +
-                "html { width:100%; height:100%; " +
-                "       background:url(locked_page.png) center center no-repeat; }" +
-                "</style></head><body></body></html>";
+        private final String SSL_ERROR_HTML = "<html><head><style>" +
+                "body { margin-left:" + dp(48) + "; margin-right:" + dp(48) + "; " +
+                        "margin-top:" + dp(96) + "; background-color:#fafafa; }" +
+                "img { width:" + dp(48) + "; height:" + dp(48) + "; }" +
+                "div.warn { font-size:" + sp(16) + "; margin-top:" + dp(16) + "; " +
+                "           opacity:0.87; line-height:1.28; }" +
+                "div.example { font-size:" + sp(14) + "; margin-top:" + dp(16) + "; " +
+                "              opacity:0.54; line-height:1.21905; }" +
+                "a { font-size:" + sp(14) + "; text-decoration:none; text-transform:uppercase; " +
+                "    margin-top:" + dp(24) + "; display:inline-block; color:#4285F4; " +
+                "    height:" + dp(48) + "; font-weight:bold; }" +
+                "</style></head><body><p><img src=quantum_ic_warning_amber_96.png><br>" +
+                "<div class=warn>%s</div>" +
+                "<div class=example>%s</div>" +
+                "<a href=%s>%s</a></body></html>";
 
         @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);
         }
     }