shill: Export portal detection failure phase and status

When portal detection fails, report the failure phase and status
to the given Service. The Chrome can then retrieve this information from
Service property through DBUS, and inform the user appropriately.

BUG=chromium:399486
TEST=unit tests
CQ-DEPEND=CL:211763

Change-Id: I27ec85bc6bf73162b1214d35bc84084588c3a855
Reviewed-on: https://chromium-review.googlesource.com/211745
Reviewed-by: Peter Qiu <zqiu@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
diff --git a/device.cc b/device.cc
index 66b568f..a7d9d44 100644
--- a/device.cc
+++ b/device.cc
@@ -1094,6 +1094,12 @@
         Metrics::kMetricPortalAttemptsToOnlineMax,
         Metrics::kMetricPortalAttemptsToOnlineNumBuckets);
   } else {
+    // Set failure phase and status.
+    if (selected_service_.get()) {
+      selected_service_->SetPortalDetectionFailure(
+          PortalDetector::PhaseToString(result.phase),
+          PortalDetector::StatusToString(result.status));
+    }
     SetServiceConnectedState(Service::kStatePortal);
 
     metrics()->SendToUMA(