Add DBus methods to allow/disallow updates over 3G

This fix adds a new DBus pair of methods to allow/disallow the
updates over cellular networks and get the current state of this
setting. The setting is overridden by the device policy and the
SetUpdateOverCellularPermission() method fails if called on an
enrolled device that has the autoupdate settings in the device
policy.

BUG=chromium:213401
TEST=unittests for connection_manager changes. Manual test for the DBus service, see below.

Manual test procedure.
======================
Run on a shell:

1. Test for the default setting.
$ update_engine_client -show_update_over_cellular
[0701/183633:INFO:update_engine_client.cc(371)] Current update over cellular network setting: DISABLED
[0701/183633:INFO:update_engine_client.cc(443)] Done.

2. Test that enable works.
$ update_engine_client -update_over_cellular=yes -show_update_over_cellular
[0701/183655:INFO:update_engine_client.cc(371)] Current update over cellular network setting: ENABLED
[0701/183655:INFO:update_engine_client.cc(443)] Done.

3. Test that disable works.
$ update_engine_client -update_over_cellular=no -show_update_over_cellular
[0701/183659:INFO:update_engine_client.cc(371)] Current update over cellular network setting: DISABLED
[0701/183659:INFO:update_engine_client.cc(443)] Done.

4. Enable again the update over cellular, connect the chromebook to a 3G
and perform an update check.

Change-Id: Ic234a3ef8898b1e60e26277208276a958b7e0d94
Reviewed-on: https://gerrit.chromium.org/gerrit/60716
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/update_engine_client.cc b/update_engine_client.cc
index 87b1615..3455a52 100644
--- a/update_engine_client.cc
+++ b/update_engine_client.cc
@@ -39,6 +39,11 @@
             "Exit status is 0 if the update succeeded, and 1 otherwise.");
 DEFINE_bool(watch_for_updates, false,
             "Listen for status updates and print them to the screen.");
+DEFINE_bool(show_update_over_cellular, false,
+            "Show the current setting for updates over cellular networks.");
+DEFINE_string(update_over_cellular, "",
+              "Enables (\"yes\") or disables (\"no\") the updates over "
+              "cellular networks.");
 
 namespace {
 
@@ -260,6 +265,39 @@
   return output;
 }
 
+bool SetUpdateOverCellularPermission(gboolean allowed) {
+  DBusGProxy* proxy;
+  GError* error = NULL;
+
+  CHECK(GetProxy(&proxy));
+
+  gboolean rc =
+      org_chromium_UpdateEngineInterface_set_update_over_cellular_permission(
+          proxy,
+          allowed,
+          &error);
+  CHECK_EQ(rc, true) << "Error setting the update over cellular setting: "
+                     << GetAndFreeGError(&error);
+  return true;
+}
+
+bool GetUpdateOverCellularPermission() {
+  DBusGProxy* proxy;
+  GError* error = NULL;
+
+  CHECK(GetProxy(&proxy));
+
+  gboolean allowed;
+  gboolean rc =
+      org_chromium_UpdateEngineInterface_get_update_over_cellular_permission(
+          proxy,
+          &allowed,
+          &error);
+  CHECK_EQ(rc, true) << "Error getting the update over cellular setting: "
+                     << GetAndFreeGError(&error);
+  return allowed;
+}
+
 static gboolean CompleteUpdateSource(gpointer data) {
   string current_op;
   if (!GetStatus(&current_op) || current_op == "UPDATE_STATUS_IDLE") {
@@ -316,6 +354,24 @@
     return 0;
   }
 
+  // Changes the current update over cellular network setting.
+  if (!FLAGS_update_over_cellular.empty()) {
+    gboolean allowed = FLAGS_update_over_cellular == "yes";
+    if (!allowed && FLAGS_update_over_cellular != "no") {
+      LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular
+                 << "\". Please specify \"yes\" or \"no\".";
+    } else {
+      SetUpdateOverCellularPermission(allowed);
+    }
+  }
+
+  // Show the current update over cellular network setting.
+  if (FLAGS_show_update_over_cellular) {
+    bool allowed = GetUpdateOverCellularPermission();
+    LOG(INFO) << "Current update over cellular network setting: "
+              << (allowed ? "ENABLED" : "DISABLED");
+  }
+
   // First, update the target channel if requested.
   if (!FLAGS_channel.empty())
     SetTargetChannel(FLAGS_channel);