Merge branch 'cros/upstream' into 'cros/master'

Fixed:
	connection_manager_interface.h: remove line 53-56
	fix the assert in common/http_fetcher_unittest.cc:637

BUG=none
TEST=sent squashed merge to buildbots and HWtest was success.

Change-Id: I15037921592a2b7a4dd76dff71417d03caf97cf6
diff --git a/Android.mk b/Android.mk
index cff7081..a7e6836 100644
--- a/Android.mk
+++ b/Android.mk
@@ -992,6 +992,7 @@
     p2p_manager_unittest.cc \
     payload_consumer/download_action_unittest.cc \
     payload_state_unittest.cc \
+    proxy_resolver_unittest.cc \
     update_attempter_unittest.cc \
     update_manager/boxed_value_unittest.cc \
     update_manager/chromeos_policy_unittest.cc \
diff --git a/common/http_fetcher_unittest.cc b/common/http_fetcher_unittest.cc
index dcc1573..73110e9 100644
--- a/common/http_fetcher_unittest.cc
+++ b/common/http_fetcher_unittest.cc
@@ -634,7 +634,7 @@
   fetcher->Unpause();
   fetcher->Pause();
   // Proxy resolver comes back after we paused the fetcher.
-  ASSERT_TRUE(proxy_callback);
+  ASSERT_FALSE(proxy_callback.is_null());
   proxy_callback.Run({1, kNoProxy});
 }
 
diff --git a/common/utils.cc b/common/utils.cc
index ea748c1..b63b867 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -57,7 +57,7 @@
 #include "update_engine/common/prefs_interface.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/payload_consumer/file_descriptor.h"
-#include "update_engine/payload_consumer/payload_constants.h"
+#include "update_engine/payload_consumer/file_writer.h"
 
 using base::Time;
 using base::TimeDelta;
@@ -1027,19 +1027,6 @@
   return false;
 }
 
-bool IsZlibCompatible(const string& fingerprint) {
-  if (fingerprint.size() != sizeof(kCompatibleZlibFingerprint[0]) - 1) {
-    LOG(ERROR) << "Invalid fingerprint: " << fingerprint;
-    return false;
-  }
-  for (auto& f : kCompatibleZlibFingerprint) {
-    if (base::CompareCaseInsensitiveASCII(fingerprint, f) == 0) {
-      return true;
-    }
-  }
-  return false;
-}
-
 bool ReadExtents(const string& path, const vector<Extent>& extents,
                  brillo::Blob* out_data, ssize_t out_data_size,
                  size_t block_size) {
diff --git a/common/utils.h b/common/utils.h
index 8cccc24..184e72b 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -308,9 +308,6 @@
 bool GetMinorVersion(const brillo::KeyValueStore& store,
                      uint32_t* minor_version);
 
-// Returns whether zlib |fingerprint| is compatible with zlib we are using.
-bool IsZlibCompatible(const std::string& fingerprint);
-
 // This function reads the specified data in |extents| into |out_data|. The
 // extents are read from the file at |path|. |out_data_size| is the size of
 // |out_data|. Returns false if the number of bytes to read given in
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index e442441..4a8178c 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -352,7 +352,8 @@
 
   target_path_ = install_plan_->partitions[current_partition_].target_path;
   int err;
-  target_fd_ = OpenFile(target_path_.c_str(), O_RDWR, &err);
+
+  target_fd_ = OpenFile(target_path_.c_str(), O_RDWR | O_DSYNC, &err);
   if (!target_fd_) {
     LOG(ERROR) << "Unable to open target partition "
                << partition.partition_name() << " on slot "
diff --git a/payload_consumer/delta_performer_unittest.cc b/payload_consumer/delta_performer_unittest.cc
index 18481a7..12d0708 100644
--- a/payload_consumer/delta_performer_unittest.cc
+++ b/payload_consumer/delta_performer_unittest.cc
@@ -813,20 +813,4 @@
   EXPECT_EQ(DeltaPerformer::kSupportedMajorPayloadVersion, major_version);
 }
 
-// Test that we recognize our own zlib compressor implementation as supported.
-// All other equivalent implementations should be added to
-// kCompatibleZlibFingerprint.
-TEST_F(DeltaPerformerTest, ZlibFingerprintMatch) {
-  string fingerprint;
-#ifdef __ANDROID__
-  const std::string kZlibFingerprintPath =
-      test_utils::GetBuildArtifactsPath("zlib_fingerprint");
-#else
-  const std::string kZlibFingerprintPath = "/etc/zlib_fingerprint";
-#endif  // __ANDROID__
-  EXPECT_TRUE(base::ReadFileToString(base::FilePath(kZlibFingerprintPath),
-                                     &fingerprint));
-  EXPECT_TRUE(utils::IsZlibCompatible(fingerprint));
-}
-
 }  // namespace chromeos_update_engine
diff --git a/payload_consumer/payload_constants.cc b/payload_consumer/payload_constants.cc
index de0fd74..4c11d7a 100644
--- a/payload_consumer/payload_constants.cc
+++ b/payload_consumer/payload_constants.cc
@@ -32,17 +32,6 @@
 
 const char kDeltaMagic[4] = {'C', 'r', 'A', 'U'};
 
