AU: disable GPIOs in production; some structural changes

Since we are not making use of the GPIO funcionality in UE for the
moment, it's been advised that it should be disabled. This CL does just
that, plus a few small changes:

* Adds a "no-op" GPIO implementation, which simply returns a constant
  value every time it's being asked whether test-mode was signaled (in
  this case, we set it to return false).

* The GPIO handler is embedded in SystemState. This makes sense from
  both the conceptual and usability standpoint.  The SystemState object
  can be parametrized to initialize either a real or a no-op GPIO
  handler.

BUG=chromium-os:32263
TEST=passes unit tests; does not engage GPIO protocol on x86-alex

Change-Id: I8121647baa7611041073dcf305beddab57c0e49c
Reviewed-on: https://gerrit.chromium.org/gerrit/40633
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/system_state.cc b/system_state.cc
index 78d5036..fc3ba57 100644
--- a/system_state.cc
+++ b/system_state.cc
@@ -15,7 +15,7 @@
     : device_policy_(NULL),
       connection_manager_(this) {}
 
-bool RealSystemState::Initialize() {
+bool RealSystemState::Initialize(bool enable_gpio) {
   metrics_lib_.Init();
 
   if (!prefs_.Init(FilePath(kPrefsDirectory))) {
@@ -26,6 +26,22 @@
   if (!payload_state_.Initialize(&prefs_))
     return false;
 
+  // Initialize the GPIO handler as instructed.
+  if (enable_gpio) {
+    // A real GPIO handler. Defer GPIO discovery to ensure the udev has ample
+    // time to export the devices. Also require that test mode is physically
+    // queried at most once and the result cached, for a more consistent update
+    // behavior.
+    udev_iface_.reset(new StandardUdevInterface());
+    file_descriptor_.reset(new EintrSafeFileDescriptor());
+    gpio_handler_.reset(new StandardGpioHandler(udev_iface_.get(),
+                                                file_descriptor_.get(),
+                                                true, true));
+  } else {
+    // A no-op GPIO handler, always indicating a non-test mode.
+    gpio_handler_.reset(new NoopGpioHandler(false));
+  }
+
   // All is well. Initialization successful.
   return true;
 }