Add {Get,Set}CohortHint interface.

Export the "cohort hint" getter and setter in the client interfaces
(D-Bus and Binder). The cohort hint is sent to Omaha on every update
check request but can be ignored and/or reset by Omaha on every
response.

Other minor linter fixes to the affected files.

Bug: 31740109
Test: Build with D-Bus and with Binder.

(cherry picked from commit 5b5fa8b412312a41cfd4d7ab475b54d4f730ed2a)

Change-Id: Ieb40c2d4bbe2ce926d54b6348b22f2840d8327db
Reviewed-on: https://chromium-review.googlesource.com/395206
Commit-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Christopher Book <cbook@chromium.org>
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 55d7e64..44897e0 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -233,6 +233,8 @@
                 "target channel is more stable than the current channel unless "
                 "--nopowerwash is specified.");
   DEFINE_bool(check_for_update, false, "Initiate check for updates.");
+  DEFINE_string(
+      cohort_hint, "", "Set the current cohort hint to the passed value.");
   DEFINE_bool(follow, false,
               "Wait for any update operations to complete."
               "Exit status is 0 if the update succeeded, and 1 otherwise.");
@@ -259,6 +261,7 @@
               "Shows whether rollback partition "
               "is available.");
   DEFINE_bool(show_channel, false, "Show the current and target channels.");
+  DEFINE_bool(show_cohort_hint, false, "Show the current cohort hint.");
   DEFINE_bool(show_p2p_update, false,
               "Show the current setting for peer-to-peer update sharing.");
   DEFINE_bool(show_update_over_cellular, false,
@@ -333,6 +336,27 @@
               << (allowed ? "ENABLED" : "DISABLED");
   }
 
+  // Change/show the cohort hint.
+  bool set_cohort_hint =
+      base::CommandLine::ForCurrentProcess()->HasSwitch("cohort_hint");
+  if (set_cohort_hint) {
+    LOG(INFO) << "Setting cohort hint to: \"" << FLAGS_cohort_hint << "\"";
+    if (!client_->SetCohortHint(FLAGS_cohort_hint)) {
+      LOG(ERROR) << "Error setting the cohort hint.";
+      return 1;
+    }
+  }
+
+  if (FLAGS_show_cohort_hint || set_cohort_hint) {
+    string cohort_hint;
+    if (!client_->GetCohortHint(&cohort_hint)) {
+      LOG(ERROR) << "Error getting the cohort hint.";
+      return 1;
+    }
+
+    LOG(INFO) << "Current cohort hint: \"" << cohort_hint << "\"";
+  }
+
   if (!FLAGS_powerwash && !FLAGS_rollback && FLAGS_channel.empty()) {
     LOG(ERROR) << "powerwash flag only makes sense rollback or channel change";
     return 1;