-// The zlib in Android and Chrome OS are currently compatible with each other,
-// so they are sharing the same array, but if in the future they are no longer
-// compatible with each other, we coule make the same change on the other one to
-// make them compatible again or use ifdef here.
-const char kCompatibleZlibFingerprint[][65] = {
-    "ea973605ccbbdb24f59f449c5f65861a1a9bc7a4353377aaaa06cb3e0f1cfbd7",
-    "3747fa404cceb00a5ec3606fc779510aaa784d5864ab1d5c28b9e267c40aad5c",
-    // zlib 1.2.11
-    "61514794a2985bee78135fd67a2f1fd18e56f3c3e410fbc4552a0e05a701e47a",
-};
-
 const char* InstallOperationTypeName(InstallOperation_Type op_type) {
   switch (op_type) {
     case InstallOperation::BSDIFF:
diff --git a/payload_consumer/payload_constants.h b/payload_consumer/payload_constants.h
index 7509ed2..76d740f 100644
--- a/payload_consumer/payload_constants.h
+++ b/payload_consumer/payload_constants.h
@@ -56,15 +56,6 @@
 extern const char kBspatchPath[];
 extern const char kDeltaMagic[4];
 
-// The list of compatible SHA256 hashes of zlib source code.
-// This is used to check if the source image have a compatible zlib (produce
-// same compressed result given the same input).
-// When a new fingerprint is found, please examine the changes in zlib source
-// carefully and determine if it's still compatible with previous version, if
-// yes then add the new fingerprint to this array, otherwise remove all previous
-// fingerprints in the array first, and only include the new fingerprint.
-extern const char kCompatibleZlibFingerprint[3][65];
-
 // A block number denoting a hole on a sparse file. Used on Extents to refer to
 // section of blocks not present on disk on a sparse file.
 const uint64_t kSparseHole = std::numeric_limits<uint64_t>::max();
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index 0716c1f..776650f 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -319,9 +319,6 @@
   DEFINE_string(properties_file, "",
                 "If passed, dumps the payload properties of the payload passed "
                 "in --in_file and exits.");
-  DEFINE_string(zlib_fingerprint, "",
-                "The fingerprint of zlib in the source image in hash string "
-                "format, used to check imgdiff compatibility.");
 
   DEFINE_string(old_channel, "",
                 "The channel for the old image. 'dev-channel', 'npo-channel', "
@@ -565,14 +562,6 @@
     LOG(INFO) << "Using provided minor_version=" << FLAGS_minor_version;
   }
 
-  if (!FLAGS_zlib_fingerprint.empty()) {
-    if (utils::IsZlibCompatible(FLAGS_zlib_fingerprint)) {
-      payload_config.version.imgdiff_allowed = true;
-    } else {
-      LOG(INFO) << "IMGDIFF operation disabled due to fingerprint mismatch.";
-    }
-  }
-
   if (payload_config.is_delta) {
     LOG(INFO) << "Generating delta update";
   } else {
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index e62ba94..b139491 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -210,9 +210,6 @@
 # Path to the postinstall config file in target image if exists.
 POSTINSTALL_CONFIG_FILE=""
 
-# The fingerprint of zlib in the source image.
-ZLIB_FINGERPRINT=""
-
 # read_option_int <file.txt> <option_key> [default_value]
 #
 # Reads the unsigned integer value associated with |option_key| in a key=value
@@ -332,11 +329,6 @@
   # updater supports a newer major version.
   FORCE_MAJOR_VERSION="1"
 
-  if [[ "${partitions_array}" == "SRC_PARTITIONS" ]]; then
-    # Copy from zlib_fingerprint in source image to stdout.
-    ZLIB_FINGERPRINT=$(e2cp "${root}":/etc/zlib_fingerprint -)
-  fi
-
   # When generating legacy Chrome OS images, we need to use "boot" and "system"
   # for the partition names to be compatible with updating Brillo devices with
   # Chrome OS images.
@@ -410,10 +402,6 @@
 Disabling deltas for this source version."
       exit ${EX_UNSUPPORTED_DELTA}
     fi
-
-    if [[ "${FORCE_MINOR_VERSION}" -ge 4 ]]; then
-      ZLIB_FINGERPRINT=$(unzip -p "${image}" "META/zlib_fingerprint.txt")
-    fi
   else
     # Target image
     local postinstall_config=$(create_tempfile "postinstall_config.XXXXXX")
@@ -535,9 +523,6 @@
     if [[ -n "${FORCE_MINOR_VERSION}" ]]; then
       GENERATOR_ARGS+=( --minor_version="${FORCE_MINOR_VERSION}" )
     fi
-    if [[ -n "${ZLIB_FINGERPRINT}" ]]; then
-      GENERATOR_ARGS+=( --zlib_fingerprint="${ZLIB_FINGERPRINT}" )
-    fi
   fi
 
   if [[ -n "${FORCE_MAJOR_VERSION}" ]]; then
diff --git a/update_attempter.cc b/update_attempter.cc
index 6a7853d..6b07ff9 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -329,12 +329,11 @@
   bool use_p2p_for_downloading = false;
   bool use_p2p_for_sharing = false;
 
-  // Never use p2p for downloading in interactive checks unless the
-  // developer has opted in for it via a marker file.
+  // Never use p2p for downloading in interactive checks unless the developer
+  // has opted in for it via a marker file.
   //
-  // (Why would a developer want to opt in? If he's working on the
-  // update_engine or p2p codebases so he can actually test his
-  // code.).
+  // (Why would a developer want to opt in? If they are working on the
+  // update_engine or p2p codebases so they can actually test their code.)
 
   if (system_state_ != nullptr) {
     if (!system_state_->p2p_manager()->IsP2PEnabled()) {
@@ -805,12 +804,6 @@
 }
 
 bool UpdateAttempter::RebootIfNeeded() {
-  if (status_ != UpdateStatus::UPDATED_NEED_REBOOT) {
-    LOG(INFO) << "Reboot requested, but status is "
-              << UpdateStatusToString(status_) << ", so not rebooting.";
-    return false;
-  }
-
   if (system_state_->power_manager()->RequestReboot())
     return true;