Allow to set the network used for an update attempt.

When triggering an update attempt in Android, we can force all the
traffic to go through a given network by passing a NETWORK_ID=<id>
in the extra key-value pair field.

Bug: 29921093
TEST=Called update_engine_client passing NETWORK_ID.

Change-Id: I13becdd133cccc912b542d48061fcfe9f566099a
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index d435b52..c823e34 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -33,6 +33,7 @@
 #include "update_engine/common/multi_range_http_fetcher.h"
 #include "update_engine/common/utils.h"
 #include "update_engine/daemon_state_android.h"
+#include "update_engine/network_selector.h"
 #include "update_engine/payload_consumer/download_action.h"
 #include "update_engine/payload_consumer/filesystem_verifier_action.h"
 #include "update_engine/payload_consumer/postinstall_runner_action.h"
@@ -80,6 +81,7 @@
       boot_control_(boot_control),
       hardware_(hardware),
       processor_(new ActionProcessor()) {
+  network_selector_ = network::CreateNetworkSelector();
 }
 
 UpdateAttempterAndroid::~UpdateAttempterAndroid() {
@@ -175,6 +177,20 @@
       base::StringToInt(headers[kPayloadPropertyPowerwash], &data_wipe) &&
       data_wipe != 0;
 
+  NetworkId network_id = kDefaultNetworkId;
+  if (!headers[kPayloadPropertyNetworkId].empty()) {
+    if (!base::StringToUint64(headers[kPayloadPropertyNetworkId],
+                              &network_id)) {
+      return LogAndSetError(
+          error,
+          FROM_HERE,
+          "Invalid network_id: " + headers[kPayloadPropertyNetworkId]);
+    }
+    if (!network_selector_->SetProcessNetwork(network_id)) {
+      LOG(WARNING) << "Unable to set network_id, continuing with the update.";
+    }
+  }
+
   LOG(INFO) << "Using this install plan:";
   install_plan_.Dump();