AU: Implement getting of tracks through GetTrack.

Add SetTrack and GetTrack to UpdateEngine.xml as well.

BUG=chromium-os:8104
TEST=tested on device with update_engine_client

Change-Id: I10ef2552e9280524b3a8d5f232d104a81a114e06

Review URL: http://codereview.chromium.org/4181001
diff --git a/UpdateEngine.conf b/UpdateEngine.conf
index 2149798..534fade 100644
--- a/UpdateEngine.conf
+++ b/UpdateEngine.conf
@@ -21,7 +21,13 @@
            send_member="GetStatus"/>
     <allow send_destination="org.chromium.UpdateEngine"
            send_interface="org.chromium.UpdateEngineInterface"
+           send_member="GetTrack"/>
+    <allow send_destination="org.chromium.UpdateEngine"
+           send_interface="org.chromium.UpdateEngineInterface"
            send_member="RebootIfNeeded"/>
+    <allow send_destination="org.chromium.UpdateEngine"
+           send_interface="org.chromium.UpdateEngineInterface"
+           send_member="SetTrack"/>
   </policy>
   <policy context="default">
     <deny send_destination="org.chromium.UpdateEngine" />
diff --git a/dbus_service.cc b/dbus_service.cc
index 5a46b51..a27fd18 100644
--- a/dbus_service.cc
+++ b/dbus_service.cc
@@ -99,6 +99,15 @@
   return TRUE;
 }
 
+gboolean update_engine_service_get_track(UpdateEngineService* self,
+                                         gchar** track,
+                                         GError **error) {
+  string track_str =
+      chromeos_update_engine::OmahaRequestDeviceParams::GetDeviceTrack();
+  *track = strdup(track_str.c_str());
+  return TRUE;
+}
+
 gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
                                                 GError **error) {
   if (!self->update_attempter_->RebootIfNeeded()) {
diff --git a/dbus_service.h b/dbus_service.h
index b802fae..4fe17e9 100644
--- a/dbus_service.h
+++ b/dbus_service.h
@@ -59,6 +59,10 @@
                                           int64_t* new_size,
                                           GError **error);
 
+gboolean update_engine_service_get_track(UpdateEngineService* self,
+                                         gchar** track,
+                                         GError **error);
+
 gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
                                                 GError **error);
 
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index 03327b2..4cc5426 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -92,6 +92,13 @@
   return params.SetTrack(track);
 }
 
+string OmahaRequestDeviceParams::GetDeviceTrack() {
+  OmahaRequestDeviceParams params;
+  // Note that params.app_track is an empty string if the value in
+  // lsb-release file is invalid. See Init() for details.
+  return params.Init("", "") ? params.app_track : "";
+}
+
 string OmahaRequestDeviceParams::GetLsbValue(const string& key,
                                              const string& default_value,
                                              ValueValidator validator) const {
diff --git a/omaha_request_params.h b/omaha_request_params.h
index d7d2493..b8e2ee5 100644
--- a/omaha_request_params.h
+++ b/omaha_request_params.h
@@ -80,6 +80,9 @@
   bool SetTrack(const std::string& track);
   static bool SetDeviceTrack(const std::string& track);
 
+  // Returns the release track. On error, returns an empty string.
+  static std::string GetDeviceTrack();
+
   // For unit-tests.
   void set_root(const std::string& root) { root_ = root; }
 
diff --git a/update_engine.xml b/update_engine.xml
index 73bc92e..2008d2d 100644
--- a/update_engine.xml
+++ b/update_engine.xml
@@ -18,6 +18,9 @@
       <arg type="s" name="new_version" direction="out" />
       <arg type="x" name="new_size" direction="out" />
     </method>
+    <method name="GetTrack">
+      <arg type="s" name="track" direction="out" />
+    </method>
     <method name="RebootIfNeeded">
     </method>
     <method name="SetTrack">
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 20c86a5..c0b61fe 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -26,6 +26,7 @@
 DEFINE_bool(check_for_update, false, "Initiate check for updates.");
 DEFINE_string(omaha_url, "", "The URL of the Omaha update server.");
 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_string(track, "", "Permanently change the update track.");
 DEFINE_bool(update, false, "Forces an update and waits for its completion. "
@@ -192,6 +193,24 @@
   LOG(INFO) << "Track permanently set to: " << track;
 }
 
+string GetTrack() {
+  DBusGProxy* proxy;
+  GError* error = NULL;
+
+  CHECK(GetProxy(&proxy));
+
+  char* track = NULL;
+  gboolean rc =
+      org_chromium_UpdateEngineInterface_get_track(proxy,
+                                                   &track,
+                                                   &error);
+  CHECK_EQ(rc, true) << "Error getting the track: "
+                     << GetGErrorMessage(error);
+  string output = track;
+  g_free(track);
+  return output;
+}
+
 static gboolean CompleteUpdateSource(gpointer data) {
   string current_op;
   if (!GetStatus(&current_op) || current_op == "UPDATE_STATUS_IDLE") {
@@ -239,6 +258,11 @@
     SetTrack(FLAGS_track);
   }
 
+  // Show the track if requested.
+  if (FLAGS_show_track) {
+    LOG(INFO) << "Track: " << GetTrack();
+  }
+
   // Initiate an update check, if necessary.
   if (FLAGS_check_for_update ||
       FLAGS_update ||