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/mock_system_state.h b/mock_system_state.h
index 8b04f7e..a666a66 100644
--- a/mock_system_state.h
+++ b/mock_system_state.h
@@ -14,6 +14,7 @@
 #include "update_engine/mock_gpio_handler.h"
 #include "update_engine/mock_payload_state.h"
 #include "update_engine/clock.h"
+#include "update_engine/hardware.h"
 #include "update_engine/prefs_mock.h"
 #include "update_engine/system_state.h"
 
@@ -44,6 +45,10 @@
     return connection_manager_;
   }
 
+  inline virtual HardwareInterface* hardware() {
+    return hardware_;
+  }
+
   inline virtual MetricsLibraryInterface* metrics_lib() {
     return &mock_metrics_lib_;
   }
@@ -83,6 +88,10 @@
     clock_ = clock;
   }
 
+  inline void set_hardware(HardwareInterface* hardware) {
+    hardware_ = hardware;
+  }
+
   inline void set_prefs(PrefsInterface* prefs) {
     prefs_ = prefs;
   }
@@ -119,10 +128,12 @@
 
   // These are the other object we own.
   Clock default_clock_;
+  Hardware default_hardware_;
   OmahaRequestParams default_request_params_;
 
   // These are pointers to objects which caller can override.
   ClockInterface* clock_;
+  HardwareInterface* hardware_;
   PrefsInterface* prefs_;
   PrefsInterface* powerwash_safe_prefs_;
   ConnectionManager* connection_manager_;