Send an UMA metric when failed to boot into the new partition.

When a payload is successfully applied, the /other/ partition
is marked as valid and a reboot is needed, the reboot into this
new partition can fail due to several reasons. If than happens,
the firmware can rollback to the previous partition.

When this happens, this fix sends a new UMA metric with the
attempt number of this failing payload.

In order to test this functionality we need to fake the
utils::BootDevice() to emulate a reboot into the same or
a different partition. To achieve this, this function is
moved to a new "HardwareInterface" that can be faked
using the FakeHardware class that can hold similar hardware
related functions. Implementations and unittest were
refactored as needed.

BUG=chromium:243572
TEST=unittests

Change-Id: I1a4242df0bd61e2718ab881ead603b1d3705b877
Reviewed-on: https://gerrit.chromium.org/gerrit/61815
Commit-Queue: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/real_system_state.h b/real_system_state.h
index 9ced628..c51094e 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -10,6 +10,7 @@
 #include <update_engine/clock.h>
 #include <update_engine/connection_manager.h>
 #include <update_engine/gpio_handler.h>
+#include <update_engine/hardware.h>
 #include <update_engine/payload_state.h>
 #include <update_engine/prefs.h>
 #include <update_engine/update_attempter.h>
@@ -44,6 +45,10 @@
     return &connection_manager_;
   }
 
+  virtual inline HardwareInterface* hardware() {
+    return &hardware_;
+  }
+
   virtual inline MetricsLibraryInterface* metrics_lib() {
     return &metrics_lib_;
   }
@@ -93,6 +98,9 @@
   // decisions depending on the current type of connection.
   ConnectionManager connection_manager_;
 
+  // Interface for the hardware functions.
+  Hardware hardware_;
+
   // The Metrics Library interface for reporting UMA stats.
   MetricsLibrary metrics_lib_;