Merge "CaptivePortalLoginActivity: improve logging"
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index 5b3b984..4e6faf6 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -37,6 +37,7 @@
 import android.util.ArrayMap;
 import android.util.Log;
 import android.util.TypedValue;
+import android.util.SparseArray;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
@@ -44,6 +45,7 @@
 import android.webkit.WebChromeClient;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
+import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.ProgressBar;
 import android.widget.TextView;
@@ -375,7 +377,7 @@
                 return;
             }
             final URL url = makeURL(urlString);
-            Log.d(TAG, "onPageSarted: " + sanitizeURL(url));
+            Log.d(TAG, "onPageStarted: " + sanitizeURL(url));
             mHostname = host(url);
             // For internally generated pages, leave URL bar listing prior URL as this is the URL
             // the page refers to.
@@ -426,7 +428,7 @@
             final URL url = makeURL(error.getUrl());
             final String host = host(url);
             Log.d(TAG, String.format("SSL error: %s, url: %s, certificate: %s",
-                    error.getPrimaryError(), sanitizeURL(url), error.getCertificate()));
+                    sslErrorName(error), sanitizeURL(url), error.getCertificate()));
             if (url == null || !Objects.equals(host, mHostname)) {
                 // Ignore ssl errors for resources coming from a different hostname than the page
                 // that we are currently loading, and only cancel the request.
@@ -539,4 +541,18 @@
     private void logMetricsEvent(int event) {
         MetricsLogger.action(this, event, getPackageName());
     }
+
+    private static final SparseArray<String> SSL_ERRORS = new SparseArray<>();
+    static {
+        SSL_ERRORS.put(SslError.SSL_NOTYETVALID,  "SSL_NOTYETVALID");
+        SSL_ERRORS.put(SslError.SSL_EXPIRED,      "SSL_EXPIRED");
+        SSL_ERRORS.put(SslError.SSL_IDMISMATCH,   "SSL_IDMISMATCH");
+        SSL_ERRORS.put(SslError.SSL_UNTRUSTED,    "SSL_UNTRUSTED");
+        SSL_ERRORS.put(SslError.SSL_DATE_INVALID, "SSL_DATE_INVALID");
+        SSL_ERRORS.put(SslError.SSL_INVALID,      "SSL_INVALID");
+    }
+
+    private static String sslErrorName(SslError error) {
+        return SSL_ERRORS.get(error.getPrimaryError(), "UNKNOWN");
+    }
 }