Support in update_engine for script for UI jank investigation.

We need to update image_to_live.sh to run in a loop to help investigate
the kernel behavior during AU. Since update_engine doesn't allow a
new update to be applied unless the device is rebooted after the previous
update, this CL adds an option to reset the state for testing purposes.

This CL does not cause any change in product code, since
update_engine_client will never be invoked with this option in product.

BUG=chromium-os:27954
TEST=Tested on ZGB.
Change-Id: I561e58893818a1b4990fdc131cd3bb64e473155e
Reviewed-on: https://gerrit.chromium.org/gerrit/29907
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/update_engine_client.cc b/update_engine_client.cc
index db14fb6..f8396c9 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -28,6 +28,7 @@
 DEFINE_bool(reboot, false, "Initiate a reboot if needed.");
 DEFINE_bool(show_track, false, "Show the update track.");
 DEFINE_bool(status, false, "Print the status to stdout.");
+DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle.");
 DEFINE_string(track, "", "Permanently change the update track.");
 DEFINE_bool(update, false, "Forces an update and waits for its completion. "
             "Exit status is 0 if the update succeeded, and 1 otherwise.");
@@ -81,6 +82,18 @@
   LOG(INFO) << "  new_size: " << new_size;
 }
 
+bool ResetStatus() {
+  DBusGProxy* proxy;
+  GError* error = NULL;
+
+  CHECK(GetProxy(&proxy));
+
+  gboolean rc =
+      org_chromium_UpdateEngineInterface_reset_status(proxy, &error);
+  return rc;
+}
+
+
 // If |op| is non-NULL, sets it to the current operation string or an
 // empty string if unable to obtain the current status.
 bool GetStatus(string* op) {
@@ -251,6 +264,19 @@
   chromeos_update_engine::Subprocess::Init();
   google::ParseCommandLineFlags(&argc, &argv, true);
 
+  // Update the status if requested.
+  if (FLAGS_reset_status) {
+    LOG(INFO) << "Setting Update Engine status to idle ...";
+    if (!ResetStatus()) {
+      LOG(ERROR) << "ResetStatus failed.";
+      return 1;
+    }
+
+    LOG(INFO) << "ResetStatus succeeded.";
+    return 0;
+  }
+
+
   if (FLAGS_status) {
     LOG(INFO) << "Querying Update Engine status...";
     if (!GetStatus(NULL)) {