Add a feature to get the last UpdateAttempt ErrorCode from update_engine

For autotest, update_engine test failures are always hard to debug,
since the error message is not clear. Add a new flag 'last_attempt_error'
to get the last UpdateAttempt ErrorCode from update_engine.

Bug:25598547
Test:emerge-peppy update_engine
     emerge-peppy update_engine_client
     cros flash a test image to DUT.
     (on the DUT):update_engine_client --last_attempt_error
     Compare the results with the update_engine logs, matched.

Change-Id: Id12681097ed30b0826cad68809f17f934a07e5b2
diff --git a/common_service.cc b/common_service.cc
index 3c77c93..f0b818f 100644
--- a/common_service.cc
+++ b/common_service.cc
@@ -35,6 +35,7 @@
 #include "update_engine/omaha_request_params.h"
 #include "update_engine/p2p_manager.h"
 #include "update_engine/update_attempter.h"
+#include "update_engine/payload_state_interface.h"
 
 using base::StringPrintf;
 using brillo::ErrorPtr;
@@ -318,4 +319,10 @@
   return true;
 }
 
+bool UpdateEngineService::GetLastAttemptError(ErrorPtr* /* error */,
+                                              int32_t* out_last_attempt_error) {
+  ErrorCode error_code = system_state_->payload_state()->GetAttemptErrorCode();
+  *out_last_attempt_error = static_cast<int>(error_code);
+  return true;
+}
 }  // namespace chromeos_update_engine