update_engine: added CanRollback dbus method

Added a method to the update engine to check if a rollback
partition is available and can be booted from.
update_engine_client is also updated to call the function
when --can_rollback paramater is specified

BUG=chromium:343301
TEST=Ran "update_engine_client --can_rollback" and unit tests

Change-Id: If3fcb29a0067069a22812f60e9b67c6fdbbd18bd
Reviewed-on: https://chromium-review.googlesource.com/187157
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/update_engine_client.cc b/update_engine_client.cc
index fc06da2..6bd3d9f 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -42,6 +42,8 @@
 DEFINE_bool(reboot, false, "Initiate a reboot if needed.");
 DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle.");
 DEFINE_bool(rollback, false, "Perform a rollback to the previous partition.");
+DEFINE_bool(can_rollback, false, "Shows whether rollback partition "
+            "is available.");
 DEFINE_bool(show_channel, false, "Show the current and target channels.");
 DEFINE_bool(show_p2p_update, false,
             "Show the current setting for peer-to-peer update sharing.");
@@ -207,6 +209,20 @@
   return true;
 }
 
+bool CanRollback() {
+  DBusGProxy* proxy;
+  GError* error = NULL;
+
+  CHECK(GetProxy(&proxy));
+
+  gboolean can_rollback = FALSE;
+  gboolean rc = update_engine_client_can_rollback(proxy,
+                                                  &can_rollback,
+                                                  &error);
+  CHECK_EQ(rc, TRUE) << "Error while querying rollback partition availabilty: "
+                     << GetAndFreeGError(&error);
+  return can_rollback;
+}
 bool CheckForUpdates(const string& app_version, const string& omaha_url) {
   DBusGProxy* proxy;
   GError* error = NULL;
@@ -412,6 +428,13 @@
     }
   }
 
+  // Show the rollback availability.
+  if (FLAGS_can_rollback) {
+    bool can_rollback = CanRollback();
+    LOG(INFO) << "Rollback partition: "
+              << (can_rollback ? "AVAILABLE" : "UNAVAILABLE");
+  }
+
   // Show the current P2P enabled setting.
   if (FLAGS_show_p2p_update) {
     bool enabled = GetP2PUpdatePermission();